抹布长凳
代码RAG MCP服务器基准测试 --衡量RAG如何帮助AI找到正确的代码。
没有现有基准涵盖以下交叉点 代码搜索+MCP协议+A/B比较抹布长凳填补了这个空白。
它衡量什么
ragbench索引真实的开源存储库(Flask、FastAPI、Express),并运行105个已知正确答案的代码搜索查询。它衡量:
| 度量 | 它告诉你什么 |
|---|---|
| Hit@1 / Hit@5 | RAG在顶部结果中找到了正确的文件吗? |
| 符号Hit@5 | 它是否找到了正确的函数/类? |
| 平均倒数排名 | 第一个正确结果的排名有多高? |
| 潜伏期p50/p95 | 查询速度有多快? |
| 摄入速度 | 索引代码库的速度有多快? |
| RAM/索引大小 | 资源消耗 |
| 综合得分 | 所有指标的加权组合 |
查询类型
locate--“X在哪里定义?”(最常见的开发人员问题)callers--“什么叫X?”explain--“X是如何工作的?”(需要多个相关文件)impact--“如果我改变X,会发生什么?”multi_hop--“通过多个文件跟踪X到Y”(传递性推理)cross_package--“模块A如何与模块B交互?”architecture--“项目的结构和层次是怎样的?”dead_code--“函数X真的在任何地方被调用吗?”conditional_path--“当条件C为真时,存在哪些代码路径?”test_traceability--“哪些测试涵盖了函数X?”
A/B模式
比较RAG与grep/glob基线,以衡量RAG提供的实际改善:
- 工具调用减少了多少?
- 找到正确的代码要快多少?
- RAG真的有帮助吗?或者grep足够吗?
快速开始
# Clone
git clone https://github.com/Miro96/nova-rag-benchmark.git
cd nova-rag-benchmark
# Install
python3 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
# Run benchmark on your RAG MCP server
rag-bench run --command "python -m your_server" --transport stdio
# Or use a preset
rag-bench run --preset mcp-local-rag
# Run tests (325 tests)
pytest tests/ -v用法
对单个服务器进行基准测试
# With a preset
rag-bench run --preset nova-rag
# With a custom command
rag-bench run --command "npx -y mcp-local-rag" --transport stdio
# With a config file
rag-bench run --config my-server.json
# Only test on one repo
rag-bench run --preset nova-rag --repo flask
# A/B comparison vs grep baseline
rag-bench run --preset nova-rag --ab-baseline比较多台服务器
rag-bench compare --presets nova-rag,mcp-local-rag,chroma-mcp运输方式
rag bench支持三种客户端传输模式 BaseClient 接口:
| 模式 | 标志 | 描述 |
|---|---|---|
| MCP 标准 | --transport stdio | JSON-RPC通过子进程stdin/stdout(默认) |
| CLI子流程 | --transport cli | 带有CLI参数的子进程,stdout捕获 |
| 过程中的 | --transport inprocess | 直接导入Python(仅预设) |
# MCP stdio (default)
rag-bench run --command "python -m my_server" --transport stdio
# CLI subprocess
rag-bench run --command "my-rag search" --transport cli
# In-process (requires Python module)
rag-bench run --preset naive-rag --transport inprocess排行榜
# Start the web leaderboard
rag-bench serve --port 8080
# Submit results
rag-bench submit results/run_*.json \
--git-url https://github.com/you/your-rag \
--git-user yourusername \
--server-url http://localhost:8080打开 http://localhost:8080 查看带有排序、过滤和雷达图比较的排行榜。
服务器配置格式
为RAG MCP服务器创建JSON配置:
{
"name": "my-rag-server",
"git_url": "https://github.com/you/my-rag",
"command": "python -m my_rag.server",
"transport": "stdio",
"tool_mapping": {
"ingest": {
"tool": "index_directory",
"params": { "path": "{path}" }
},
"query": {
"tool": "search",
"params": { "query": "{query}", "limit": "{top_k}" }
}
}
}如果 tool_mapping 如果省略,rag bench将通过分析来自的工具名称和模式来自动检测工具 tools/list.
预摄取命令
您可以通过以下方式声明在索引之前运行shell命令 pre_ingest 现场。使用 {repo_path} 作为存储库目录的模板变量,以及 {cwd} 对于基准时间的工作目录:
{
"name": "my-rag-server",
"pre_ingest": [
"pip install -r {repo_path}/requirements.txt",
"cd {repo_path} && npm install"
]
}索引目录
预设配置可以声明要索引的目录(默认为repo根目录):
{
"name": "my-rag-server",
"index_directories": ["src/", "lib/"]
}默认情况下,所有未被忽略的文件都会被索引; index_directories 限制对特定子目录的索引。
内置预设
| 预设 | 服务器 | 描述 |
|---|---|---|
nova-rag | 诺瓦拉格 | 混合语义+图形+关键字RAG |
naive-rag | 仅嵌入基线 | 原始嵌入相似性(无代码图) |
cocoindex-code | CocoIndex v0.2.33 | CocoIndex代码检索预设 |
grep-glob | 关键字基线 | 纯grep/glob关键字搜索(无嵌入) |
mcp-local-rag | mcp本地抹布 | MCP本地RAG服务器 |
chroma-mcp | 色度mcp | Chroma矢量数据库MCP服务器 |
比较结果(105个查询,3个重复)
Flask+FastAPI+Express上所有内置预设的四向比较:
rag-bench compare --presets nova-rag,naive-rag,cocoindex-code,grep-glob --replicates 3| 度量 | nova-rag | naive rag | cocoindex代码 | grep-glob |
|---|---|---|---|---|
| Hit@1 | 20.0% | 1.9% | 4.8% | 20.0% |
| Hit@5 | 45.7% | 6.7% | 16.2% | 55.2% |
| Hit@10 | 53.3% | 7.6% | 23.8% | 74.3% |
| 符号Hit@5 | 33.3% | 13.3% | 0.0% | 0.0% |
| 平均倒数排名 | 0.315 | 0.037 | 0.099 | 0.340 |
| 延迟p50 | 14.6毫秒 | 3.5毫秒 | 447.1毫秒 | 22.3毫秒 |
| 延迟p95 | 24.4毫秒 | 4.0毫秒 | 573.5毫秒 | 90.6毫秒 |
| 摄入速度 | 2675 f/s | 206 f/s | -- | -- |
| 综合得分 | 0.550 | 0.364 | 0.327 | 0.523 |
关键要点:
- 诺瓦拉格 是解析符号的唯一预设(33.3%符号Hit@5)--grep/glob和仅嵌入的方法无法识别函数/类名。
- grep glob 在原始文件召回中获胜(55.2%Hit@5)但不返回符号级结果。
- 天真的破布 (仅嵌入)在文件召回方面表现最差(6.7%)Hit@5),表明仅凭语义相似性不足以进行代码搜索。
- cocoindex代码 具有高延迟(~450ms p50),而其他方法的延迟低于25ms。
- 诺瓦拉格 索引速度比原始rag快13倍(2675比206文件/秒)。
再现性:所有预设在3个重复的复合评分中的CV均小于0.05。
数据集
3个真正的开源存储库,105个查询包含基本事实:
每个查询都有:
- 预期文件(地面实况)
- 预期符号(函数/类名)
- 难度级别(易/中/难)
- 查询类型(定位/调用者/解释/影响/多操作/交叉包/架构/死代码/条件路径/测试跟踪性)
指标
综合得分公式
Score = 0.30 * Hit@5
+ 0.15 * SymbolHit@5
+ 0.15 * MRR
+ 0.15 * ToolCallEfficiency
+ 0.15 * LatencyScore
+ 0.10 * ResourceScore建筑
rag_bench/
├── cli.py # CLI entry point (click)
├── transport/ # Client transport layer
│ ├── base.py # BaseClient interface
│ ├── mcp_client.py # MCP JSON-RPC client (stdio)
│ ├── cli_client.py # Subprocess CLI client
│ └── in_process.py # In-process (Python import) client
├── adapter.py # Normalizes different RAG server interfaces
├── runner.py # Orchestrates: ingest → warmup → benchmark → metrics
├── metrics.py # Hit@K, MRR, latency percentiles, composite score
├── baseline.py # Grep/Glob baseline for A/B comparison
├── report.py # Rich terminal tables
├── submit.py # HTTP submit to leaderboard
├── presets/ # JSON configs for known servers
└── datasets/ # Repos + 105 queries with ground truth
server/
├── app.py # FastAPI leaderboard server
├── db.py # SQLite storage
├── models.py # Pydantic models
└── static/ # Leaderboard web UI贡献
- 添加查询 --更多的查询提高了基准测试的可靠性。添加
rag_bench/datasets/queries/ - 添加预设 --中新RAG MCP服务器的配置文件
rag_bench/presets/ - 添加仓库 --中的新测试存储库
rag_bench/datasets/repos.json - 提交结果 --运行基准测试并提交到公共排行榜
为什么存在
现有的基准测试不包括RAG+MCP+代码搜索交集:
| CodeRAG工作台 | GrepRAG | MCP工作台 | 抹布长凳 | |
|---|---|---|---|---|
| 代码RAG | 是 | 是 | 否 | 是 |
| MCP协议 | 否 | 否 | 是 | 是 |
| A/B:RAG与无RAG | 部分 | 是 | 否 | 是 |
| 自定义仓库 | 否 | 否 | 不 | 是 |
| 排行榜 | 否 | 否 | 拥抱脸 | 自托管 |
许可证
麻省理工学院
