0004. Lexical retrieval: diagnosis, a lexical question set and the default search

Context

ADR 0003 made vector-only the default and left two points open: why the full-text ranking hurts was never analyzed, and the paraphrase-style questions favor embeddings, so the value of lexical matching (exact terms, numbers, citations such as "§ 14 Abs. 1 UStG") was never measured. This ADR records the analysis, a second question set, three candidate improvements and the decision.

Diagnosis

pnpm eval:diagnose ranks every answerable question with vector and with Postgres full-text search (top 50) and counts who finds the expected unit in the top 5.

Question set both vector only full-text only neither
paraphrase, 75 questions 46 26 1 2
lexical, 28 questions (added by this change) 14 5 1 8

On the paraphrase set full-text finds one question that vector misses (q057), so any hybrid had almost no room to help there; vector missed only 3 of 75.

Why does full-text rank the wrong unit first? Postgres ts_rank_cd has no term-rarity weighting. The analysis checks this directly, with crude stems (the first six letters of each word): in the 28 paraphrase questions where full-text had no hit in the top 5 and put a wrong unit first, a rarity-weighted word overlap prefers the expected unit over that wrong unit in 24 cases (ties 2, prefers the wrong unit 2). In the lexical set the figures are 6, 7 (ties, mostly citation questions that share no words) and 0 out of 13. This supports the explanation that the missing rarity weighting is a main cause; it is an indication from a crude measure and a comparison with the first wrong unit only, and it does not prove that nothing else contributes.

The lexical question set

eval/lexical-questions.jsonl: 28 answerable questions in three styles (10 exact rare terms, 9 numbers or amounts, 9 citation lookups such as "Was regelt § 172 Abs. 1 AO?"), derived from the corpus text and validated by code: each quoted term occurs in the expected unit, each citation equals the label of the expected unit, and no unrelated unit contains all the terms (apparent ambiguities were decided one by one and recorded with a reason in not_expected; ten apparent ambiguities came up: four questions were dropped and six were recorded with a reason). Six questions that needed such a judgment are flagged needs_review. The set favors lexical matching by construction and is reported separately from the paraphrase set; the questions were chosen and checked by the same author, not by anyone else.

Decision rule

Fixed before the runs (rule in the merged change lexical-retrieval; the candidate list below was written before the first run):

Results

Development half, MRR (pooled over 38 paraphrase and 14 lexical questions):

Configuration paraphrase dev lexical dev pooled
vector only (previous default) 0.879 0.550 0.791
hybrid, Postgres full-text (older default) 0.798 0.617 0.750
hybrid, BM25 0.913 0.546 0.814
hybrid, BM25, full-text weight 0.5 0.901 0.562 0.810
vector + citation matching 0.866 0.738 0.832
hybrid, BM25 + citation matching 0.900 0.728 0.854
hybrid, strict AND query with fallback 0.811 0.617 0.759
hybrid, strict AND query, weight 0.5 0.860 0.633 0.799

The finalist is BM25 plus citation matching. Held-out half:

Configuration paraphrase (37) recall@5 / MRR lexical (14) recall@5 / MRR
vector only 0.946 / 0.900 0.643 / 0.522
hybrid, Postgres full-text 0.838 / 0.697 0.714 / 0.677
hybrid, BM25 + citation matching 0.946 / 0.901 0.786 / 0.713

Against vector-only, on the held-out paraphrase questions the finalist differs by MRR +0.001 (95% interval [-0.071, +0.073]) and recall@5 +0.000, not significant, so it is not significantly worse. On the held-out lexical questions MRR is +0.191 [+0.040, +0.373], significant, and recall@5 +0.143 [-0.143, +0.429], not significant. Both conditions of the rule hold.

All questions (75 paraphrase, 28 lexical):

Configuration paraphrase recall@5 / MRR lexical recall@5 / MRR
hybrid, BM25 + citation (default) 0.960 / 0.900 0.857 / 0.720
vector only 0.960 / 0.889 0.679 / 0.536
hybrid, BM25 without citation 0.960 / 0.907 0.607 / 0.538
hybrid, Postgres full-text 0.907 / 0.748 0.714 / 0.647
full-text only (Postgres) 0.627 / 0.396 0.536 / 0.428

On all lexical questions the default beats vector-only in MRR by +0.185 [+0.081, +0.304]; recall@5 by +0.179 [0.000, +0.357]. On all paraphrase questions it is +0.011 [-0.034, +0.056], not significant.

Decision

The default search is hybrid with BM25 and citation matching (full-text weight 1). Vector-only, the Postgres full-text ranking, the strict AND query, the common-term filter and the fusion weights remain selectable options.

What the numbers say, and what they do not:

Consequences

Limits of the evidence