Skip to content

Fix Unicode keyword matching and keep ANN widening on the paper shortlist - #38

Merged
wshlavacek merged 21 commits into
mainfrom
fix/stage-two-retrieval
Dec 1, 2026
Merged

wshlavacek merged 21 commits into
mainfrom
fix/stage-two-retrieval

Conversation

@wshlavacek

Copy link
Copy Markdown
Collaborator

Retrieval changes

Keyword front-loading now uses the same Unicode normalization for query terms, stored chunks and paper titles. Queries match ligatures, compatibility digits and case variants in existing databases. When a raised number could be either an isotope label or a table note, the search checks the shortlisted papers for the numbered acronym first and uses the bare acronym if that spelling is absent. Applications executing sqlite_norm_expr() directly on a raw SQLite connection can register the normalizer once with litkit.retrieval.register_search_normalizer(conn).

Widened FAISS searches now apply the Stage‑1 paper filter on every round and stop when every shortlisted paper reaches its cap. Duplicate chunk IDs count once. A sparse shortlist can still trigger the reported global fallback. An explicitly global lexical search can supply keyword matches from other papers while ANN widening stays constrained. Repeated paper IDs no longer make the shortlist appear sparse, and the CLI honors its documented LITKIT_ALLOW_GLOBAL_LEXICAL=1 setting.

Closes #20
Closes #25

Verification

  • Independent adversarial review of the full branch from 8e78224 through 80a25db returned clean. The final round also exercised a read-only existing SQLite database and a real FAISS index with duplicate hits.
  • Ran the regressions against the merged base and the branch. A real flat FAISS index has an exact lexical hit outside its initial ANN window, a first widening with only out-of-shortlist hits, and two eligible passages reached on the second widening. The checks also exercise duplicate IDs, sparse fallback and explicit global lexical scope.
  • On macOS ARM64, the full suite, including CPU and accelerator tests with cached model weights, passed 351 tests with one Windows-only skip and ten expected failures tracked in Consumer picks up unfinished *_pending.npz segments #4, Builds give a paper a second vector when it reappears #7 and Databases created before doc_id can't be opened #10.
  • Regression tests cover mixed-script questions such as BRCA1突变, scientific terms adjacent to table notes, isotope-specific results under a one-hit limit, SQLite locks and authorizers, and a capped one-paper shortlist where a single FAISS search is sufficient.
  • The installed CLI built and reopened an index offline. On a separate snapshot of an existing workspace, a query using cached production CPU models and the terms fibrosis-associated and CD4 returned two chunks from the one shortlisted paper, respecting the two-chunk cap.

SQLite timings

Measured the same three-term query (fibrosis-associated, rna, cd4) with a 200-result limit on Python 3.12.12 and SQLite 3.50.4. The benchmark used a temporary tenfold copy of a 297-paper, 11,670-chunk corpus. Times are medians of three warm runs after one warm-up.

Scope Chunks Main Branch
20 shortlisted papers 605 100.3 ms 13.5 ms
Global 116,700 20.01 s 2.78 s

…ortlist

Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
…zers

Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
…al databases

Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
…e boundaries

Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
…r digits

Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
…ules

Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
@wshlavacek
wshlavacek merged commit 3b50583 into main Dec 1, 2026
4 checks passed
@wshlavacek
wshlavacek deleted the fix/stage-two-retrieval branch December 1, 2026 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant