Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ set(CPP_FILES
# ivf
if (SVS_EXPERIMENTAL_ENABLE_IVF)
list(APPEND CPP_FILES
src/dynamic_ivf.cpp
src/ivf.cpp
)
endif()
Expand Down
39 changes: 39 additions & 0 deletions bindings/python/include/svs/python/dynamic_ivf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2025 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

// svs python bindings
#include "svs/python/core.h"

#include <pybind11/pybind11.h>

namespace svs::python::dynamic_ivf {

// Specializations
template <typename F> void for_standard_specializations(F&& f) {
#define X(Q, T, Dist, N) f.template operator()<Q, T, Dist, N>()
X(float, float, DistanceL2, Dynamic);
X(float, float, DistanceIP, Dynamic);
X(float, svs::Float16, DistanceL2, Dynamic);
X(float, svs::Float16, DistanceIP, Dynamic);
X(float, svs::BFloat16, DistanceL2, Dynamic);
X(float, svs::BFloat16, DistanceIP, Dynamic);
#undef X
}

void wrap(pybind11::module& m);
} // namespace svs::python::dynamic_ivf
22 changes: 22 additions & 0 deletions bindings/python/include/svs/python/ivf.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,28 @@ template <typename Manager> void add_interface(pybind11::class_<Manager>& manage

See also: `svs.IVFSearchParameters`.)"
);

manager.def(
"get_distance",
[](const Manager& index, size_t id, const py_contiguous_array_t<float>& query) {
return index.get_distance(id, as_span(query));
},
pybind11::arg("id"),
pybind11::arg("query"),
R"(
Compute the distance between a query vector and a vector in the index.

Args:
id: The ID of the vector in the index.
query: The query vector as a numpy array.

Returns:
The distance between the query and the indexed vector.

Raises:
RuntimeError: If the ID doesn't exist or dimensions don't match.
)"
);
}

void wrap(pybind11::module& m);
Expand Down
Loading
Loading