Skip to content

Plan: retriever rewrite in three stages - #181

Merged
adamjohnwright merged 1 commit into
mainfrom
plan/retriever-rewrite
Sep 8, 2026
Merged

adamjohnwright merged 1 commit into
mainfrom
plan/retriever-rewrite

Conversation

@adamjohnwright

Copy link
Copy Markdown
Contributor

Implementation plan for spec 001. No code yet.

The staging, and why

A structural change and a behaviour change are never in the same commit:

stage what exit criterion
1 BaseRetriever with vendored RRF; expansion and SelfQuery both stay retrieval_baseline compare shows zero difference
2 D1 — plain semantic search replaces SelfQuery; retrieval drops 21 → 1 LLM calls differences confined to the vector side
3 D2/D3 — budget and bundle become arguments two callers get different budgets; four mypy baseline entries deleted

Stage 1 producing identical output is the point. If it does not, the refactor changed something it should not have, and that is far easier to find before Stage 2 moves the results deliberately.

Each stage ends by answering a real question through the full chain, via both invoke and ainvoke — not by testing the retriever in isolation. That is the failure mode that recurred most this week and is Article I of the constitution.

What is deliberately not generated

No research.md, data-model.md or contracts/.

D1–D4 are settled with measured evidence in the spec, so there is nothing to research. The feature introduces no data model and no external contract. Generating that scaffolding would be exactly the ceremony the constitution says to avoid — Spec Kit is for decisions, not paperwork.

Complexity tracking

Four simplifications considered and rejected, with reasons — notably keeping metadata_info.py. It looks like 339 dead lines after D1, but evaluator.py and bin/retrieval_baseline still construct SelfQuery, so deleting it would break the tool that measures Stage 2.

Verification

Every factual claim was checked against the code rather than written from memory:

userguide is already a plain BaseRetriever          ✓
four collections hold 121,291 documents             ✓ (had written "~121k")
RRF = weight/(rank+60), rank from 1, page_content   ✓ (read from the pinned source)
four mypy baseline entries, not three               ✓
metadata_info still used by 2 files                 ✓

🤖 Generated with Claude Code

Stages the work so a structural change and a behaviour change are never in the
same commit:

  1  BaseRetriever with vendored RRF. Query expansion and SelfQuery both stay.
     This changes how the code is arranged, not what it returns, so the exit
     criterion is that retrieval_baseline shows ZERO difference.
  2  D1: plain semantic search replaces SelfQuery. Retrieval drops to one LLM
     call per message. Differences must be confined to the vector side.
  3  D2/D3: the budget and the bundle become arguments, which removes the B008
     suppression and the four retrievers.*.rag mypy baseline entries.

Each stage ends by answering a real question through the full chain via both
invoke and ainvoke -- not by testing the retriever in isolation, which is the
failure mode that recurred most this week and is Article I of the constitution.

Deliberately not generated: research.md, data-model.md, contracts/. There are no
unresolved unknowns (D1-D4 are settled with evidence in the spec) and the feature
introduces no data model or external contract, so the scaffolding would be
ceremony. The constitution says Spec Kit is for decisions, not paperwork.

Complexity tracking records four rejected simplifications and why, including
keeping metadata_info.py: it is not dead, because the evaluator and the baseline
harness still construct SelfQuery, and deleting it would break the tool that
measures stage 2.

Every factual claim was checked against the code: userguide is already a plain
BaseRetriever, the four collections hold 121,291 documents, RRF is
weight/(rank+60) counting from 1 and de-duplicating on page_content, and there
are four mypy baseline entries rather than three.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@adamjohnwright
adamjohnwright merged commit c6fd825 into main Sep 8, 2026
10 checks passed
@adamjohnwright
adamjohnwright deleted the plan/retriever-rewrite branch September 9, 2026 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant