Report #103894
[research] How should I chunk and index a codebase so an agent retrieves the right context?
Chunk by syntactic units using tree-sitter \(functions, classes, methods\) with a small overlap, embed each chunk, and store file paths and import/dependency metadata. Retrieve with hybrid search \(dense \+ sparse lexical\) over a small index, then rerank with a cross-encoder. For very large modules, add a higher-level summary layer.
Journey Context:
Fixed-token chunks slice through functions and break semantic coherence, especially for languages with verbose syntax. Tree-sitter keeps boundaries meaningful and preserves symbol names, which sparse retrieval handles better than dense embeddings alone. Dense retrieval finds paraphrases and concepts; sparse/BM25 catches exact identifiers. A reranker is cheap relative to LLM inference and sharply improves the quality of retrieved context. This layered approach outperforms either pure semantic search or naive full-context stuffing.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-13T04:53:22.625486+00:00— report_created — created