Closed inoue0426 closed 1 month ago
Hi, thank you for reaching out! The notebook in the examples directory is outdated and should not be used. You should either follow the code in the tutorial (https://langchain-ai.github.io/langgraph/tutorials/rag/langgraph_adaptive_rag_local) or in this notebook from the repo: https://github.com/langchain-ai/langgraph/blob/main/docs/docs/tutorials/rag/langgraph_adaptive_rag_local.ipynb. Lmk if you have any other questions!
Checked other resources
https://github.com/langchain-ai/langgraph/blob/main/examples/rag/langgraph_rag_agent_llama3_local.ipynb
[Sep 22 2024 Comments: ] It looks like the sample documentation is correct. Just the github version is incorrect.
https://langchain-ai.github.io/langgraph/tutorials/rag/langgraph_adaptive_rag_local
Example Code
Error Message and Stack Trace (if applicable)
Description
Description
I encountered a
KeyError: 'documents'
in the web search function of this notebook. This error occurs when trying to access the 'documents' key from thestate
dictionary, which may not always exist. Proper error handling is needed to make the function more robust.Current Behavior
The function assumes that
state["documents"]
always exists, leading to a KeyError when it doesn't.Expected Behavior
The function should handle cases where
state["documents"]
doesn't exist, initializing it as an empty list if necessary.Proposed Solution
Modify the code to use
state.get("documents", [])
instead of directly accessingstate["documents"]
. This change will return an empty list if the 'documents' key doesn't exist, preventing the KeyError.Code Changes
Would it be acceptable for me to create a Pull Request with these changes?
System Info
➜ python -m langchain_core.sys_info
System Information
Package Information
Optional packages not installed
Other Dependencies