Skip to content

feat: add distance scores to dense search results - #101

Open
Arshdeep54 wants to merge 1 commit into
sdslabs:mainfrom
Arshdeep54:main
Open

Arshdeep54 wants to merge 1 commit into
sdslabs:mainfrom
Arshdeep54:main

Conversation

@Arshdeep54

Copy link
Copy Markdown
Collaborator

Summary

Search results now return a distance score alongside each point ID (lower = closer).

Changes

  • VectorIndex::search returns (PointId, distance) pairs, updated Flat, KD-tree and HNSW
  • HNSW returns true Euclidean distance (sqrt applied), matching Flat and KD-tree
  • HNSW now rejects queries whose similarity differs from the index's
  • Cosine distance returns 1.0 for zero vectors instead of NaN
  • Python client: search / batch_search return (point_id, score) tuples

@Arshdeep54

Copy link
Copy Markdown
Collaborator Author

Pinned toolchain version to 1.98.1

@TanmayArya-1p TanmayArya-1p left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

small nits for asserting distance in tests. apart from that LGTM

Comment thread crates/api/src/tests.rs

assert_eq!(results.len(), 1);
assert_eq!(results[0], ids[0]); // The first vector should be closest
assert_eq!(results[0].0, ids[0]); // The first vector should be closest

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we should assert the similarity score also here

assert_eq!(results.len(), 2);
assert_eq!(results[0], id1); // Closest
assert_eq!(results[1], id2); // Second closest
assert_eq!(results[0].0, id1); // Closest

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should probably assert distance here as well

assert_eq!(results[0], id1);
assert_eq!(results[1], id2);
assert_eq!(results[0].0, id1);
assert_eq!(results[1].0, id2);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should assert distance here as well

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.

2 participants