Skip to content

Commit 79a5683

Browse files
committed
feat: ignore irrelevant documents
1 parent 3efc628 commit 79a5683

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

server/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class Config(BaseSettings):
4848
document_index_prefix: str = 'doc'
4949
document_index_tag: str = 'chat_id'
5050
embedding_dimensions: int = 768
51+
minimum_similarity_score: float = 0.3
5152

5253
redis_host: str = 'redis'
5354
redis_port: int = 6379

server/databases/redis/wrapper.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ class Mappings(TypedDict):
2222
2323
Attributes
2424
----------
25+
score (float) : the document's score
2526
vector (bytes) : the document's vector
2627
content (str) : the document's content
2728
chat_id (str) : the document's tag
2829
"""
2930

31+
score: float
3032
vector: bytes
3133
content: str
3234
chat_id: str
@@ -142,7 +144,11 @@ async def search(self, search_field: str, embedding: NDArray[float32], top_k: in
142144
redis_query_parameters, # type: ignore (this is a bug in the redis-py library)
143145
)
144146

145-
return ' '.join(document['content'] for document in search_response.docs)
147+
return ' '.join(
148+
document['content']
149+
for document in search_response.docs
150+
if float(document['score']) > Config.minimum_similarity_score
151+
)
146152

147153
async def save_messages(
148154
self,

0 commit comments

Comments
 (0)