KeyError with MultiQueryRetriever and Custom Prompt for Fetching data from ChromaDB #28169
Unanswered
AbdelazimLokma
asked this question in
Q&A
Replies: 1 comment 1 reply
-
@AbdelazimLokma, try upgrading LangChain to the newest version by running try: retriever = MultiQueryRetriever.from_llm(
retriever=db.as_retriever(search_type="similarity", search_kwargs={"k": 2}),
llm=llm) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Checked other resources
Commit to Help
Example Code
Description
I am having trouble using MultiQueryRetriever and PromptTemplate.
My goal is to take a list of allegations against a police officer, and using the MultiQueryRetriever, have the LLM generate one query per allegation + description combination, in order to fetch the most relevant rule broken for each allegation. I have Chroma as my vector store, it contains a police department officer rule book. To do this, I am using a custom prompt that instructs the LLM to generate one Chroma query for each allegation. In order to generate this query, it must look at the allegation and try to extract potential violations (relevant to the allegation) from the description, then form a query that can be used to fetch relevant rules from Chroma. (Take a look at the actual prompt for more detail)
However, I am getting this error and have no idea why:
KeyError: "Input to PromptTemplate is missing variables {'description', 'allegations', 'num_allegations'}. Expected: ['allegations', 'description', 'num_allegations'] Received: ['question']\nNote: if you intended {description} to be part of the string and not a variable, please escape it with double curly braces like: '{{description}}'."
for some reason, it keeps saying that I only passed in a variable 'question', but when i call retriever.invoke(), I am clearly passing in the required variables.
here is an example input that is being passed in:
{'allegations': 'Conformance to Laws, Conduct Unbecoming, Respectful Treatment, Alcohol off Duty', 'description': 'Officer firstname Lastname fled from a taxicab without paying the fare. Officer Lastname was located by Officers from Area A‐7. Officer Lastname A‐7 where he was uncooperative with Sgt. Lastname and refused to talk to him. Sgt. Lastname escorted Officer Lastname back to the o his department equipment was received by Sgt. Lastname including a Glock 40 Serial # number, Radio # number, Handcuffs #number, 3 magazine Police Badge# number, 1 container of OC Spray and 1 bullet resistant vest. Department equipment to be turned over to Sgt. last name', 'num_allegations': '4'}
System Info
langchain==0.2.2
langchain-community==0.2.3
langchain-core==0.2.43
langchain-google-genai==2.0.1
langchain-openai==0.1.8
langchain-text-splitters==0.2.4
using a mac
Using Python 3.11.9
Beta Was this translation helpful? Give feedback.
All reactions