File Chunking Configuration
To prevent timeouts when reviewing large files, the tool automatically splits files into manageable chunks based on function boundaries.
File Chunking Configuration
Overview
To prevent timeouts when reviewing large files, the tool automatically splits files into manageable chunks based on function boundaries.
How It Works
- Small files (< threshold) are reviewed in one pass
- Large files (>= threshold) are split by function into chunks
- Each chunk is reviewed separately with
ACTION: NEXT_CHUNK - Context is maintained between chunks
Default Settings
review:
chunk_threshold: 400 # Files >= 400 lines are chunked
chunk_size: 250 # Maximum 250 lines per chunk
Timeout Settings
llm:
timeout: 600 # 10 minutes
Customization
For Fast GPUs (128GB+ VRAM)
If you have a powerful GPU and want larger chunks:
review:
chunk_threshold: 600 # Larger threshold
chunk_size: 400 # Larger chunks
llm:
timeout: 900 # 15 minutes for larger chunks
For Slower Models or Limited Resources
If you're still getting timeouts:
review:
chunk_threshold: 200 # Chunk sooner
chunk_size: 150 # Smaller chunks
llm:
timeout: 300 # 5 minutes (faster to detect issues)
For Very Large Files
If you have files with 5000+ lines:
review:
chunk_threshold: 300 # Chunk early
chunk_size: 200 # Small chunks for consistency
Troubleshooting Timeouts
Symptom: "ERROR: Request timed out"
Cause: The model is taking too long to process the chunk.
Solutions (try in order):
-
Reduce chunk size (current: 250 lines)
review: chunk_size: 150 -
Lower chunk threshold (current: 400 lines)
review: chunk_threshold: 200 -
Increase timeout (current: 600s)
llm: timeout: 900 -
Check LLM provider health
make validate -
Reduce context window
- Clear old beads:
bd close --all - Delete old lessons:
rm .ai-code-reviewer/LESSONS.md - Restart review session
- Clear old beads:
Symptom: Chunks too small, too many chunks
Cause: Settings are too aggressive for your hardware.
Solution: Increase chunk size:
review:
chunk_threshold: 600
chunk_size: 400
Symptom: AI asks to review same file multiple times
Cause: Chunk tracking might be confused.
Solution:
- Use
ACTION: SKIP_FILEto move on - Try different directory with
ACTION: SET_SCOPE
How Chunking Works Internally
C File Chunking Strategy
- Parse file for function boundaries using regex
- Split by functions (each function = potential chunk)
- Group small functions together (up to chunk_size)
- Split large functions (>2x chunk_size) into sub-chunks
- Include context (headers, globals, up to 20 lines between functions)
Example
File with 1200 lines, 10 functions:
threshold: 400, chunk_size: 250
Chunk 1: Header + includes (50 lines)
Chunk 2: Function 1 (200 lines)
Chunk 3: Function 2 (150 lines)
Chunk 4: Function 3 + Function 4 (180 lines combined)
Chunk 5: Function 5 (part 1) (250 lines)
Chunk 6: Function 5 (part 2) (220 lines)
Chunk 7: Functions 6-8 (240 lines combined)
Chunk 8: Function 9 (190 lines)
Chunk 9: Function 10 + footer (120 lines)
Migration
Existing users will automatically get new defaults via config-update:
- Timeout: 300s → 600s
- Threshold: 800 → 400 lines
- Chunk size: 500 → 250 lines
Run make config-update or python scripts/config_update.py to apply.
Benefits of Smaller Chunks
- Faster responses - Model processes less text
- Better focus - AI reviews one function at a time
- Reduced memory - Lower GPU VRAM usage
- Fewer timeouts - More predictable processing time
- Better error messages - Issues isolated to specific functions
Trade-offs
Smaller chunks (150-200 lines):
- ✅ Faster, fewer timeouts
- ❌ More chunks to review (more iterations)
- ❌ Less context between functions
Larger chunks (400-500 lines):
- ✅ Fewer chunks (faster overall)
- ✅ More context visible
- ❌ Higher risk of timeouts
- ❌ Requires more GPU memory
Recommended Settings by Use Case
FreeBSD kernel (large C files, complex)
review:
chunk_threshold: 300
chunk_size: 200
llm:
timeout: 600
User-space utilities (smaller files)
review:
chunk_threshold: 500
chunk_size: 300
llm:
timeout: 600
Mixed codebase (safe defaults)
review:
chunk_threshold: 400
chunk_size: 250
llm:
timeout: 600
Related Documents
基于命题分块以增强RAG
命题分块技术(Proposition Chunking)——这是一种通过将文档分解为原子级事实陈述来实现更精准检索的先进方法。与传统仅按字符数分割文本的分块方式不同,命题分块能保持单个事实的语义完整性。
TileMap Chunk Manager
**Category:** Performance - 2D Rendering & Memory Management
🤖 n8n AI Agent Mastery Course 2025
Welcome to the most comprehensive n8n AI Agent course! Build powerful automation workflows and intelligent AI agents using n8n's visual workflow builder.
Document Chunking/Splitting in Langroid
Langroid's [`ParsingConfig`][langroid.parsing.parser.ParsingConfig]