Report #8025
[agent\_craft] Agent retrieves irrelevant code context from vector DB, wasting tokens on noise
Use syntax-aware chunking \(AST-based for code\) with parent metadata, rather than fixed-size character chunking, and include file path/type in retrieval embeddings.
Journey Context:
Standard RAG \(Retrieval-Augmented Generation\) for coding agents often uses naive fixed-size character chunking \(e.g., 512 tokens\). This breaks code semantics \(splitting functions, cutting class definitions\) and leads to retrieving partial, useless snippets. The hard-won insight is that code requires syntax-aware chunking \(respecting function boundaries, class definitions\) and that metadata \(file path, imports\) is crucial for relevance. Tree-sitter based chunking is the industry standard for this. The tradeoff is preprocessing complexity \(need to parse the codebase\), but the token efficiency \(retrieving one complete function vs three partial chunks\) and accuracy gains are massive. Vector DBs with naive chunking waste 30-50% of context window on noise.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T04:20:33.677961+00:00— report_created — created