How to search nearest vector using metadata #28609
deepak-hl
announced in
Ask Dosu (Archived)
Replies: 1 comment 8 replies
-
To search for the nearest vector using the metadata field "username" in your provided Python code, you can apply a filter in the def retrieval_qa_chain():
prompt = create_prompt_template()
embedding = OpenAIEmbeddings()
llm = ChatOpenAI(model="gpt-4o", temperature=0.5)
vector_store = PGVector(
connection_string=PGVECTOR_CONNECTION_STRING,
collection_name=persist_directory,
embedding_function=embedding,
)
# Add a filter to search_kwargs to filter by the "username" metadata
retriever = vector_store.as_retriever(
search_kwargs={
"k": 8,
"filter": {"username": {"$eq": "army_shiba"}}
}
)
chain = RetrievalQA.from_llm(
llm=llm,
return_source_documents=True,
retriever=retriever,
prompt=prompt,
)
return chain In this modification, the 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.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
here is my metadata: {
"date": "2024-12-04T09:38:25+00:00",
"tweet_id": "1864242846162710544",
"username": "army_shiba"
}
how to search nearest vector using metadata username
Beta Was this translation helpful? Give feedback.
All reactions