Official code, benchmark, and evaluation harness for
Beyond Top-K: Replacing Black-Box Retrieval with Interpretable Agentic Operations Sagar Tamang, Ayush Vyas, Tabarakul Hazarika · TwoSpoon · 2026
- 📄 Paper (arXiv): https://arxiv.org/abs/2608.06305
- 🌐 Project page: https://twospoon.github.io/READ/
Retrieval-augmented generation over long documents is dominated by one design: chunk the text, embed the chunks, surface the top-k nearest neighbours. On a 780-page government financial report — 86.8% table rows, thousands of near-identical figures, units that change every few statements — that design loses to an agent that just reads the file.
READ replaces the vector index with three deterministic operations over the raw Markdown, exposed as an MCP server:
| Tool | What it does |
|---|---|
memory_grep |
Normalization-aware line search. Returns line numbers. |
memory_outline |
The heading structure, with line numbers. The map. |
memory_read |
Lines a–b of one file, bounded at 400 per call. |
memory_list |
What files exist, with sizes and line counts. |
Because every operation is a pure function of the document, a trajectory is a replayable audit trail rather than an opaque similarity score. There is no index to build, no embedding model to download, and nothing to re-index when the document changes.
51 hand-verified questions, gemini-2.5-pro throughout, matched k=8 for every
retrieval baseline. Paired inference: exact McNemar on discordant pairs,
Holm-corrected across the family.
| System | Accuracy | Δ vs READ | pHolm | $/question |
|---|---|---|---|---|
read_no_outline |
66.7% | −7.8 | 1.00 | 0.040 |
read_naive_grep |
66.7% | −7.8 | 1.00 | 0.043 |
read |
58.8% | — | — | 0.058 |
bm25 |
51.0% | +7.8 | 1.00 | 0.020 |
hybrid |
29.4% | +29.4 | 0.016 | 0.022 |
agentic_rag |
27.5% | +31.4 | 0.012 | 0.051 |
dense |
15.7% | +43.1 | 2 × 10⁻⁵ | 0.023 |
Three things this table is saying, including the ones that cut against us:
- The gap is the interface, not iteration.
agentic_ragis the same agent, the same loop, the same budget — but its tool is vector search. It reaches 27.5%. Iteration alone does not close the gap. - 15.7% is not dense's ceiling, and we say so. Sweeping chunk size and depth
(
results/results_sweep.jsonl) lifts dense to 35.3% at 2,000 characters and k=16. READ still beats that by 23.5 points (pHolm = 0.017), and beats all six swept configurations. - BM25 is statistically indistinguishable from READ. Of 22 discordant questions, 13 favour READ and 9 favour BM25 — close to a coin toss. Our result separates embedding-based from embedding-free retrieval. It does not establish that agentic search beats lexical search.
The two READ ablations scoring above READ is a real and reported null: with n = 51 neither difference is significant, and the naive-grep ablation is discussed at length in the paper rather than buried.
If you only want the MCP server, you need neither an API key nor a GPU:
git clone https://github.com/twospoon/READ.git
cd READ
pip install -e . # one dependency: mcp
# point it at any directory of Markdown
MEMORY_DIR=./memory memory-mcp --transport stdioWire it into an MCP client — for Claude Desktop, claude_desktop_config.json:
{
"mcpServers": {
"memory": {
"command": "memory-mcp",
"args": ["--transport", "stdio", "--root", "/abs/path/to/your/markdown"]
}
}
}Or drive the store directly, with no MCP layer at all:
from pathlib import Path
from memory_mcp import store
root = Path("memory")
print(store.outline(root)) # the map
print(store.grep(root, "48964.89")) # finds the printed "48,964.89"
print(store.read_lines(root, "FA_2024_25_GUJARAT/pymupdf4llm.md", 380, 435))That grep call is the paper's normalization result in one line: the document
prints 48,964.89, the agent searches for 48964.89, and a literal grep finds
nothing. Matching runs against two normalized shadows of each line
(spaced_form, squashed_form) while reporting the original line and line
number, so results stay valid inputs to read_lines.
The document is not in this repository. The benchmark distributes questions, gold answers, and line references — not the document text. Reproduce the corpus in two steps:
# 1. download the source PDF (public record, ~4 MB, 780 pages)
curl -o FA_2024_25.pdf \
"https://cag.gov.in/uploads/state_accounts_report/account-report-FA-VOL-I-2024-25-069c52aa2b34bf9-63690940.pdf"
# 2. convert it with the backend the paper used
pip install -e ".[convert]"
converter -i FA_2024_25.pdf --type pymupdf4llm
mkdir -p memory/FA_2024_25_GUJARAT
cp output/FA_2024_25/pymupdf4llm.md memory/FA_2024_25_GUJARAT/You should get 1,683,730 bytes · 24,099 lines · 745 page markers. Verify
before trusting any number, because a different pymupdf4llm version can shift
line numbers and silently invalidate every gold reference:
python scripts/02_annotate_benchmark.py --verifyThe four-way converter comparison in Appendix C (Table 11) needs
pip install -e ".[convert-all]"; docling and marker-pdf each download
multi-GB models on first run.
pip install -e ".[eval,dev]"
export GEMINI_API_KEY=... # bash
$env:GEMINI_API_KEY = "..." # PowerShellA .env file in the repo root with GEMINI_API_KEY=... works too; it is
gitignored and loaded automatically. No key is needed to run the MCP server or
to regenerate every table and figure from the shipped results — only to
generate new result rows.
Model calls go to Google Gemini (google-genai); get a key at
https://aistudio.google.com/apikey. The provider is isolated in
read_eval/llm.py, so switching it means editing one file.
Embeddings run locally, so the dense baseline does not drift when a hosted
embedding endpoint updates its model.
# 1. profile the corpus — instant, no API calls, no key needed.
# This step alone reproduces Table 1, Figure 2, Figure 3.
python scripts/01_profile_corpus.py
python scripts/05_corpus_figures.py
# 2. check the benchmark against your conversion — no API calls
python scripts/02_annotate_benchmark.py --status
python scripts/02_annotate_benchmark.py --verify
# 3. build the embedding index — the only compute-heavy step
python scripts/02b_build_index.py --plan # projection table, costs nothing
python scripts/02b_build_index.py # BAAI/bge-base-en-v1.5, ~438 MB, ~20 min CPU
# 4. run the grid — the step that costs money
python scripts/03_run_experiment.py --dry-run # cell count first
python scripts/03_run_experiment.py --limit 3 --systems read dense
python scripts/03_run_experiment.py # full: ~$13
python scripts/03_run_experiment.py --sweep # Appendix D: ~$8
# 5. figures and tables — no API calls
python scripts/04_make_figures.pyStep 4 is resumable: rows append to results/results.jsonl and a re-run
skips what is already there. Killing it mid-run and restarting is supported.
Watch progress with wc -l results/results.jsonl — do not pipe a long run
through tail, which buffers until the pipe closes and makes a healthy job look
frozen.
The whole paper cost $21.16 across 663 cells. --dry-run prints the cell
count before you spend anything.
Reproduction caveat. The generator is not deterministic even at fixed settings, so your accuracies will move by a point or two. The paper's
seedsconfig exists so that variance can be reported rather than assumed away. If you want to check our arithmetic rather than re-run the models, everything below is derived from the shippedresults/*.jsonlwith no API calls:python scripts/04_make_figures.pyandnotebooks/analysis.ipynb.
READ/
src/memory_mcp/ THE ARTIFACT — the retrieval interface
store.py normalized grep, outline, bounded reads (pure, testable)
server.py FastMCP wrapper exposing the four tools
src/converter/ PDF -> Markdown, 4 backends (Appendix C)
read_eval/ the paper's harness
corpus.py line/page geometry, structure, artifact profiling
read_tools.py tool schemas over the released memory_mcp.store
retrievers.py chunking + dense / BM25 / hybrid / oracle
agent.py the tool loop and every baseline's call pattern
judge.py numeric matching, LLM judge, groundedness
metrics.py results.jsonl -> tidy frames and LaTeX tables
stats.py Wilson / bootstrap intervals, exact McNemar, Holm
plotting.py the paper's figures
runner.py resumable orchestration
llm.py Gemini client, pricing, tool-schema conversion
provenance.py automatic run/timing capture
benchmark/
questions.jsonl 64 questions, 51 verified. Gold answers + line refs.
SCHEMA.md field-by-field definition
annotation/ the four hand-annotation scripts, with the reading
notes that justify every gold figure
config/experiments.yaml the grid
scripts/ 01 profile · 02 annotate · 02b index · 03 run · 04 figures
· 05 corpus figures · 06 audit
results/ 663 result rows with full trajectories, tables, provenance
figures/ PDF + PNG + CSV per figure
notebooks/analysis.ipynb reproduces every table and figure from results/
memory/ where the corpus goes (ships empty — see above)
LAB_NOTEBOOK.md findings, decisions, all 25 bugs, and the claims that
turned out to be wrong
| Paper | Reproduced from | API key? |
|---|---|---|
| Table 1 (corpus profile), Fig. 2 (unit distance) | scripts/01_profile_corpus.py, 05_corpus_figures.py |
no |
| Table 2, Fig. 3 (chunking damage) | read_eval/retrievers.py::chunk_boundary_damage |
no |
| Table 3 (normalization probes) | tests/test_harness.py |
no |
| Table 4 (conversion damage) | read_eval/conversion.py |
no |
| Table 5 (systems) | config/experiments.yaml |
no |
| Table 6 (pilot) | LAB_NOTEBOOK.md §2 |
— |
| Table 7 (main), Table 8 (paired), Fig. 4 | results/results.jsonl → scripts/04_make_figures.py |
no |
| Table 9 (by category), Table 10 (failures) | results/tables/ |
no |
| Table 11 (converters) | src/converter/ + read_eval/conversion.py |
no |
| Table 12 (benchmark composition) | benchmark/questions.jsonl |
no |
| Table 13, 14, Fig. 5 (dense sweep) | results/results_sweep.jsonl |
no |
Every number in the paper can be re-derived from the shipped results without spending a rupee. An API key is only needed to generate new rows.
results.jsonl (357 rows) and results_sweep.jsonl (306 rows) carry one JSON
object per (system × question) cell:
| Field | |
|---|---|
trajectory |
every tool call: name, arguments, result size, latency, whether it returned nothing |
exposed_lines, exposed_pages |
exactly which lines of the document the system saw |
retrieved_chunks |
for RAG systems: chunk id, line span, page span, similarity, rank |
scores |
exact_figure, judge (with its reasoning), grounded, hallucinated |
input_tokens, output_tokens, thinking_tokens, cost_usd, latency_s |
These records contain no document text — only line numbers, spans, and
counts. That is a deliberate property, and it is also what makes the
auditability claim checkable: exposed_lines plus your own conversion is enough
to replay any trajectory by hand.
results/provenance/ records host, CPU, library versions, git commit and
dirty flag, parameters and per-step timings for every run that produced these
files.
pip install -e ".[eval,dev]"
pytest -q45 tests, of which 31 need the corpus and skip cleanly without it — so a fresh
clone gives you 14 passed, 31 skipped, not a wall of errors.
tests/test_store.py covers the retrieval primitives — including
path-traversal refusal and the normalization shadows. tests/test_harness.py
covers the evaluation machinery, and includes
test_normalization_ablation_actually_differs, which is the test that turned
"normalization obviously matters" into a measured claim. It also found that an
earlier draft's claim about statement-number punctuation was false; that
correction is in LAB_NOTEBOOK.md.
- Code (
src/,read_eval/,scripts/,tests/): MIT, see LICENSE. - Benchmark (
benchmark/questions.jsonl) and results (results/): MIT. Gold answers were read off the document by hand; no answer in this benchmark was invented by a model.benchmark/annotation/preserves the reading notes. - The source document is a public record of the Comptroller and Auditor General of India and is not redistributed here. Its terms are the CAG's.
This research was sponsored by Two Spoon Technologies Private Limited (TwoSpoon), which funded the model calls the experiments required. All three authors are affiliated with TwoSpoon, and the work was carried out with no external funding.
Sagar Tamang led the research: the question, the corpus analysis, the READ interface and its evaluation harness, the benchmark, and the experiments. Tabarakul Hazarika contributed to the experimental work. Ayush Vyas conducted the code review and the evaluation audit, and prepared the final manuscript.
See CITATION.cff, or:
@misc{tamang2026topkreplacingblackboxretrieval,
title = {Beyond Top-K: Replacing Black-Box Retrieval with Interpretable Agentic Operations},
author = {Sagar Tamang and Ayush Vyas and Tabarakul Hazarika},
year = {2026},
eprint = {2608.06305},
archivePrefix = {arXiv},
primaryClass = {cs.AI},
url = {https://arxiv.org/abs/2608.06305}
}Stated plainly, and at more length in §8 of the paper:
- One document, one backbone. Every number here is
gemini-2.5-proon one 780-page report. The artifact counts are specific topymupdf4llm. - n = 51. Underpowered for small effects. Differences under roughly 28 points will not reach significance on an unpaired reading of this benchmark — which is why the paired test is used and why the BM25 null is reported as a null.
- The 800-character sweep arm was not run. Appendix D says so and explains why the omission does not change the conclusion.
long_contextandoracleare implemented but disabled inconfig/experiments.yaml. Enable them when you want those specific claims;long_contextwrites ~500k tokens of cache on the first question.
