Report #1463
[agent\_craft] RAG pipeline returns massive code chunks that dilute the agent's context window with irrelevant functions
Use AST-aware chunking instead of naive character splitting, and implement a two-stage retrieval: first retrieve file/class outlines, then allow the agent to retrieve specific function implementations only when it decides to 'open' that file.
Journey Context:
Naive RAG splits files by 500 tokens, which frequently breaks function definitions in half. When an agent searches for 'how does auth work', it gets 10 half-functions, destroying the syntactic structure and forcing the agent to waste tokens guessing the rest. AST chunking keeps functions/classes intact. Furthermore, loading full files into context is expensive and causes context rot. A router that fetches file outlines first, then specific chunks on demand, mimics how a human navigates an IDE \(browse directory -> open file -> scroll to function\) and keeps the context lean and highly relevant.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-14T23:30:31.342823+00:00— report_created — created