Metadata retrieval #5755
-
I am implementing a RAG agent using PGVector and the retrieval tool. I inserted the data in PGVector and want the AI model to retrieve it using metadata. aka. the model will search for a ticket/release name or id and that should be retrieved using metadata. But I cant find a way to filter using metadata. Any ideas? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hey @ZeyadAttia-Tek! 👋 I'm here to help you with any bugs, questions, or contributions while you wait for a human maintainer. Let's tackle this together! To filter and retrieve data using metadata in a RAG agent implemented with PGVector and the retrieval tool, you can use the from langflow.custom import Component
from langflow.io import MessageTextInput
class VectaraRagComponent(Component):
# Other configurations...
inputs = [
# Other inputs...
MessageTextInput(
name="filter",
display_name="Metadata Filters",
value="",
advanced=True,
info="The filter string to narrow the search to according to metadata attributes.",
),
# Other inputs...
]
def generate_response(self) -> Message:
# Other configurations...
config = VectaraQueryConfig(
lambda_val=self.lexical_interpolation,
filter=self.filter, # Use the filter here
summary_config=summary_config,
rerank_config=rerank_config,
)
rag = vectara.as_rag(config)
response = rag.invoke(self.search_query, config={"callbacks": self.get_langchain_callbacks()})
text_output = response["answer"]
return Message(text=text_output) Set 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.
To filter and retrieve data using metadata with plain Python, PGVector, and the Agent component in Langflow, you can create a custom component that interacts with PGVector. Here's a general approach:
Create a Custom Component: Define a custom component that connects to your PGVector instance and performs queries based on metadata.
Build the Vector Store: Use the
build
method to create a vector store from your PGVector instance. This method can handle inputs and create a vector store using the provided connection string and collection name.Query with Metadata: Implement a method to query the vector store using metadata. You can use SQL queries or PGVector's built-in methods to filt…