How to pass a filtering query to an AzureVectorIndexRetriever #28742
Replies: 2 comments
-
To correctly implement a filtering query in query = "What did the president say about Ketanji Brown Jackson"
docs = vectorstore.similarity_search(
query,
pre_filter={"metadata.source": {"$eq": "specific_document_name.txt"}},
) This query filters the results to only include chunks from the document with the specified name in the Regarding the error you encountered with To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other |
Beta Was this translation helpful? Give feedback.
-
What worked for me is to use |
Beta Was this translation helpful? Give feedback.
-
I use Azure Index as my vector database, and use the
AzureSearchVectorStoreRetriever
as my retriever in my Langgraph rag chain.I have a requirement of retrieving chunks belonging to a specific document, i.e having a specific source metadata field. I attempt to pass a filter query using the following line :
azureIndex = AzureVectorIndex() retriever = azureIndex.get_retriever( search_kwargs={ "filter": { "source": "source_doc" } } )
However, I get this error:
TypeError: AzureVectorIndex.get_retriever() got an unexpected keyword argument 'search_kwargs'
I also attempt to use an Odata filtering query to the retriever but I constantly get an invalid query. Can you give me a sample correct Odata query to filter the retrieval and only run a retrieval/similarity search over documents from a specified source doc? how do I correctly implement this filtering?
retriever = AzureAISearchRetriever( content_key="content", top_k=5, index_name=index_name, service_name=os.getenv("AZUREAI_SERVICE_NAME"), api_key=os.getenv("VECTOR_STORE_PASSWORD"), filter="search.in(source,'')" )
Beta Was this translation helpful? Give feedback.
All reactions