Skip to content

Commit

Permalink
Updated retrieve_from docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
antoninoLorenzo committed Aug 12, 2024
1 parent 8681efa commit bde431a
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/agent/knowledge/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,33 @@ def retrieve(self, query: str, limit: int = 3):
)
return self.retrieve_from(query, collection_name, limit)

def retrieve_from(self, query: str, collection_name: str, limit: int = 3):
"""Performs retrieval of chunks from the vector database"""
def retrieve_from(self, query: str, collection_name: str,
limit: int = 3,
threshold: int = 0.5) -> list[str] | None:
"""Performs retrieval of chunks from the vector database.
:param query:
A natural language query used to search in the vector database.
:param collection_name:
The name of the collection where the search happens; the collection
must exist inside the vector database.
:param limit:
Number of maximum results returned by the search.
:param threshold:
Minimum similarity score that must be satisfied by the search
results.
:return: list of chunks or None
"""
if len(query) < 3:
return None

hits = self._connection.search(
collection_name=collection_name,
query_vector=self._encoder(self._embedding_model, query)['embedding'],
limit=limit,
score_threshold=0.5
score_threshold=threshold
)
return [points.payload['text'] for points in hits]
results = [points.payload['text'] for points in hits]
return results if results else None

def get_available_collections(self):
"""Makes a query to Qdrant and uses collections metadata to get
Expand Down

0 comments on commit bde431a

Please sign in to comment.