Skip to content

fix(core): reject nonfinite vectors and duplicate IDs before index mutation - #1316

Closed
ruvnet wants to merge 1 commit into
fix/filtered-topk-1313from
fix/core-input-contracts-1313
Closed

ruvnet wants to merge 1 commit into
fix/filtered-topk-1313from
fix/core-input-contracts-1313

Conversation

@ruvnet

@ruvnet ruvnet commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

Stacked implementation, depends on #1315

Review order: first #1315 (filtered top-k), then this PR (input integrity). This PR is deliberately based on fix/filtered-topk-1313 to avoid competing edits to vector_db.rs. After #1315 merges, retarget this PR to main and re-run hosted CI. Do not merge out of order.

Tracking issue: #1313. Related prior reports: #1134 (Python SDK), #931 (nonfinite float safety).

Confirmed regressions against unmodified main

  • Explicit duplicate IDs were accepted. test_duplicate_id_is_rejected_without_mutating_existing_vector failed on main and passes with this change.
  • NaN insert was accepted. test_nonfinite_insert_and_query_rejected failed on main and passes with this change.
  • Two regression tests both failed on main (exit 101) and passed with this fix. Additional batch atomic-preflight and HNSW duplicate tests pass.

Fix

  • Validate dimension and finite vectors before VectorDB insert, batch insert or search operations.
  • Serialize VectorDB insert mutations under the index write lock and preflight explicit ID uniqueness against persisted storage.
  • Reject duplicates within input batches or collisions with already stored IDs before mutation.
  • Preserve zero vectors for Euclidean distance; do not impose global normalization.

Combined state validation (both stacked changes together)

  • cargo test -p ruvector-core --lib: 284 passed, 0 failed, 2 ignored.
  • cargo test -p ruvector-core --no-default-features --lib: 284 passed, 0 failed, 2 ignored.
  • Matched debug filtered benchmark (10k x 384D, 40 queries/selectivity): 40/40 complete at both 10% and 1%; p50 16.566 ms / 14.318 ms respectively. This includes finite-query validation and remains within run-to-run variance of fix(core): complete filtered top-k with adaptive refill and selective memory optimization #1315 alone.
  • GitHub blob SHA matches the exact locally tested combined file.

Compatibility decision required before merge

Rejecting duplicate IDs is a behavior change for callers who relied on implicit upsert. It prevents stale HNSW nodes and score/vector mismatches, but may break those callers. Review whether an explicit atomic upsert API or migration guidance is necessary. This draft is not release approval.

Known limits

This fixes the VectorDB contract only. Low-level HNSW, MemoryStorage, npm binary and Python SDK behaviors are not universally covered. Auto-generated ID collision, crash consistency, full concurrent snapshot semantics and 100k/1M load tests remain separate qualification tasks. No hosted CI has reported a status yet.

@ruvnet
ruvnet changed the base branch from main to fix/filtered-topk-1313 November 2, 2026 14:07

ruvnet commented Nov 2, 2026

Copy link
Copy Markdown
Owner Author

Additional verified runtime and release benchmark evidence (2026-11-02)

Native Node runtime, rebuilt from combined current-source changes

  • cargo build -p ruvector-node --quiet: exit 0, native addon compiled.
  • Loaded locally compiled libruvector_node.so as a temporary .node addon with Node.js. The actual NAPI export is VectorDb.
  • Inserted 100 records from JavaScript using Float32Array and JSON metadata, 10 eligible; exact filtered search with k=10 returned 10/10 eligible records (no wrong-namespace IDs).
  • Attempted explicit duplicate ID insert: rejected.
  • Attempted NaN insert: rejected.
  • Receipt: NATIVE_SMOKE_PASS filtered=10/10 duplicate_rejected=true nonfinite_rejected=true, Node exit 0.
  • This is a freshly rebuilt core/native addon smoke test, not a published npm package test or deployed-service validation.

Optimized release benchmark, combined branch

Single local ruOS desktop, deterministic synthetic in-memory flat search, 384D, 10%/1% metadata eligibility, k=10:

Corpus Queries per selectivity Complete top-k 10% p50 / p95 1% p50 / p95
10,000 vectors 40 40/40 each 4.165 / 5.166 ms 1.862 / 4.269 ms
100,000 vectors 20 20/20 each 76.203 / 95.837 ms 67.721 / 78.816 ms

100k variant was an ephemeral modification to the ignored 10k benchmark harness, restored after execution. These release results are not a matched unmodified-main release performance comparison, nor production latency guarantees. Release 100k shows linear-scan cost remains a scale risk and warrants a metadata index/predicate-aware ANN strategy.

Gates unchanged

Both implementation PRs remain draft. No hosted GitHub CI status reported. No 1M load test, multi-thread mutation stress, service authorization, persistence crash or npm-published-binary certification. Explicit duplicate ID reject semantics are a compatibility review item.

ruvnet commented Nov 2, 2026

Copy link
Copy Markdown
Owner Author

Optimization follow-up: draft #1317 stacks on this branch and adds a selective equality inverted index. Combined Rust tests 288 passed, native Node smoke passed. This PR's duplicate-ID rejection remains a compatibility decision requiring review before merge. Merge order #1315 → #1316 → #1317.

@ruvnet

ruvnet commented Nov 6, 2026

Copy link
Copy Markdown
Owner Author

Not superseded by #1368. That PR keeps upsert semantics, and this one turns a duplicate-id insert into an error, which breaks concurrent_tests::test_concurrent_metadata_updates (the Tests (core-and-rest) failure here). In #1368 a re-added id's stale HNSW node is excluded from filtered results by a liveness check. This PR needs a rebase onto c8d7b1c, plus a decision on the upsert contract, before it can land.

@ruvnet

ruvnet commented Nov 12, 2026

Copy link
Copy Markdown
Owner Author

Closing as superseded by main commit 8ce9cfe (ruvector-core 2.5.1, #1443): VectorDB::insert, insert_batch (whole batch, before storage) and search already reject NaN/Inf vectors with InvalidInput. This PR's other half, rejecting an explicit duplicate ID, now contradicts main: re-inserting an existing id is a deliberate upsert on main (the old HNSW node is retired, no ghost). Its base #1315 was closed unmerged on 2026-11-06 and filtered top-k completeness is already locked in by tests/retrieval_correctness.rs. If strict duplicate-ID rejection is wanted as an opt-in, please open a fresh PR against main.

@ruvnet ruvnet closed this Nov 12, 2026
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