[PR #5222] DOC: Add missing docs_txt = format_docs() lines in adaptive RAG tutorial #4311

Closed
opened 2026-02-20 17:50:00 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langchain-ai/langgraph/pull/5222

State: closed
Merged: Yes


Summary

Fixes missing docs_txt = format_docs(docs) lines in the adaptive RAG tutorial that were causing raw document objects to be passed directly to the RAG chain instead of properly formatted text.

Issue Fixed

Closes #5216

Details

The format_docs function was already properly defined in the notebook:

def format_docs(docs):
    return "\n\n".join(doc.page_content for doc in docs)

However, it wasn't being called before passing documents to the RAG chain. This caused Document objects to be passed directly instead of formatted text strings, which is the expected input format.

Before:

generation = rag_chain.invoke({"context": documents, "question": question})

After:

docs_txt = format_docs(documents)
generation = rag_chain.invoke({"context": docs_txt, "question": question})

Testing

The tutorial notebook should now work correctly with properly formatted document context being passed to the RAG chain.

Type of Change

  • Documentation fix
  • Bug fix (non-breaking change which fixes an issue)
**Original Pull Request:** https://github.com/langchain-ai/langgraph/pull/5222 **State:** closed **Merged:** Yes --- ## Summary Fixes missing `docs_txt = format_docs(docs)` lines in the adaptive RAG tutorial that were causing raw document objects to be passed directly to the RAG chain instead of properly formatted text. ## Issue Fixed Closes #5216 ## Details The `format_docs` function was already properly defined in the notebook: ```python def format_docs(docs): return "\n\n".join(doc.page_content for doc in docs) ``` However, it wasn't being called before passing documents to the RAG chain. This caused Document objects to be passed directly instead of formatted text strings, which is the expected input format. ### Before: ```python generation = rag_chain.invoke({"context": documents, "question": question}) ``` ### After: ```python docs_txt = format_docs(documents) generation = rag_chain.invoke({"context": docs_txt, "question": question}) ``` ## Testing The tutorial notebook should now work correctly with properly formatted document context being passed to the RAG chain. ## Type of Change - [x] Documentation fix - [x] Bug fix (non-breaking change which fixes an issue)
yindo added the pull-request label 2026-02-20 17:50:00 -05:00
yindo closed this issue 2026-02-20 17:50:00 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#4311