33
44
55import os
6+ from types import SimpleNamespace
67
78from haystack_integrations .components .retrievers .qdrant import QdrantEmbeddingRetriever
89from haystack_integrations .document_stores .qdrant import QdrantDocumentStore
@@ -26,7 +27,7 @@ class OpeaQDrantRetriever(OpeaComponent):
2627 def __init__ (self , name : str , description : str , config : dict = None ):
2728 super ().__init__ (name , ServiceType .RETRIEVER .name .lower (), description , config )
2829
29- self .retriever = self ._initialize_client ()
30+ self .db_store , self . retriever = self ._initialize_client ()
3031 health_status = self .check_health ()
3132 if not health_status :
3233 logger .error ("OpeaQDrantRetriever health check failed." )
@@ -43,7 +44,7 @@ def _initialize_client(self) -> QdrantEmbeddingRetriever:
4344
4445 retriever = QdrantEmbeddingRetriever (document_store = qdrant_store )
4546
46- return retriever
47+ return qdrant_store , retriever
4748
4849 def check_health (self ) -> bool :
4950 """Checks the health of the retriever service.
@@ -55,7 +56,7 @@ def check_health(self) -> bool:
5556 logger .info ("[ check health ] start to check health of QDrant" )
5657 try :
5758 # Check the status of the QDrant service
58- _ = self .retriever .client
59+ _ = self .db_store .client
5960 logger .info ("[ check health ] Successfully connected to QDrant!" )
6061 return True
6162 except Exception as e :
@@ -75,6 +76,14 @@ async def invoke(self, input: EmbedDoc) -> list:
7576
7677 search_res = self .retriever .run (query_embedding = input .embedding )["documents" ]
7778
79+ # format result to align with the standard output in opea_retrievers_microservice.py
80+ final_res = []
81+ for res in search_res :
82+ dict_res = res .meta
83+ res_obj = SimpleNamespace (** dict_res )
84+ final_res .append (res_obj )
85+
7886 if logflag :
79- logger .info (f"[ similarity search ] search result: { search_res } " )
80- return search_res
87+ logger .info (f"[ similarity search ] search result: { final_res } " )
88+
89+ return final_res
0 commit comments