Skip to content

Commit

Permalink
Fix Qdrant retriever RAG issue. (#1289)
Browse files Browse the repository at this point in the history
* Fix Qdrant retriever no retrieved result issue.
Signed-off-by: letonghan <[email protected]>
  • Loading branch information
letonghan authored Feb 14, 2025
1 parent 47f68a4 commit c3c8497
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion comps/retrievers/deployment/docker_compose/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ services:
RETRIEVER_COMPONENT_NAME: ${RETRIEVER_COMPONENT_NAME:-OPEA_RETRIEVER_QDRANT}
QDRANT_HOST: ${QDRANT_HOST}
QDRANT_PORT: ${QDRANT_PORT}
INDEX_NAME: ${INDEX_NAME}
QDRANT_INDEX_NAME: ${INDEX_NAME}
depends_on:
qdrant-vector-db:
condition: service_healthy
Expand Down
19 changes: 14 additions & 5 deletions comps/retrievers/src/integrations/qdrant.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@


import os
from types import SimpleNamespace

from haystack_integrations.components.retrievers.qdrant import QdrantEmbeddingRetriever
from haystack_integrations.document_stores.qdrant import QdrantDocumentStore
Expand All @@ -26,7 +27,7 @@ class OpeaQDrantRetriever(OpeaComponent):
def __init__(self, name: str, description: str, config: dict = None):
super().__init__(name, ServiceType.RETRIEVER.name.lower(), description, config)

self.retriever = self._initialize_client()
self.db_store, self.retriever = self._initialize_client()
health_status = self.check_health()
if not health_status:
logger.error("OpeaQDrantRetriever health check failed.")
Expand All @@ -43,7 +44,7 @@ def _initialize_client(self) -> QdrantEmbeddingRetriever:

retriever = QdrantEmbeddingRetriever(document_store=qdrant_store)

return retriever
return qdrant_store, retriever

def check_health(self) -> bool:
"""Checks the health of the retriever service.
Expand All @@ -55,7 +56,7 @@ def check_health(self) -> bool:
logger.info("[ check health ] start to check health of QDrant")
try:
# Check the status of the QDrant service
_ = self.retriever.client
_ = self.db_store.client
logger.info("[ check health ] Successfully connected to QDrant!")
return True
except Exception as e:
Expand All @@ -75,6 +76,14 @@ async def invoke(self, input: EmbedDoc) -> list:

search_res = self.retriever.run(query_embedding=input.embedding)["documents"]

# format result to align with the standard output in opea_retrievers_microservice.py
final_res = []
for res in search_res:
dict_res = res.meta
res_obj = SimpleNamespace(**dict_res)
final_res.append(res_obj)

if logflag:
logger.info(f"[ similarity search ] search result: {search_res}")
return search_res
logger.info(f"[ similarity search ] search result: {final_res}")

return final_res
3 changes: 2 additions & 1 deletion comps/retrievers/src/opea_retrievers_microservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ async def ingest_files(
r.metadata["b64_img_str"] = [input.base64_image, r.metadata["b64_img_str"]]
else:
r.metadata["b64_img_str"] = input.base64_image
metadata_list.append(r.metadata)
if r.metadata:
metadata_list.append(r.metadata)
retrieved_docs.append(TextDoc(text=r.page_content))
result = SearchedMultimodalDoc(
retrieved_docs=retrieved_docs, initial_query=input.text, metadata=metadata_list
Expand Down

0 comments on commit c3c8497

Please sign in to comment.