Skip to content

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

Open
yuejiaointel wants to merge 1 commit intomainfrom
yuejiao/add-get-distance-reconstruct
Open

[CPP Runtime] Add get_distance and reconstruct_at to VamanaIndex API#315
yuejiaointel wants to merge 1 commit intomainfrom
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

) const noexcept = 0;

// Compute distance between stored vector `id` and `query` (dim floats).
virtual Status get_distance(double* distance, size_t id, const float* query)
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.

Not sure if it makes sense to add double type usage for just 1 call.
Wouldn't it be enough float type here?
@ibhati , your thoughts?

throw StatusException{ErrorCode::NOT_INITIALIZED, "Index not initialized"};
}
svs::data::SimpleDataView<float> dst{output, n, dim_};
std::span<const uint64_t> id_span{reinterpret_cast<const uint64_t*>(ids), n};
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.

Even if on x86-64 CPU size_t is equal to uint64_t, there is still the risk of reinterpret_cast here.
Would suggest type-safe conversion:

Suggested change
std::span<const uint64_t> id_span{reinterpret_cast<const uint64_t*>(ids), n};
std::vector<const uint64_t> id_vec(ids, ids + n);

return impl_->get_distance(id, query_span);
}

void reconstruct_at(size_t n, const size_t* ids, float* output) {
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.

Instead of raw pointers here, I would recommend to follow approaches for existing methods' signatures defined in this class where arguments are typed.
See: void DynamicVamanaIndexImpl::add(data::ConstSimpleDataView<float> data, std::span<const size_t> labels)

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