Ask questions based not only on page_content but also on metadata. #9868
Replies: 1 comment 2 replies
-
🤖 Hello, Based on your description, it seems like you're trying to configure the LLM Agent to utilize both page_content and metadata from a Document, and perform searches based on metadata fields in a question. To achieve this, you can use the Here's how you can use it: from langchain import BaseLanguageModel
from langchain.chains.query_constructor.schema import AttributeInfo
# Assuming you have an instance of BaseLanguageModel
llm = BaseLanguageModel()
# Document contents and metadata
document_contents = "<your document contents>"
attribute_info = [
AttributeInfo(name="<metadata field 1>", type="<type>", description="<description>"),
AttributeInfo(name="<metadata field 2>", type="<type>", description="<description>"),
# Add more AttributeInfo objects as needed
]
# Load the query constructor chain
chain = load_query_constructor_chain(llm, document_contents, attribute_info) In the Please replace Regarding the The Here is the relevant code: llm_chain = load_query_constructor_chain(
llm,
document_contents,
metadata_field_info,
enable_limit=enable_limit,
**chain_kwargs,
) In the context shared, I hope this helps! If you have any other questions, feel free to ask. Sources
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone! I am pretty new to LangChain, I'm trying to build LLM Agent, that will answer questions based on DataFrame. I am using gpt-3.5-turbo, so my context windows is 4096 tokens, my dataframe contains 195K tokens, to I can't input it fully into llm. I have devided it into chunks, stored in vectore storage in embedded format and tryed using several approaches to get answer to some dataframe-based question. I have used
AttributeInfo()
to specify what metadata atribute llm should use, when is recieves some question, here is code sample of AttributeInfo:I have added metadata_field_info into SelfQueryRetriever:
When i have used retriever - it actually have found some Documents, that are simillar to the question, but when I tried to use more complex questions, for example: "Provide texts, whose title contains word 'shotgun'" (and in dataset there are several texts, whose title contains that word) I received next:
That was the first problem, that i ancountered.
Then I tried to build LLM Agent, here is code snipper:
Agent worked, but only on page_content data, it did't use any metadata.
My question is, how can I make LLM Agent, that will use Document with page_content and metadata and fill serach for metadata fileds in question (as in worked in SelfQueryRetriever with AttributeInfo) and try to answer baed on both data: page_content and metadata?
Beta Was this translation helpful? Give feedback.
All reactions