Replies: 2 comments
-
🤖 Hey @dokato! Great to see you back with another intriguing question. Hope you've been doing well since our last chat. 😊 Based on the information you provided, it seems like you're trying to retrieve a specific document from your vector store based on its However, you can achieve this by using the Here is an example of how you can use it: from langchain_core.vectorstores import PGVector
# Assuming you have a connection string to your database
CONNECTION_STRING = "postgresql://user:password@localhost:5432/mydatabase"
# Create a PGVector instance
docsearch = PGVector.from_texts(
texts=["foo", "bar", "baz"],
collection_name="test_collection_filter",
embedding=FakeEmbeddingsWithAdaDimension(),
metadatas=[{"page_id": "1"}, {"page_id": "2"}, {"page_id": "3"}],
connection_string=CONNECTION_STRING,
pre_delete_collection=True,
)
# Search for a specific page_id
output = docsearch.similarity_search_with_score("foo", k=1, filter={"page_id": "1"}) In this example, the Please note that the metadata fields you want to filter by need to be included in the You can find more information about this in the test functions Please note that this approach will still perform a similarity search, but the results will be filtered based on the metadata. If you need to directly query by metadata without performing a similarity search, you might need to implement a custom solution outside of LangChain. I hope this helps! If you have any further questions, feel free to ask. Sources
|
Beta Was this translation helpful? Give feedback.
-
I can't access : Would you point me to the tests for metadata search? Would like to check the functionality? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Checked other resources
Commit to Help
Example Code
Description
I'm building an agent that retrieves the page id from the content of the message. Now I want to query that id from my vector store, but I don't want to run similarity search on vectors, but instead just fetch a specific
page_id
based on the metadata in my store. Can I do that with langchain?The example above return page that mentions my page_id in the content, and not the page of that particular page_id that I want.
System Info
langchain==0.1.4
langchain-community==0.0.16
langchain-core==0.1.16
langchain-openai==0.0.5
macos
Beta Was this translation helpful? Give feedback.
All reactions