[CPP Runtime] Add get_distance and reconstruct_at to VamanaIndex API#315
[CPP Runtime] Add get_distance and reconstruct_at to VamanaIndex API#315yuejiaointel wants to merge 1 commit intomainfrom
Conversation
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
0ed65a3 to
9ac27bc
Compare
rfsaliev
left a comment
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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}; |
There was a problem hiding this comment.
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:
| 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) { |
There was a problem hiding this comment.
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)
Summary
get_distance()andreconstruct_at()methods to the runtime shared library (VamanaIndexandDynamicVamanaIndex)get_distancecomputes distance between a stored vector (by ID) and a query vector, returning adoublereconstruct_atdecompresses/reconstructs stored vectors back tofloat32by ID — works transparently with all storage kinds (FP32, FP16, SQI8, LVQ, LeanVec)runtime_error_wrapperin the manager, orchestrator dispatch in the impl layer