Repository navigation
Tunable multi-hit name resolution with structure clustering + OPSIN - #2
Merged
Merged
Conversation
Reworks Search name resolution to fix wrong-hit selection and add flexible, tunable matching: - Candidate pooling: collect top-k candidates per source instead of collapsing each source to one pre-chosen winner before consensus. - Structure clustering: pool is clustered into distinct compounds by InChIKey (skeleton-aware), so a wrong #1 hit from one source no longer dominates. - Query-aware ranking: clusters ranked by a confidence combining method base, how well each candidate matches the query (name similarity / Tanimoto), and cross-source support. Exact-identifier paths reproduce the old confidence. - Multi-hit output: n_hits (int or "all") + min_confidence return ranked distinct compounds with a hit_rank column; default stays one row per query. New columns: hit_rank, n_source_support, opsin_smiles (+ optional alternatives). DataFrame/file extra columns broadcast across hit rows. - PYOPSIN anchoring (opt-in, use_opsin): IUPAC names parsed to SMILES offline and used as a high-confidence structure anchor; pulls the correct compound by InChIKey regardless of name spelling. Graceful fallback without Java. - Tunable knobs (were hard-coded): top_k_per_source, cluster_by_skeleton, fuzzy_score_cutoff, fuzzy_scorer, consensus_compat_threshold, query_weight. - All resolvers (cas/name/smiles/inchi/inchikey/dtxsid/formula) flow through the same pool -> cluster -> rank -> finalise pipeline. Validation (scripts/validate_name_search.py) against CompTox CASRN ground truth: on a hard synonym sample the resolver returns 0 wrong hits at 100% precision (default), and enabling OPSIN lifts recall from 16% to ~99.5% while holding precision. Adds a precision regression test asserting zero wrong hits. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Searchreturned exactly one merged hit per query, and for name queries that hit was often wrong. Root cause: each source was collapsed to a single candidate (rows[0]/ first synonym) before consensus scoring, so a wrong #1 hit from one source could dominate and the correct compound (hit #2 elsewhere) was never seen.What changed
kcandidates per source instead of one pre-chosen winner.n_hits(int or"all") +min_confidencereturn ranked distinct compounds with ahit_rankcolumn. Default stays one row per query. New columns:hit_rank,n_source_support,opsin_smiles(+ optionalalternatives). DataFrame/file extra columns broadcast across hit rows.use_opsin=True) — IUPAC names parsed to SMILES offline and used as a high-confidence anchor; pulls the correct compound by InChIKey regardless of name spelling. Graceful fallback when Java/py2opsin is absent.top_k_per_source,cluster_by_skeleton,fuzzy_score_cutoff,fuzzy_scorer,consensus_compat_threshold,query_weight.pool → cluster → rank → finalisepipeline.Validation
scripts/validate_name_search.pyreproduces the CASRN→table→reproduce-by-name idea using CompTox as ground truth (correctness = InChIKey skeleton). On a hard 200-chemical synonym sample (all sources):¹ the single tuned "wrong hit" is an inorganic salt (
Cerium(3+) triiodate) reported at confidence 0.0.The wrong-hit failure mode is eliminated in precision-first default mode; the remaining default gap is recall, which the tunables (esp. OPSIN) close.
Tests
tests/test_search_multihit.py— 25 unit tests (clustering, validation, ranking, multi-hit, broadcast, OPSIN).tests/test_search_precision_regression.py— integration test asserting zero wrong hits vs CompTox ground truth (skips when the offline DB is absent).test_exact_inchikey_with_low_consensus) is pre-existing — it fails identically onmain.Notes
uv.lockis intentionally not included (itsplatformdirschange pre-existed this branch and is unrelated).🤖 Generated with Claude Code