Chonks:基于AST与混合检索的多语言代码RAG工具
A year of reading AST-aware code RAG papers, and the thing I built
提供了一套经过文献验证的代码RAG工程实践方案,包含具体的分块策略、混合检索架构及避坑指南,对做Agent开发的同学极具参考价值。
Chonks indexes a large codebase into one SQLite file and serves it to a coding agent over MCP. Tree-sitter AST chunks, hybrid semantic plus BM25, a typed cross-reference graph. No LLM in the retrieval path. Apache-2.0, free, no telemetry. Built for multi-million line codebases.
Chonks 将大型代码库索引为一个 SQLite 文件,并通过 MCP 向编码代理提供服务。它使用 Tree-sitter AST 块、混合语义加 BM25 以及类型化的交叉引用图。检索路径中不包含 LLM。采用 Apache-2.0 协议,免费,无遥测数据收集。专为数百万行规模的代码库构建。
Ten languages get full symbol and graph support, including C++, C#, HLSL and Python, so it works where a call path crosses languages.
十种语言获得完整的符号和图支持,包括 C++、C#、HLSL 和 Python,因此它在调用路径跨语言的场景中也能正常工作。
Acc@5 64/100 on held-out Loc-Bench, in one call. The ids were picked before tuning and are published in the repo.
在预留的 Loc-Bench 测试集上,Acc@5 达到 64/100,仅需一次调用。这些 ID 是在调优前选定的,并已发布在仓库中。
The reading list, and what I got from every single one:
阅读清单,以及我从每一篇中获得的收获:
- [cAST](https://aclanthology.org/2025.findings-emnlp.430/), Findings of EMNLP 2025. Recursive AST-node splitting with sibling merging. The core chunking algorithm.
- [LARGER](https://arxiv.org/abs/2605.16352), 2026. Lexical anchors, then confidence-filtered expansion. Became my graph seed gate.
- [Reformulate, Retrieve, Localize](https://arxiv.org/abs/2512.07022), 2026. Pull identifiers and stack-trace terms out of bug report text before retrieval. I do it rule-based, with no LLM call.
- [From Fragments to Paths](https://arxiv.org/abs/2606.22906), 2026. Budget-constrained traversal over multi-relational repository structure. The same shape as my graph expansion.
- [AST-derived vs LLM-extracted graphs](https://arxiv.org/abs/2601.08773), 2026. The head-to-head behind my choice to keep the LLM out of index time.
- [Practical Code RAG at Scale](https://arxiv.org/abs/2510.20609), 2025. The counterpoint. Line chunking matches syntax-aware splitting on completion benchmarks, and BM25 beats dense embeddings for code-to-code queries.
- [LocAgent](https://arxiv.org/abs/2503.09089), 2025. Released Loc-Bench, which I use as the held-out set.
- [GraphRAG](https://arxiv.org/abs/2404.16130), 2024.
- [cAST](https://aclanthology.org/2025.findings-emnlp.430/),EMNLP 2025 Findings。递归 AST 节点拆分结合兄弟节点合并。这是核心的分块算法。
- [LARGER](https://arxiv.org/abs/2605.16352),2026 年。词法锚点,随后进行置信度过滤的扩展。这成为了我的图种子门控机制。
- [Reformulate, Retrieve, Localize](https://arxiv.org/abs/2512.07022),2026 年。在检索之前,从错误报告文本中提取标识符和堆栈跟踪术语。我采用基于规则的方法,无需调用 LLM。
- [From Fragments to Paths](https://arxiv.org/abs/2606.22906),2026 年。在多关系仓库结构上进行预算受限的遍历。其形态与我的图扩展过程相同。
- [AST-derived vs LLM-extracted graphs](https://arxiv.org/abs/2601.08773),2026 年。这是我决定在索引阶段排除 LLM 的直接对比依据。
- [Practical Code RAG at Scale](https://arxiv.org/abs/2510.20609),2025 年。作为反面观点。在完成基准测试中,行级分块与语法感知拆分的效果相当,而在代码到代码的查询中,BM25 优于密集向量嵌入。
- [LocAgent](https://arxiv.org/abs/2503.09089),2025 年。发布了 Loc-Bench,我将其用作预留测试集。
- [GraphRAG](https://arxiv.org/abs/2404.16130),2024 年。
Most of these I found while building. A lot of the time it turns out, what I was building was converging to the lit.
其中大部分是我在构建过程中发现的。很多时候事实证明,我正在构建的东西正逐渐趋同于这些文献中的方法。
https://github.com/mgonzalez01/Chonks
更进一步:量化金融体系
看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力