VectorIndexAutoRetriever
class:from llama_index.core.retrievers import VectorIndexAutoRetriever retriever = VectorIndexAutoRetriever( index, vector_store_info=vector_store_info, similarity_top_k=2, empty_query_top_k=10, # if only metadata filters are specified, this is the limit verbose=True, )
IndexNode
, with an index id linking back source document. This will allow us to do recursive retrieval in the next section (which depends on IndexNode objects linking to downstream retrievers/query engines/other Nodes).filters = Filter( should=[ Filter( must=[ FieldCondition( key="fruit", match=MatchValue(value="apple"), ), FieldCondition( key="city", match=MatchValue(value="Tokyo"), ), ] ), Filter( must=[ FieldCondition( key="fruit", match=MatchValue(value="grape"), ), FieldCondition( key="city", match=MatchValue(value="Toronto"), ), ] ), ] ) retriever = index.as_retriever(vector_store_kwargs={"qdrant_filters": filters})
index
and vector_store_info
with your own Qdrant index and vector store information. Also, the filters should be adjusted according to your specific needs.sentence_window_query_engine
, it seems to be a different type of query engine. If you want to switch from sentence_window_query_engine
to VectorIndexAutoRetriever
, you would need to instantiate the VectorIndexAutoRetriever
as shown above and use it for your retrieval tasks.VectorIndexAutoRetriever
with the appropriate filters. If the query does not require filters, it will use the sentence_window_query_engine
.class CustomRetriever: def __init__(self, vector_index_auto_retriever, sentence_window_query_engine): self.vector_index_auto_retriever = vector_index_auto_retriever self.sentence_window_query_engine = sentence_window_query_engine def retrieve(self, query): if self._requires_filters(query): return self.vector_index_auto_retriever.retrieve(query) else: return self.sentence_window_query_engine.retrieve(query) def _requires_filters(self, query): # Implement your logic here to decide whether the query requires filters or not pass
_requires_filters
method to decide whether the query requires filters or not. This could be based on the presence of certain keywords, the structure of the query, or any other criteria that you decide.CustomRetriever
, you can instantiate it with your VectorIndexAutoRetriever
and sentence_window_query_engine
.custom_retriever = CustomRetriever(vector_index_auto_retriever, sentence_window_query_engine)
custom_retriever
to retrieve documents based on the query. The custom_retriever
will decide whether to use the Qdrant filters or not based on the query.response = custom_retriever.retrieve("Your query here")