[GH-ISSUE #5535] RAG: Embedded code files are truncated when context window is exceeded #5154

Closed
opened 2026-06-05 14:52:20 -04:00 by yindo · 1 comment
Owner

Originally created by @miraitech24 on GitHub (Apr 25, 2026).
Original GitHub issue: https://github.com/Mintplex-Labs/anything-llm/issues/5535

Problem Description
When embedding code files or long documents, the LLM only sees a portion of the content. The model's response cuts off mid-way, as if the context was pruned. This makes code analysis workflows unusable.

Steps to Reproduce

  1. Create a workspace
  2. Upload a moderate-length code file (e.g., 300-500 lines of Python/JavaScript)
  3. Wait for embedding to complete
  4. Ask a question that requires reading the middle or end of the file: 'What does function X at line 300 do?'
  5. Model's response either:
    • Cuts off mid-sentence
    • Says it can't find the function
    • Only references the beginning of the file

What I suspect is happening
Based on AnythingLLM documentation, when the context window is exceeded, the system automatically prunes/truncates the context. For code files with high information density, this pruning likely removes critical content.

Expected Behavior
The full embedded content should be accessible to the LLM, or at minimum:

  • User should be warned when truncation occurs
  • User should have control over truncation strategy
  • Code files should have different chunking/pruning rules than plain text

Actual Behavior
Silent truncation. The LLM behaves as if it has read the whole file, but its responses show it only saw a fragment.

Why This Matters
Code files are not natural language. Removing 'less relevant' lines breaks syntax, logic flow, and variable references. This is not just a 'precision' issue — it fundamentally breaks code understanding.

Suggested Investigation Points

  1. Does AnythingLLM log when context truncation happens?
  2. Can users configure truncation behavior per workspace?
  3. Should code files have larger chunk sizes or different overlap settings?

Temporary Workaround Attempted

  • Reducing chunk size → worse, loses more context
  • Increasing chunk size → triggers truncation faster
  • Manual file splitting → defeats the purpose of RAG

Environment

  • AnythingLLM version: [please fill]
  • OS: [please fill]
  • DeepSeek API via Generic OpenAI provider
  • Default embedding model (all-miniLM-L6)

Example Request
If needed, I can provide a sample code file and exact queries that demonstrate the truncation.

Originally created by @miraitech24 on GitHub (Apr 25, 2026). Original GitHub issue: https://github.com/Mintplex-Labs/anything-llm/issues/5535 **Problem Description** When embedding code files or long documents, the LLM only sees a portion of the content. The model's response cuts off mid-way, as if the context was pruned. This makes code analysis workflows unusable. **Steps to Reproduce** 1. Create a workspace 2. Upload a moderate-length code file (e.g., 300-500 lines of Python/JavaScript) 3. Wait for embedding to complete 4. Ask a question that requires reading the middle or end of the file: 'What does function X at line 300 do?' 5. Model's response either: - Cuts off mid-sentence - Says it can't find the function - Only references the beginning of the file **What I suspect is happening** Based on AnythingLLM documentation, when the context window is exceeded, the system automatically prunes/truncates the context. For code files with high information density, this pruning likely removes critical content. **Expected Behavior** The full embedded content should be accessible to the LLM, or at minimum: - User should be warned when truncation occurs - User should have control over truncation strategy - Code files should have different chunking/pruning rules than plain text **Actual Behavior** Silent truncation. The LLM behaves as if it has read the whole file, but its responses show it only saw a fragment. **Why This Matters** Code files are not natural language. Removing 'less relevant' lines breaks syntax, logic flow, and variable references. This is not just a 'precision' issue — it fundamentally breaks code understanding. **Suggested Investigation Points** 1. Does AnythingLLM log when context truncation happens? 2. Can users configure truncation behavior per workspace? 3. Should code files have larger chunk sizes or different overlap settings? **Temporary Workaround Attempted** - Reducing chunk size → worse, loses more context - Increasing chunk size → triggers truncation faster - Manual file splitting → defeats the purpose of RAG **Environment** - AnythingLLM version: [please fill] - OS: [please fill] - DeepSeek API via Generic OpenAI provider - Default embedding model (all-miniLM-L6) **Example Request** If needed, I can provide a sample code file and exact queries that demonstrate the truncation.
yindo closed this issue 2026-06-05 14:52:20 -04:00
Author
Owner

@timothycarambat commented on GitHub (Apr 25, 2026):

Does AnythingLLM log when context truncation happens?

Yes, it is in the logs, but not in the UI

Can users configure truncation behavior per workspace?

It is based on your model's context window. Users should not control this as passing invalid contexts to a cloud will usually throw, and with local you will get pruned elsewhere like in LM Studio, the model will loop infinitely, or the call with throw

Should code files have larger chunk sizes or different overlap settings?

This is a new splitting strategy and is more specific to code. That being said RAG's entire purpose is chunking - so if you try to rag on code, this will happen. If anything you actually want full context ingestion - which you can get by draggin and dropping the file into chat directly or document pinning:
https://docs.anythingllm.com/chatting-with-documents/introduction#document-pinning

I think this is not specifically a bug, but a nuance of RAG vs full-doc ingestion?

<!-- gh-comment-id:4320482802 --> @timothycarambat commented on GitHub (Apr 25, 2026): > Does AnythingLLM log when context truncation happens? Yes, it is in the logs, but not in the UI > Can users configure truncation behavior per workspace? It is based on your model's context window. Users should not control this as passing invalid contexts to a cloud will usually throw, and with local you will get pruned elsewhere like in LM Studio, the model will loop infinitely, or the call with throw > Should code files have larger chunk sizes or different overlap settings? This is a new splitting strategy and is more specific to code. That being said RAG's entire purpose _is chunking_ - so if you try to rag on code, this will happen. If anything you actually want full context ingestion - which you can get by draggin and dropping the file into chat directly or document pinning: https://docs.anythingllm.com/chatting-with-documents/introduction#document-pinning I think this is not specifically a bug, but a nuance of RAG vs full-doc ingestion?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mintplex-Labs/anything-llm#5154