Skip to content

Correctness: filtered top-k underfill and vector mutation/input invariants (version-bound) #1310

Closed

Description

@ruvnet

Goal

Eliminate silent underfill and integrity ambiguity in RuVector retrieval, with version-bound regression evidence.

Provenance and scope

The retained 24 October 2026 CPU comparison (Titan Vector vs RuVector, prepared 2 November) measured 10,000 vectors per fixture. At 10% and 1% eligible selectivity, each tested older RuVector core flat/HNSW configuration returned fewer than the requested eligible top 10 on 7,200/7,200 queries. No wrong-namespace IDs were observed. Tested npm identities: ruvector 0.3.3 / @ruvector/core 0.1.33 / Linux native 0.1.31; separate repository binary c44d733. These are historical results, not verification of today's npm release.

Current repository inspection (2026-11-02):

Work packages

  1. P0: core VectorDB filtered top-k contract. Guarantee the complete eligible top min(k, eligible_count) for exact flat retrieval. Prefer a clearly documented correctness-first route, with bounded behavior, exact distance oracle, deterministic tie handling, and no unfiltered regression. Separate quantitative/performance optimization after correctness is proven. Do not advertise HNSW-filtered recall as exact unless explicitly reranked against the full eligible set.
  2. P1: duplicate ID mutations. Reproduce on HEAD across flat/HNSW and Node binding; define explicit upsert or reject semantics, and ensure returned vector and score always refer to the same revision. Avoid implicit mutation across persistence/index boundaries. Link any existing fix.
  3. P1: non-finite input checks. Audit insert, batch, search and persisted restored data across public bindings; reject NaN/±Infinity before mutation and distance sorts; fold into Sweep: 91 panicky float sorts (sort_by(partial_cmp().unwrap())) across 27 crates — NaN-reachable in core query paths (ADR-340 invariant 1) #931 where relevant.
  4. Regression and benchmark matrix. Corpus sizes 10K/100K/1M; dimensions 128/384/768; selectivity 1%/10%/100%; flat and HNSW; warm/cold, update/delete/restart, concurrent reads. Measure recall@10, complete eligible top-k, namespace validity, p50/p95/p99, build and memory. Compare identical work and latest published vs source binary.

Acceptance criteria

  • With >=10 eligible entries: all 10 returned, unique, allowed namespace IDs, correctly scored and ordered; with <10: return exactly eligible_count.
  • Exact filtered flat path recall@10 = 100% against an independent distance oracle (including boundary ties).
  • Duplicate-ID insert/update either rejects with no side effects or enforces deterministic upsert with matching vector/score in storage and ANN.
  • NaN/Infinity inputs produce a typed error with no persisted mutation; non-finite scores never reach result sorting.
  • Preserve unfiltered behavior, demonstrate CI + isolated tests + before/after benchmark and label all untested environments explicitly.

Execution policy

Use small linked PRs, tests first, no claim of production readiness from source inspection, no automatic merge until matching performance/security review. This issue tracks the gap; individual PRs must state exactly which public path they fix.

Activity

  1. ruvnet commented on Nov 2, 2026

    @ruvnet
    OwnerAuthor

    Execution progress, 2026-11-02

    P0 core filtered path implemented in draft PR #1311, commit bd73ee8a. It adds exact eligible fallback on underfill and two regression tests. Hosted CI triggered; no Rust passing result claimed until checks finish.

    Additional issue/PR triage to avoid duplicate fixes:

    Next gate: CI for #1311, benchmark correctness fallback at 10K/100K/1M with selectivity 1%/10%, and decide whether to replace O(N) scan with indexed exact prefilter before enabling in latency-sensitive production. Historical 2026-10-24 comparison tested older npm native bytes; an updated source commit does not establish a new published binary result.

  2. ruvnet commented on Nov 2, 2026

    @ruvnet
    OwnerAuthor

    Progress: draft PR #1312 fixes the separate Node JSON boundary problem. It now rejects malformed search filters and insert metadata instead of silently dropping either field. This is independent of the filtered top K correction in draft PR #1311. Both require hosted CI and a pinned native binding test before release.

  3. ruvnet commented on Nov 2, 2026

    @ruvnet
    OwnerAuthor

    Integration review: #1161, #1167 and #1150 currently report mergeable=false, so treat those existing fixes as unresolved until conflicts are handled and tests rerun. #1078 reports mergeable=true but remains open. None should be called a shipped fix yet.

  4. ruvnet commented on Nov 9, 2026

    @ruvnet
    OwnerAuthor

    Fixed by #1443 (merge b59a81a) and published as ruvector-core 2.5.1 on crates.io.

    Qualified on main (1b3e11d) before the fix, with the new crates/ruvector-core/tests/retrieval_correctness.rs (10k × 32-D, HNSW and flat):

    Contract main 2.5.1
    Filtered top-10 full at 1% and 10% selectivity (≥10 eligible) pass (already fixed by #1368) pass
    Re-inserting an existing ID is an upsert with no ghost fail: ghost of v0 at old position, score 0 pass
    NaN / ±Inf rejected on insert, insert_batch (whole batch before storage), search fail: insert accepted NaN pass

    Duplicate-ID semantics are upsert: one live row, and the superseded HNSW node becomes a tombstone that can no longer answer for the ID (this also covers snapshots written by older versions). Non-finite vectors get InvalidInput. Both contracts, plus tests/filtered_search.rs, now run on every PR (regression-guard / ruvector-core-retrieval-correctness).

    npm level (npm/packages/core/test-retrieval.js, the same contract through the native binding):

    • Published @ruvector/core@0.1.37, fresh install: filtered top-10 ok; FAIL upsertWithoutGhosts: hnsw=true: ghost of v0 at its old position; FAIL rejectsNonFinite: … insert accepted NaN.
    • A binding built from this fix, in the same install: retrieval correctness: all passed.

    From crates.io, in a fresh project depending on ruvector-core = "=2.5.1":

    len=2000 ghost_of_v0=false nan_insert_rejected=true nan_query_rejected=true
    

    The npm build of @ruvector/core that contains this fix comes next through the attested release workflow. Releases built before b59a81a (including the in-flight 0.1.38 platform build) do not include it. I'll note the version here once it's out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions