Minimal RAG — question answering over large document collectionsMinimal RAG —— 面向大规模文档库的检索问答

Leave judgmentto the model.Give it capabletools. 判断交给模型,能力交给工具。

One model loop and two tools — no pipeline in between. The model decides what to search, what to read and when to answer.一个模型循环、两个工具,中间没有流水线。搜什么、读什么、何时回答,都由模型决定。

MODEL what to search? turn 1 judgment searchBM25 · passages readdoc · offset · limit capability answer + source IDs
94.1%

BrowseComp-Plus, all 830 queries · #2 of 85BrowseComp-Plus 全量 830 题 · 85 个条目中第 2self-scored with the official script · verification pending官方脚本自评 · 等待维护方复核

12.7

searches per query每题平均搜索次数#1 on the leaderboard: ~209榜首约 209 次

~400

lines of core code行核心代码loop 66 · tools 192 · adapter 153循环 66 · 工具 192 · 适配器 153

01 — The idea理念

A typical RAG pipeline decides in code.典型的 RAG 流水线,用代码做决定。

The query rewrite, the router, the retrievers, the top-k and the prompt are all fixed before the model ever sees the question.查询改写、路由、检索器、top-k、提示词,在模型看到问题之前就全部定死了。

Here, the model makes every decision.在这里,每个决定都交给模型。

What to search, whether to search again, what to read and when to stop — decided by the model, every turn, for every question.搜什么、要不要再搜、读哪里、何时停止——每道题、每一轮,都由模型判断。

The tools do the work.具体的活,交给工具。

Just two. search ranks original passages with BM25; read returns original text at any position. Both hand back document IDs and offsets the model can act on.只有两个:search 用 BM25 给原文段落排序;read 返回任意位置的原文。两者都返回文档 ID 和偏移,模型可以直接接着用。

Everything else is deleted.其余的,全部删掉。

No embeddings, no reranker, no router. What connects the model to its tools is a 66-line loop.没有向量、没有重排序、没有路由。连接模型和工具的,只是一个 66 行的循环。

0104
Model模型judgment
Tools工具capability
deleted已删除
model⟲ run_agent() · 66 linestools
02
02 — Judgment判断

Watch the model decide.看模型如何做判断。

A real run, recorded on 2026-10-13 with gpt-6.1-sol over a five-document demo corpus. Every green note marks a choice the model made on its own — nothing in the code makes it.一次真实运行:2026-10-13 用 gpt-6.1-sol 在 5 篇演示文档上录制。每条绿色标注都是模型自己做出的选择,代码没有替它决定任何一步。

minimal_rag ask --index sol-demo.sqlite --model gpt-6.1-sol --max-turns 4
replay
  • Question问题
  • Decide: the query判断:查询词
  • search()
  • Decide: what to read判断:读哪里
  • read()
  • Decide: enough?判断:够了吗
  • Answer + source答案与来源
  • model calls模型调用 0/3
    input tokens输入 token 0
    chars read读取字符 0
Demo corpus, not a benchmark result. Values checked by hand against the source. Recording ↗演示语料,不是基准成绩;数值已人工对照原文。录制数据 ↗
03
03 — Capability能力

Same model. Better tools. 23 more right.同一个模型,换上更好的工具,多答对 23 题。

Same model, same BM25 index, same 230 queries. Replace our search/read with the benchmark's standard search tool and correct answers fall from 217 to 194. The gain comes from the interface, not only the model.同一模型、同一 BM25 索引、同样 230 道题。把我们的 search/read 换成基准自带的标准搜索工具,答对数从 217 掉到 194。提升来自工具接口,而不只是模型。

search(query, limit)

Ranks original passages with SQLite FTS5 BM25 and returns each with its document ID and character offset — real text, not a summary.用 SQLite FTS5 BM25 给原文段落排序,每条都带文档 ID 和字符偏移——给的是原文,不是摘要。

→ "Remediation SLA options + customer tier mapping…" · dsid_c838… · @0
read(document_id, offset, limit)

Returns original text at any position in any document. Where to look and how much to read is up to the model — like a person scrolling a file.返回任意文档任意位置的原文。读哪里、读多少由模型决定,就像人翻文件一样。

→ read("dsid_c838…", 3900, 6000) · "TTM (same across tiers) — Sev0: 30 minutes…"
search + readours本项目
0
/ 230 correct · 94.3%
standard searchbenchmark default基准默认
0
/ 230 correct · 84.3%
paired difference配对差值
+10.0 pp
95% CI [5.2, 14.8] — excludes zero.95% 置信区间 [5.2, 14.8],不含 0。
0−551015 pp 5.214.8

Better tools, fewer moves.工具越好,动作越少。

Average searches per query · BrowseComp-Plus Agents leaderboard, 2026-10-17每题平均搜索次数 · BrowseComp-Plus Agents 榜,2026-10-17
Minimal RAG94.10% · single agent单智能体 · BM25 · gpt-6.1-sol
12.7
Best BM25-only entry before ours此前最好的纯 BM25 条目90.48% · BM25 + query expansion · GPT-5.5
33.7
Leaderboard #1排行榜第 195.18% · multi-agent · Qwen2-7B + Reason-ModernColBERT · GPT-5
~209
04
04 — Minimal极简

What's left is a loop.剩下的,只是一个循环。

The model replies with text or tool calls; the loop runs the tools and appends the results. That is the entire control flow. Green lines hand control to the model; blue lines run a tool.模型返回文本或工具调用;循环执行工具、把结果追加回去。控制流就这些。绿色行把控制权交给模型,蓝色行执行工具。

src/minimal_rag/loop.pyrun_agent()

    
0lines

core loop核心循环

0lines

search + read toolssearch + read 工具

0lines

model adapter模型适配器

Line counts at tag frozen-20261017, the version behind the submitted results.行数取自产生提交成绩的 frozen-20261017 标签。

Tried. Measured. Dropped.试过,测过,删掉。

Every choice is a paired comparison on the same questions; what lost stays on record.每项都是同题配对对照;输掉的方案同样留档。

Vector retrieval tool独立向量检索工具Qwen3-Embedding-8B alongside BM25; the model picksQwen3-Embedding-8B 与 BM25 并列,由模型选择

Enterprise test400
305 vs 309 BM25 only仅 BM25
✕ dropped不采用

ripgrep Grep toolripgrep 全库 Grep 工具about 3 wins traceable to Grep逐题追溯可归因约 3 题

Enterprise dev100 78 vs 74
BrowseComp dev30 28 vs 28
◐ optional · off可选 · 默认关

verbosity = highfixed evidence, 30 questions固定证据 30 题

22 vs 23 low
✕ default low默认 low

Direct Responses API backend直连 Responses API 后端replacing the Codex transport替代 Codex 传输

Enterprise dev30 24 vs 22
fact completeness事实完整度 93.0% vs 84.7%
✓ kept · portable保留 · 可移植
Stronger model,
stronger system.
模型变强,
系统直接变强。

No decision is hard-coded in the loop, so there is no pipeline to re-tune around a better model — it simply makes better decisions.循环里没有写死任何决定,换上更强的模型不需要重调流水线——它只是做出更好的判断。

05
05 — Proof成绩

94.1% on BrowseComp-Plus.BrowseComp-Plus 94.1%。

Each dot below is one of the 830 queries, in query-ID order, from the submitted run. 781 correct, 49 not. Hover a dot to inspect it; dimmer dots had lower evidence recall.下面每个点是 830 题中的一道,按题号排列,来自提交的那次运行。781 对,49 错。悬停可查看单题;越暗表示证据召回越低。

correct正确incorrect错误dimmer = lower recall越暗 = 召回越低
official scoring script + Qwen3-32B judge, run by us · verification pending官方判分脚本 + Qwen3-32B 裁判,由本项目运行 · 等待复核
#2 / 85

Agents leaderboard; top single-agent and BM25-only entryAgents 榜排名;单智能体与纯 BM25 条目中最高

0%

evidence recall证据召回率

0%

calibration error校准误差

0

reads per query每题读取次数

BrowseComp-Plus830 / 830 queries
94.10%
781 of 830. Counting the eight technically-failed-then-rerun queries as wrong: 93.37%, still #2.830 题答对 781。若把 8 道技术故障后重跑的题算错:93.37%,仍是第 2。official script + Qwen3-32B BF16 judge, run by us官方脚本 + Qwen3-32B BF16 裁判,由本项目运行
pending verification等待复核
EnterpriseRAG-Benchtest400 · dev100
77.25%
309/400 locally; dev100 74/100. All 500 answers submitted in the official format. Official board: OpenAI File Search 69.8%, BM25 + GPT-5.4 single pass 68.8%.本地 309/400;dev100 为 74/100。500 题已按官方格式提交。官方榜:OpenAI File Search 69.8%,BM25 + GPT-5.4 单轮 68.8%。local gpt-6.1-sol judge, stricter than official (86.5% vs 92.0% on public answers)本地 gpt-6.1-sol 裁判,比官方更严(公开答案:86.5% vs 92.0%)
official grading pending等待官方判分
FinanceBench100 questions
83/100
Retrieval over a shared corpus of all 371 filings.在全部 371 份财报的共享语料上检索。local judge · earlier search description本地裁判 · 较早版本 search 说明
local judge本地裁判
HotpotQA distractor100 questions
87.25F1
EM 77.0 · F1 87.25official answer metric on public dev data; supporting facts not evaluated公开 dev 数据上的官方答案指标;未评估支持事实
official metric官方指标
06
06 — Fine print口径

The fine print, in large print.限制条款,用大字写。

01

Not yet official.还不是官方成绩。

Both submissions are with the maintainers. BrowseComp was scored by us with the official script; Enterprise official grading is pending.两份提交都在等维护方处理。BrowseComp 由本项目用官方脚本判分;Enterprise 等待官方判分。

02

Development sets, not held-out sets.回归集,不是留出集。

Both benchmarks were used during development; Enterprise dev/test is our own split. One generation per question except technical reruns; failures stay in the denominator.两个基准都在开发中用过;Enterprise 的 dev/test 是本项目自己的划分。除技术错误重跑外每题生成一次,失败计入分母。

03

Eight reruns, disclosed.8 道重跑,全部公开。

Timeouts, usage limits and SDK interrupts hit eight BrowseComp queries; each was rerun once with the same configuration. Counted as wrong: 93.37%.8 道 BrowseComp 题遇到超时、额度和 SDK 中断,各用相同配置重跑一次。全算错则为 93.37%。

04

Full runs used the Codex SDK.全量成绩来自 Codex SDK。

Codex injects extra tool definitions and multi-agent text; traces show no built-in tool calls. The direct API backend was only migration-tested on Enterprise dev30.Codex 会注入额外工具定义和多智能体说明,轨迹中没有内置工具调用。直连 API 后端只在 Enterprise dev30 上做过迁移验证。

05

One change to the judge script.判分脚本只改一处。

BrowseComp judging ran on one A800 with max_model_len=8192 added. The longest judge prompt is 1,216 tokens, so nothing is truncated.BrowseComp 判分在单张 A800 上运行,仅加入 max_model_len=8192;最长判分提示 1,216 token,不会截断。

06

A student project.个人学生项目。

Budget-limited. Every question keeps an inspectable trace, configuration and evaluation record.受预算限制。每道题都保留可检查的轨迹、配置和评测记录。

07 — Run it运行

Three commands. No account.三条命令,无需账号。

The demo builds a real SQLite index from bundled samples and replays search → read → cited answer. It calls no model. Start in an empty directory with Python 3.12+ on macOS or Linux.演示用内置样例建立真实 SQLite 索引,回放“检索 → 读取 → 带来源回答”,不调用模型。在空目录运行以下命令;需要 Python 3.12+,适用于 macOS 或 Linux。

python3.12 -m venv .venv
.venv/bin/python -m pip install https://github.com/hxli2005/minimal-rag/archive/refs/heads/main.zip
.venv/bin/python -m minimal_rag demo