Skip to content

Commit 19f8e44

Browse files
author
.
committed
Update dependencies. Add optional re-ranker cutoff. Improve error message when doc path doesn't exist
1 parent fd3466b commit 19f8e44

File tree

7 files changed

+1304
-1644
lines changed

7 files changed

+1304
-1644
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,4 @@ dmypy.json
147147

148148
# Pyre type checker
149149
.pyre/
150+
.github/

docs/configure_model.rst

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@ An example of OpenAI gpt4o-mini is shown below:
2020
:language: yaml
2121

2222

23-
llamacpp
24-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25-
26-
.. literalinclude:: ../sample_templates/llm/llamacpp.yaml
27-
:language: yaml
28-
2923
Ollama + Litellm
3024
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3125

@@ -46,4 +40,4 @@ Reference
4640

4741
.. automodule:: llmsearch.models.config
4842
:members:
49-
43+

sample_templates/generic/config_template.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ semantic_search:
7575

7676
query_prefix: "query: " # Often queries have to be prefixed for embedding models, such as e5
7777

78+
score_cutoff: -3.0 # Optional reranker score cutoff. Documents below this score will be excluded from the returned document list
79+
7880
hyde:
7981
enabled: False
8082

sample_templates/llm/litellm.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ llm:
1616
temperature: 0.2
1717
model: "any"
1818
api_key: "any"
19-
base_url: "http://0.0.0.0:8000"
19+
base_url: "http://0.0.0.0:8000"

src/llmsearch/config.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,14 @@ def validate_extension(cls, value):
128128
)
129129
return value
130130

131+
@field_validator("doc_path")
132+
def validate_path(cls, value):
133+
path = Path(value)
134+
if not path.exists():
135+
raise TypeError("Provided doc_path doesn't exist.")
136+
if not path.is_dir():
137+
raise TypeError("Provided doc_path is not a directory.")
138+
return value
131139

132140
class EmbedddingsSpladeConfig(BaseModel):
133141
n_batch: int = 3
@@ -274,7 +282,10 @@ class SemanticSearchConfig(BaseModel):
274282
max_k: int = 15
275283
"""Maximum number of documents to retrieve for dense OR sparse embedding (if using both, number of documents will be k*2)"""
276284

277-
max_char_size: int = 2048
285+
score_cutoff: Optional[float] = None
286+
"""Documents with score less than specified will be excluded from relevant documents"""
287+
288+
max_char_size: int = 16384
278289
"""Maximum character size for query + documents to fit into context window of LLM."""
279290

280291
query_prefix: str = ""

src/llmsearch/ranking.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# from llmsearch.utils import LLMBundle
33
from typing import List, Tuple
44

5+
from sentence_transformers.util import semantic_search
56
import torch
67
from loguru import logger
78
from sentence_transformers.cross_encoder import CrossEncoder
@@ -183,6 +184,11 @@ def get_relevant_documents(
183184
len_ = 0
184185

185186
for doc in docs:
187+
# Skip document with lower than cutoff score, if specified
188+
if config.score_cutoff is not None and doc.metadata['score'] < config.score_cutoff:
189+
logger.info(f"Skipping document {doc.metadata['document_id']} with score: {doc.metadata['score']}")
190+
continue
191+
# if doc.metadata['score']
186192
doc_length = len(doc.page_content)
187193
if len_ + doc_length < config.max_char_size - offset_max_chars:
188194
most_relevant_docs.append(doc)

uv.lock

Lines changed: 1281 additions & 1635 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)