Skip to content

Commit

Permalink
Merge pull request Sinaptik-AI#1376 from Sinaptik-AI/fix/qdrant_no_co…
Browse files Browse the repository at this point in the history
…llection

fix(Qdrant): handle queries if no doc or qa added
  • Loading branch information
ArslanSaleem authored Sep 25, 2024
2 parents 2f4a80f + e67d105 commit db2e145
Show file tree
Hide file tree
Showing 3 changed files with 2,886 additions and 2,398 deletions.
24 changes: 20 additions & 4 deletions pandasai/ee/vectorstores/qdrant.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,14 @@ def get_relevant_question_answers(self, question: str, k: int = 1) -> List[dict]
"""
Returns relevant question answers based on search
"""
if not self._client.collection_exists(self._qa_collection_name):
return {
"documents": [],
"distances": [],
"metadatas": [],
"ids": [],
}

response = self._client.query(
self._qa_collection_name,
query_text=question,
Expand All @@ -285,13 +293,19 @@ def get_relevant_docs(self, question: str, k: int = 1) -> List[dict]:
"""
Returns relevant documents based on semantic search
"""
if not self._client.collection_exists(self._docs_collection_name):
return {
"documents": [],
"distances": [],
"metadatas": [],
"ids": [],
}
response = self._client.query(
self._docs_collection_name,
query_text=question,
limit=k,
score_threshold=self._similarity_threshold,
)

return self._convert_query_response(response)

def get_relevant_question_answers_by_id(self, ids: Iterable[str]) -> List[dict]:
Expand Down Expand Up @@ -356,9 +370,11 @@ def _convert_ids(self, ids: Iterable[str]) -> List[str]:
This allows us to overwrite the same point with the original ID.
"""
return [
id
if self._is_valid_uuid(id)
else str(uuid.uuid5(uuid.UUID(UUID_NAMESPACE), id))
(
id
if self._is_valid_uuid(id)
else str(uuid.uuid5(uuid.UUID(UUID_NAMESPACE), id))
)
for id in ids
]

Expand Down
Loading

0 comments on commit db2e145

Please sign in to comment.