arXiv:2603.27277cs.SEcs.AI2026-03被引 7

用知识图谱让大模型高效理解代码库,少用tokens,快得多。

Codebase-Memory: Tree-Sitter-Based Knowledge Graphs for LLM Code Exploration via MCP

  • 基于Tree-Sitter构建持久化代码知识图谱,支持66种语言
  • 问答准确率83%,耗时减少90%、工具调用减少57%
  • 适合需要快速定位代码结构与依赖关系的开发者

大型语言模型编码代理通常通过反复读取文件和模糊搜索来探索代码库,每查询消耗数千个词元且缺乏结构理解。我们提出Codebase-Memory,一个开源系统,通过模型上下文协议(MCP)构建基于Tree-Sitter的持久性知识图谱,采用多阶段流水线,包含并行工作池、调用图遍历、影响分析和社区发现,可解析66种编程语言。在31个真实项目中评估显示,其问答准确率达83%,相较于文件探索型代理的92%略有下降,但仅需十分之一的词元消耗和2.1倍更少的工具调用。对于图原生查询如核心节点检测和调用者排序,在31种语言中的19种上表现匹配或超越原代理。

原文摘要 · Abstract (English)

Large Language Model (LLM) coding agents typically explore codebases through repeated file-reading and grep-searching, consuming thousands of tokens per query without structural understanding. We present Codebase-Memory, an open-source system that constructs a persistent, Tree-Sitter-based knowledge graph via the Model Context Protocol (MCP), parsing 66 languages through a multi-phase pipeline with parallel worker pools, call-graph traversal, impact analysis, and community discovery. Evaluated across 31 real-world repositories, Codebase-Memory achieves 83% answer quality versus 92% for a file-exploration agent, at ten times fewer tokens and 2.1 times fewer tool calls. For graph-native queries such as hub detection and caller ranking, it matches or exceeds the explorer on 19 of 31 languages.

代码理解知识图谱LLM应用开发效率

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。