File Chunking Configuration
Configures file chunking thresholds and timeout settings to prevent timeouts when reviewing large files with an AI code reviewer.
What this file does
Configures file chunking thresholds and timeout settings to prevent timeouts when reviewing large files with an AI code reviewer.
When to use it
- You use an AI code reviewer that times out on large files
- You want to tune chunk size for your GPU memory or model speed
- You need to split files by function boundaries for better AI focus
- You are migrating from older chunking defaults
Assumes this stack
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
What's inside
7 sections, 3 default YAML configs, 3 use-case configs, 3 troubleshooting symptoms, 1 internal algorithm example
Change this for your project
- Replace
make config-updatewith your project's update command - Replace
python scripts/config_update.pywith your migration script path - Replace
bd close --allandrm.ai-code-reviewer/LESSONS.mdwith your context-clearing commands
Where it goes
Keep it in your repository where the agent or team that needs it will read it.
Worth borrowing
- Grouping small functions into one chunk and splitting large functions into sub-chunks
- Providing multiple preset configurations for different hardware or file sizes
Related Documents
基于命题分块以增强RAG
Implements proposition chunking for RAG: decomposes documents into atomic facts, evaluates quality, and compares retrieval against standard chunking.
TileMap Chunk Manager
Divides a large tilemap into fixed-size chunks, loading and rendering only those visible to reduce memory and draw calls by over 99%.
Message Chunking for MCP stdio Transport
Explains macOS 64KB pipe write limit and provides a chunking layer for MCP stdio transport that splits and reassembles large messages transparently.
🤖 n8n AI Agent Mastery Course 2025
Serves as the main README for an n8n course repository, listing 10+ AI agent workflow projects with links to YouTube tutorials and Docker setup instructions.