Skip to content

corpus: lexical_support, an absolute measure of how well a query is c… - #2

Merged
1ay1 merged 1 commit into
agentty-org:mainfrom
sail3r:lexical-support
Dec 3, 2026
Merged

1ay1 merged 1 commit into
agentty-org:mainfrom
sail3r:lexical-support

Conversation

@sail3r

@sail3r sail3r commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

corpus: lexical_support, an absolute measure of how well a query is covered

Problem

A search result doesn't say whether the corpus can answer the query at all. The fused score is min-max normalised per query (convex_combination, after Bruch et al.), so the top hit scores near 1 for any query. A host deciding whether to use the results, for example to inject them into a prompt unasked, can only pick a cut-off inside that narrow band. The band also moves with fusion settings and with the dense retriever on or off.

In agentty, which gates proactive retrieval on that score with a bar of 0.35, all 160 injections in one user's history scored between 0.90 and 0.96, so the bar never rejected anything. Re-scored with this measure, 157 of those 160 injections would have been rejected. In the sample read by hand, the injected memory facts were unrelated to the question.

Change

  • Bm25Index::ceiling(terms): the most any document could score for those terms, which is every distinct term at saturation: Σ idf(nₜ) · (k1 + 1). A term the corpus lacks counts at its full idf, so a query about something the corpus never mentions has a high ceiling that no document approaches.
  • Corpus::lexical_support(query): the best live chunk's BM25 score divided by that ceiling, together with the number of distinct analysed query terms.
    • The result is in [0, 1) on any corpus, and the top hit isn't 1 by construction.
    • Tombstoned chunks are excluded, as in lexical_search.
    • The term count lets a host refuse to trust a very short query that matched by luck.

Nothing existing changes.

Evidence

The real engine indexed agentty's docs (50 labelled answerable questions from its retrieval eval) and its source tree (100 labelled), with 36 questions neither corpus answers (20 general knowledge, 16 tasks for tools). ROC AUC measures how well each score separates answerable from unanswerable questions:

score docs source
fused top score (today) 0.84 0.89
raw BM25 top score 0.87 0.95
lexical_support 0.89 0.89

Raw BM25 separates comparably, but its best cut-off was 11.1 on one corpus and 12.6 on the other. lexical_support worked with one cut-off on both: at 0.35 it keeps 86% / 80% of the answerable questions and lets none of the 20 general-knowledge questions through.

Tasks whose words appear in the corpus ("show me the git log") can't be separated by any corpus-side score. agentty filters those by wording before it retrieves.

Tests

lexical_support_is_low_for_queries_the_corpus_does_not_answer:

  • a covered query scores in (0.25, 1);
  • a query with no term in the corpus scores 0;
  • a query sharing one rare term scores between the two;
  • an empty query has 0 terms and 0 support;
  • adding a document that answers the off-corpus query raises its support above 0.25.

Only syntax-checked here. Please run ctest.

…overed

Nothing in a search result says whether the corpus can answer the query at
all. The fused score is min-max normalized per query, so the top hit sits
near 1 for any query, answerable or not; a host that gates on it can only
pick a cut-off inside that narrow band, and the band moves with fusion
settings and with the dense retriever on or off.

lexical_support(query) divides the best live chunk's BM25 score by the
most this query could score (Bm25Index::ceiling: each distinct term at
saturation, idf * (k1 + 1); a term the corpus lacks counts at full idf).
The result is in [0, 1) on any corpus, and the top hit is not 1 by
construction. It also returns how many distinct analyzed terms the query
had, so a host can refuse to trust a two-word query that matched by luck.

Measured on agentty's docs (50 labelled answerable questions) and its
source tree (100), each against 36 questions the corpus cannot answer, it
separates them with ROC AUC 0.89 on both, where the raw BM25 score, the
next best, needs a different cut-off per corpus (11.1 vs 12.6).
@1ay1
1ay1 merged commit afde7b0 into agentty-org:main Dec 3, 2026
7 checks passed
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.

2 participants