I’m nearing the end of my allotted time and I’m attempting to solve the assessment. However, I’ve come to a brick wall. I’ve gone through all the posts involving this course, but I cannot seem to get my retriever chain to work. The Generator is giving me an OK, but I’m getting the following error when I attempt to talk to the RAG agent.
File "/usr/local/lib/python3.11/site-packages/pydantic/v1/main.py", line 716, in validate
value_as_dict = dict(value)
^^^^^^^^^^^
ValueError: dictionary update sequence element #0 has length 1; 2 is required
This is my notebook code and the full respective error message I’m getting.
Do you think you could assist me @vkudlay ? Any help is appreciated to get me pointed in the correct direction.
Side Note: I suspect that as you’ve stated previously to another user, I’m doing too much in my retriever chain. Though I’m not sure what less I could possibly do.
Hey @mrpk91! Good stuff!
You are exactly correct. You are doing too much in your retriever chain (and also just in general). The source code in the frontend is already running, so you should not be re-implementing the things that are running there. That whole process with the chains_dict = {...} is what the frontend is actively doing to keep track of everything. As such, all you need to deploy on your langserve routes are the components that should slot into the system. For example, the following route - which defines “/retriever” - should deliver the functionality that chains_dict['retriever'] is there to achieve.
I replaced the chains_dict['retriever'] in the retrieval chain with docstore.as_retriever(). I also decided to make it more in-line with how it is implemented in notebook 8 and made the following change:
Unfortunately, these changes have not solved my issue. I am still receiving the same error ValueError: dictionary update sequence element #0 has length 1; 2 is required. I took some time to try and figure out what in my code could be causing this, and the conclusion I came to was that the information I am passing to the retrieval chain is possibly not in the correct format or in the way it is expected to be received. I’m not confident that this is correct, but it is the best I can come up with.
I obviously don’t want you to give me the direct answer, but I think helping me better understand this error should allow me to come to a better conclusion. As of right now, I don’t know how to debug this error and any direction you provide will be helpful. If it helps, I’m doing this assignment in the course environment only. Thank you once again for the help so far :)
Side Note: If I run out of time, is there any way for me to get more?
This is still too much, both for the generator and retriever.
### This line should be called by you to deliver your retrieval chain.
add_routes(
app,
retrieval_chain,
path="/retriever",
)
### This line is perpetually running in the frontend. This should not be anywhere in your code.
retrieval_chain = (
{'input' : (lambda x: x)}
| RunnableAssign(
{'context' : itemgetter('input')
| chains_dict['retriever'] ### AKA RemoteRunnable("http://lab:9012/retriever/")
| LongContextReorder().transform_documents
| docs2str
})
)
It is likely the same issue as encountered here: python - Error: “dictionary update sequence element #0 has length 1; 2 is required” on Django 1.4 - Stack Overflow. It’s a bit opaque, but it’s definitely happening because you are accidentally passing in something illegal. At some point, you are accidentally trying to cast a string to a dict along some protocol. This is likely because your retrieval chain is tossing back a dictionary with values {"context": "..."} instead of a list of documents.
Sure! Let me know if you run out of time (and include the email address of your account) and I can extend