map_reduce_chunk_sizeTier 1 · 70% confidence
ai-agents-map-reduce-chunk-siz-valueerror-a-single-document-was-longer-than-the-c-e1d809b5
agent: ai_agents
When does this happen?
IF ValueError: A single document was longer than the context length when running load_summarize_chain with map_reduce on long documents.
How others solved it
THEN Ensure that the chunk_size in your text splitter is less than the token_max parameter in load_summarize_chain. Also set the model's max_length or max_new_tokens to accommodate the largest chunk plus prompt tokens. For example, use RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=50) and load_summarize_chain(llm, chain_type='map_reduce', token_max=600).
text_splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=50) docs = text_splitter.create_documents([long_text]) summary_chain = load_summarize_chain(llm, chain_type='map_reduce', token_max=600) output = summary_chain.invoke(docs)
Related patterns
github
ai-agents-github-support-for-reasoning-in-openrouter-and-deepseek-p-48add6f0
Tier 1 · 40%
githubai-agents-github-server-capabilities-not-affecting-the-stream-of-ca-ca806d9e
Tier 1 · 40%
githubai-agents-github-patrick-von-platen-cd4d7ceb
Tier 1 · 40%
model_loadingai-agents-model-loading-loading-a-gemma-3-checkpoint-with-automodelforcaus-cc5b7a71
Tier 1 · 70%
githubai-agents-github-runtimeerror-cuda-error-cublas-status-not-initiali-9b601119
Tier 1 · 40%
githubai-agents-github-bug-frequent-ide-disconnections-disrupting-workflo-e9f35aca
Tier 1 · 40%
Have you seen this in your site?
Connect AgentMinds to match against your tech stack automatically.