Skip to content

harden vector operations — bug fixes, tests, docs - #96

Merged
kacy merged 3 commits into
mainfrom
harden/vector-audit
Feb 12, 2026
Merged

harden vector operations — bug fixes, tests, docs#96
kacy merged 3 commits into
mainfrom
harden/vector-audit

Conversation

@kacy

@kacy kacy commented Feb 12, 2026

Copy link
Copy Markdown
Owner

summary

  • fix 5 bugs found during vector code audit: NaN/infinity validation, search ef state pollution, panic paths in clone and vadd, u64 overflow
  • add 8 persistence integration tests (AOF round-trip, snapshot round-trip, recovery with add/remove/auto-delete)
  • add vector similarity search section to README

what was tested

  • all 796 unit tests pass with --features vector
  • all 411 unit tests pass without vector feature (no regressions)
  • cargo fmt --all -- --check clean
  • cargo clippy --workspace --features vector -- -D warnings clean

design considerations

NaN/infinity rejection: usearch behavior with non-finite floats is undefined. vectors are now validated before reaching the HNSW index — both in add() and search().

expansion_search state pollution: change_expansion_search() mutates the index's internal state. previously, calling VSIM with a custom EF value would affect subsequent searches that used the default. now we explicitly set ef on every search call (default: 64).

fallible clone: the Clone impl previously used expect() which would crash the server if usearch couldn't allocate. now uses try_clone() with a graceful fallback to an empty set — data loss is preferable to a server crash.

kacy added 3 commits February 12, 2026 09:12
- reject NaN/infinity in add() and search() (NonFinite error variant)
- always set expansion_search explicitly in search() to prevent state
  pollution between calls (default ef=64)
- use wrapping_add for next_key to prevent overflow
- add try_clone() for fallible index cloning, graceful Clone fallback
- replace expect("just inserted") in vadd with proper error return
- AOF round-trip: vadd (3d and 1536d), vrem serialization
- snapshot round-trip: vector entries, empty vector set with TTL
- recovery: snapshot load, AOF replay with add+remove, auto-delete
  on last element removal
@kacy
kacy merged commit 80fbc59 into main Feb 12, 2026
5 of 7 checks passed
@kacy
kacy deleted the harden/vector-audit branch February 12, 2026 15:08
kacy added a commit that referenced this pull request Feb 19, 2026
* fix: harden vector operations — NaN validation, ef leak, panic paths

- reject NaN/infinity in add() and search() (NonFinite error variant)
- always set expansion_search explicitly in search() to prevent state
  pollution between calls (default ef=64)
- use wrapping_add for next_key to prevent overflow
- add try_clone() for fallible index cloning, graceful Clone fallback
- replace expect("just inserted") in vadd with proper error return

* test: add vector persistence integration tests

- AOF round-trip: vadd (3d and 1536d), vrem serialization
- snapshot round-trip: vector entries, empty vector set with TTL
- recovery: snapshot load, AOF replay with add+remove, auto-delete
  on last element removal

* docs: add vector similarity search to readme
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