Skip to content

search: choose the out-of-core retrieval strategy automatically, and say which one (#76) - #84

Merged
ypriverol merged 2 commits into
docs/benchmark-numbers-2026-09-10from
feat/fragment-index-auto
Sep 10, 2026
Merged

ypriverol merged 2 commits into
docs/benchmark-numbers-2026-09-10from
feat/fragment-index-auto

Conversation

@ypriverol

Copy link
Copy Markdown
Contributor

Stacked on #83 (docs). Removes the retrieval knob and makes the engine choose correctly, which it was not doing.

The defect this fixes

--fragment-index auto selected the fragment-ion index for any out-of-core search. It never looked at fragment resolution. Measured on the three standard sets, same binary, 8 threads, Percolator seed 42, forcing the index on:

dataset in-RAM enumeration (the default) index forced on
Astral, high-res 267 s, 38,394 PSMs @1% 222 s, 46,774
TMT a05058, low-res 94 s, 12,281 118 s, 3,613
UPS1, low-res 52 s, 15,838 65 s, 10,312

On low-resolution data the index loses most of the identifications and runs slower: it bins ions at the fragment tolerance and ranks candidates by peak votes, and a 0.5 Da bin does not discriminate. No benchmark caught this because both low-res sets fit in RAM and so never took the out-of-core path — but a large low-resolution search (a PTM-rich ion-trap run, say) would have hit it silently.

The Astral row is not a win and is documented as not being one. A candidate filter cannot create identifications. The top-1-per-scan competition shows the mechanism: decoy wins fall 9.4% while target wins fall 1.8%, so decoys leave the competition preferentially and the decoy-based q-values become optimistic. Astral has no entrapment component to detect that. Where the index is selected, the phospho benchmark measures error with a 1:1 entrapment database and it goes down (1.22–1.32% → 1.15–1.16%), which is why that result stands.

What changes

  • Selection requires out-of-core AND high-resolution fragment matching, and is made by one function, retrieval_choice, with eight unit tests covering every branch including the two refusals.
  • The engine prints the strategy it chose and why, once, e.g. candidate retrieval: fragment-ion index (out-of-core index, high-resolution fragments at 20 ppm; 100 candidates per spectrum, >= 3 matched b/y ions) or candidate retrieval: per-spectrum enumeration (out-of-core index, but low-resolution fragment matching — the fragment-ion index is not selective at a 0.5 Da tolerance). In-RAM searches say nothing, because there is no choice to report.
  • --fragment-index becomes hidden. It stays as an escape hatch for reproducing a measurement (the benchmark README uses off to reproduce the enumeration rows), but it is out of --help and its DOCS row is replaced by a note describing the automatic behaviour. Forcing on where the index cannot be used now refuses with the reason instead of silently doing nothing.
  • The benchmark README gains Choosing the retrieval strategy, with the table above and the decoy-bias explanation, and the known-gaps entry shrinks to the one thing still unmeasured: the index does not reproduce the enumeration path's multiplicity copies in the PIN Proteins column.

Verification

cargo test --workspace 1,121 passed (8 new), clippy at -D warnings, and the four ignored out-of-core equivalence gates pass. Behaviour checked end to end on the fixture: high-res out-of-core selects the index, low-res out-of-core selects enumeration and says why, forcing on at low resolution is refused, and an in-RAM run prints nothing.

…say which one (#76)

The fragment-ion index was selected for any out-of-core search. Measured on
the standard sets by forcing it on (8 threads, Percolator seed 42), that is
wrong on low-resolution data: TMT 12,281 -> 3,613 PSMs @1% and UPS1 15,838 ->
10,312, both while running slower, because the index bins ions at the fragment
tolerance and a 0.5 Da bin does not discriminate. No benchmark hit this
because the low-res sets fit in RAM, but a large low-res search would have.

Selection now requires out-of-core AND high-resolution fragment matching, is
made by one testable function, and is reported in a single line naming the
reason. --fragment-index becomes a hidden escape hatch for reproducing a
measurement rather than a user-facing knob, and its DOCS row is replaced by a
note on the automatic behaviour.

The Astral row in that measurement (38,394 -> 46,774) is not a win and is
documented as such: top-1 decoy wins fall 9.4% against 1.8% for targets, so
the decoy competition is biased and the q-values are optimistic. Astral has no
entrapment component to catch it; where the index is selected, the phospho
entrapment FDP goes down rather than up.
@coderabbitai

coderabbitai Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 2bce9aa7-ad47-48d0-8ca6-fdd200abc5c6

📥 Commits

Reviewing files that changed from the base of the PR and between 7b21908 and f9c577b.

📒 Files selected for processing (4)
  • DOCS.md
  • crates/andes/src/bin/andes/cli.rs
  • crates/andes/src/bin/andes/search.rs
  • docs/benchmarks/README.md

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Automatically select and report out-of-core candidate retrieval

🐞 Bug fix ✨ Enhancement 🧪 Tests 📝 Documentation ⚙️ Configuration changes 🕐 20-40 Minutes

Grey Divider

AI Description

• Selects fragment indexing only for out-of-core, high-resolution searches.
• Reports retrieval decisions and refuses unsafe forced-index combinations.
• Hides the override and documents the benchmark-backed policy with comprehensive branch tests.
Diagram

graph TD
  B{"Out of core?"} -- "Yes" --> C{"Full-list mode?"} -- "No" --> D{"High resolution?"} -- "Yes" --> E["Fragment-ion index"] --> H["Strategy report"]
  B -- "No" --> F["Silent enumeration"]
  C -- "Yes" --> F
  D -- "No" --> G["Reported enumeration"] --> H
Loading
High-Level Assessment

The centralized pure decision function is the best approach: it keeps policy consistent, makes every branch directly testable, and separates selection from execution. Inline conditionals would duplicate policy, while removing the hidden override entirely would prevent benchmark reproduction without improving normal-user safety.

Files changed (4) +246 / -37

Bug fix (1) +189 / -23
search.rsCentralize and test retrieval strategy selection +189/-23

Centralize and test retrieval strategy selection

• Adds 'retrieval_choice' to select fragment indexing only for out-of-core, high-resolution searches and reject incompatible forced activation. Integrates one-time strategy reporting and adds eight unit tests covering resolution, backing mode, excluded modes, and overrides.

crates/andes/src/bin/andes/search.rs

Documentation (2) +47 / -6
DOCS.mdDocument automatic candidate retrieval selection +10/-1

Document automatic candidate retrieval selection

• Replaces the public '--fragment-index' option row with guidance explaining automatic strategy selection. Documents the performance and identification-quality rationale for excluding low-resolution and full-candidate-list searches.

DOCS.md

README.mdExplain measured retrieval policy and benchmark caveats +37/-5

Explain measured retrieval policy and benchmark caveats

• Adds benchmark evidence supporting the automatic selection criteria, including low-resolution regressions and the Astral target-decoy bias caveat. Updates limitations to reflect automatic selection while retaining the known PIN protein multiplicity difference.

docs/benchmarks/README.md

Other (1) +10 / -8
cli.rsHide the fragment-index benchmark override +10/-8

Hide the fragment-index benchmark override

• Removes '--fragment-index' from normal help output while retaining 'auto', 'on', and 'off' as measurement-reproduction escape hatches. Clarifies that ordinary searches should rely on engine selection.

crates/andes/src/bin/andes/cli.rs

@qodo-code-review

qodo-code-review Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Enumeration is reported as indexed 🐞 Bug ◔ Observability
Description
params.fragment_index_top_k preserves an explicit zero while choice.use_index remains true, and
the new message chooses its label only from choice.use_index. On an out-of-core high-resolution
run with --fragment-index-top-k 0, downstream > 0 checks take full enumeration but stderr says
“fragment-ion index ... 0 candidates,” misleading benchmark records and operators.
Code

crates/andes/src/bin/andes/search.rs[R765-768]

+        if choice.use_index {
+            eprintln!(
+                "candidate retrieval: fragment-ion index ({reason}; {} candidates per spectrum, \
+                 >= {} matched b/y ions)",
Evidence
The CLI type accepts zero, the new assignment retains it, and reporting depends on
choice.use_index; downstream construction and ordering instead enable the index only when the
resulting value is greater than zero.

crates/andes/src/bin/andes/cli.rs[203-207]
crates/andes/src/bin/andes/search.rs[754-770]
crates/andes/src/bin/andes/search.rs[1424-1425]
crates/search/src/match_engine.rs[703-741]
crates/search/src/match_engine.rs[903-936]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A zero fragment-index shortlist disables the downstream index while the new strategy report still claims indexed retrieval.

## Fix Focus Areas
- crates/andes/src/bin/andes/search.rs[754-769]
- crates/andes/src/bin/andes/cli.rs[203-207]

## Recommended Fix
Validate `--fragment-index-top-k` as nonzero before retrieval starts, returning a clear argument error for zero. Add a test proving that zero cannot reach the indexed reporting branch.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Wide ppm searches use wrong retrieval 🐞 Bug ≡ Correctness
Description
retrieval_choice equates every Tolerance::Ppm with high resolution without considering its
numeric width, although Tolerance::as_da scales ppm by fragment mass. For metadata-less MGF input,
any finite positive --fragment-tol-ppm is accepted, so an out-of-core search at 1000 ppm (1 Da at
m/z 1000) enables the nonselective fragment-ion shortlist instead of enumeration.
Code

crates/andes/src/bin/andes/search.rs[R75-77]

+    let high_res = match fragment_tol {
+        Tolerance::Ppm(_) => true,
+        Tolerance::Da(d) => d <= 0.05,
Evidence
The new branch selects the index for every ppm value, while the tolerance implementation proves that
the absolute window grows with mass. MGF users can supply unrestricted positive ppm values, and this
resulting classification directly controls fragment_index_top_k.

crates/andes/src/bin/andes/search.rs[75-78]
crates/model/src/tolerance.rs[9-16]
crates/andes/src/bin/andes/cli.rs[305-315]
crates/andes/src/bin/andes/cli.rs[1171-1183]
crates/andes/src/bin/andes/search.rs[748-758]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Every ppm tolerance is currently classified as high resolution, even when its effective fragment-mass window is too wide for selective fragment-ion retrieval.

## Fix Focus Areas
- crates/andes/src/bin/andes/search.rs[75-78]
- crates/andes/src/bin/andes/search.rs[2047-2125]

## Recommended Fix
Apply an explicit maximum supported ppm tolerance based on the index's selectivity criterion instead of treating the unit alone as proof of high resolution. Keep enumeration above that limit and add boundary tests, including a very wide ppm value.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context sources
Review mode: ⚖️ Balanced: Downgraded extended -> standard: change is below the extended eligibility bar (hunks 7/18, lines 283/200; both must reach the floor). Router rationale: This changes runtime retrieval selection and refusal behavior across several search modes, with CLI/API semantics, tolerance classification, reporting, and benchmark/documentation claims creating multiple independent, easy-to-miss correctness risks.

Grey Divider

Tip of the day
💡 Did you know, you can turn these tips off under Display preferences

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment on lines +75 to +77
let high_res = match fragment_tol {
Tolerance::Ppm(_) => true,
Tolerance::Da(d) => d <= 0.05,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

1. Wide ppm searches use wrong retrieval 🐞 Bug ≡ Correctness

retrieval_choice equates every Tolerance::Ppm with high resolution without considering its
numeric width, although Tolerance::as_da scales ppm by fragment mass. For metadata-less MGF input,
any finite positive --fragment-tol-ppm is accepted, so an out-of-core search at 1000 ppm (1 Da at
m/z 1000) enables the nonselective fragment-ion shortlist instead of enumeration.
Agent Prompt
## Issue description
Every ppm tolerance is currently classified as high resolution, even when its effective fragment-mass window is too wide for selective fragment-ion retrieval.

## Fix Focus Areas
- crates/andes/src/bin/andes/search.rs[75-78]
- crates/andes/src/bin/andes/search.rs[2047-2125]

## Recommended Fix
Apply an explicit maximum supported ppm tolerance based on the index's selectivity criterion instead of treating the unit alone as proof of high resolution. Keep enumeration above that limit and add boundary tests, including a very wide ppm value.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines +765 to +768
if choice.use_index {
eprintln!(
"candidate retrieval: fragment-ion index ({reason}; {} candidates per spectrum, \
>= {} matched b/y ions)",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

2. Enumeration is reported as indexed 🐞 Bug ◔ Observability

params.fragment_index_top_k preserves an explicit zero while choice.use_index remains true, and
the new message chooses its label only from choice.use_index. On an out-of-core high-resolution
run with --fragment-index-top-k 0, downstream > 0 checks take full enumeration but stderr says
“fragment-ion index ... 0 candidates,” misleading benchmark records and operators.
Agent Prompt
## Issue description
A zero fragment-index shortlist disables the downstream index while the new strategy report still claims indexed retrieval.

## Fix Focus Areas
- crates/andes/src/bin/andes/search.rs[754-769]
- crates/andes/src/bin/andes/cli.rs[203-207]

## Recommended Fix
Validate `--fragment-index-top-k` as nonzero before retrieval starts, returning a clear argument error for zero. Add a test proving that zero cannot reach the indexed reporting branch.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

…strategy table

Astral 38,394 and UPS1 15,838 are identical to the in-RAM counts and TMT is
within 0.3%, so the out-of-core path preserves identifications and everything
the index column does belongs to the index.
@ypriverol
ypriverol added this pull request to stack #87 September 10, 2026 11:01
@ypriverol
ypriverol merged commit 2297268 into main Sep 10, 2026
1 check passed
@ypriverol
ypriverol deleted the feat/fragment-index-auto branch October 15, 2026 16:05
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