Skip to content

[CPP Runtime] Add get_distance and reconstruct_at to VamanaIndex API#315

Open
yuejiaointel wants to merge 5 commits into
mainfrom
yuejiao/add-get-distance-reconstruct
Open

[CPP Runtime] Add get_distance and reconstruct_at to VamanaIndex API#315
yuejiaointel wants to merge 5 commits into
mainfrom
yuejiao/add-get-distance-reconstruct

Conversation

@yuejiaointel
Copy link
Copy Markdown
Contributor

@yuejiaointel yuejiaointel commented Apr 8, 2026

Summary

  • Add get_distance() and reconstruct_at() methods to the runtime shared library (VamanaIndex and DynamicVamanaIndex)
  • get_distance computes distance between a stored vector (by ID) and a query vector, returning a double
  • reconstruct_at decompresses/reconstructs stored vectors back to float32 by ID — works transparently with all storage kinds (FP32, FP16, SQI8, LVQ, LeanVec)
  • Both methods follow the existing runtime API pattern: pure virtual in the public header, runtime_error_wrapper in the manager, orchestrator dispatch in the impl layer

@yuejiaointel yuejiaointel marked this pull request as draft April 9, 2026 00:42
Add get_distance() and reconstruct_at() methods to the runtime library
for OpenSearch integration. These expose existing orchestrator-layer
functionality through the shared library ABI.

- get_distance: computes distance between a stored vector and a query
- reconstruct_at: decompresses/reconstructs vectors to float32 by ID
- Works with all storage kinds (FP32, FP16, SQI8, LVQ, LeanVec)
- Added to both VamanaIndex (static) and DynamicVamanaIndex
- Includes tests for both index types
@yuejiaointel yuejiaointel force-pushed the yuejiao/add-get-distance-reconstruct branch from 0ed65a3 to 9ac27bc Compare April 9, 2026 19:43
@yuejiaointel yuejiaointel marked this pull request as ready for review April 9, 2026 22:23
Copy link
Copy Markdown
Member

@rfsaliev rfsaliev left a comment

Choose a reason for hiding this comment

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

Please change new methods' signatures in VamanaIndexImpl and DynamicVamanaIndexImpl according to the signature style used in other existing methods i.e. typed containers rather than raw pointers

Comment thread bindings/cpp/include/svs/runtime/vamana_index.h Outdated
Comment thread bindings/cpp/src/dynamic_vamana_index_impl.h Outdated
Comment thread bindings/cpp/src/dynamic_vamana_index_impl.h Outdated
yuejiaointel and others added 4 commits May 20, 2026 13:26
…terpret_cast

- VamanaIndexImpl/DynamicVamanaIndexImpl: get_distance and reconstruct_at
  now take typed containers (std::span<const float>, SimpleDataView<float>,
  std::span<const size_t>), matching the existing add() convention. The
  Manager wrappers build the views from raw C-ABI pointers.
- Public API: get_distance returns float* instead of double* to match the
  rest of the runtime API (search distances, etc.).
- Replace unsafe reinterpret_cast<const uint64_t*>(ids) with a type-safe
  std::vector<uint64_t> copy.
Copy link
Copy Markdown
Member

@rfsaliev rfsaliev left a comment

Choose a reason for hiding this comment

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

LGFM
nitpicking comment can be ignored or addressed - up to your perfectionism :)

Comment on lines +89 to +92
get_distance(float* distance, size_t id, const float* query) const noexcept = 0;

// Reconstruct `n` vectors by ID into `output` buffer (n * dim floats).
virtual Status reconstruct_at(size_t n, const size_t* ids, float* output) noexcept = 0;
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.

nit: slight inconsistency: in get_distance(), the 'output' argument is the first, when reconstruct_at() - last.

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