Skip to content

Commit 4b889af

Browse files
authored
Add mutli-vector index and batch iterator support (#123)
This PR introduces multi-vector indexing and batch iterator functionality. With this PR, each label can be associated with multiple vectors, while ensuring that neighbors are retrieved with unique labels during search. - Key APIs for `MultiBatchIterator`: `next`: Retrieve a batch of neighbors, ensuring each neighbor has a unique label. - Key APIs for `MultiMutableVamanaIndex`: `search`: Utilize `MultiBatchIterator` to perform searches. `add_points`: Allow the addition of points to the index, associating each with a corresponding label. Points with the same label can be added without issue. `delete_entries`: Remove all vectors associated with a specific label from the index. `get_distance`: Return the shortest distance among vectors with the given label and query. `make_batch_iterator`: Return a `MultiBatchIterator` associated with the current index. - Add `make_batch_iterator` to `MutableVamanaIndex` and `VamanaIndex` as well to enhance functionality. #TODOs: - [x] Add more unittests - [x] Add different types of distance into unittests - [ ] Documentation - [ ] (TBD) Disable translator in `MutableVamana` for `MultiMutableVamanaIndex` - [ ] Elevate `MultiMutableVamana` at orchestrator/type-ersure level and eventually to python bindings
1 parent 4e2cd31 commit 4b889af

File tree

7 files changed

+917
-4
lines changed

7 files changed

+917
-4
lines changed

include/svs/index/vamana/dynamic_index.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444

4545
namespace svs::index::vamana {
4646

47+
template <typename Index, typename QueryType> class BatchIterator;
48+
4749
/////
4850
///// MutableVamanaIndex
4951
/////
@@ -722,12 +724,13 @@ class MutableVamanaIndex {
722724
/// Delete consolidation performs the actual removal of deleted entries from the
723725
/// graph.
724726
///
725-
template <typename T> void delete_entries(const T& ids) {
727+
template <typename T> size_t delete_entries(const T& ids) {
726728
translator_.check_external_exist(ids.begin(), ids.end());
727729
for (auto i : ids) {
728730
delete_entry(translator_.get_internal(i));
729731
}
730732
translator_.delete_external(ids);
733+
return ids.size();
731734
}
732735

733736
void delete_entry(size_t i) {
@@ -1244,6 +1247,14 @@ class MutableVamanaIndex {
12441247
// Call extension for distance computation
12451248
return extensions::get_distance_ext(data_, distance_, internal_id, query);
12461249
}
1250+
1251+
template <typename QueryType>
1252+
auto make_batch_iterator(
1253+
std::span<const QueryType> query,
1254+
size_t extra_search_buffer_capacity = svs::UNSIGNED_INTEGER_PLACEHOLDER
1255+
) const {
1256+
return BatchIterator(*this, query, extra_search_buffer_capacity);
1257+
}
12471258
};
12481259

12491260
///// Deduction Guides.
@@ -1398,4 +1409,4 @@ auto auto_dynamic_assemble(
13981409
std::move(logger)};
13991410
}
14001411

1401-
} // namespace svs::index::vamana
1412+
} // namespace svs::index::vamana

include/svs/index/vamana/index.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848

4949
namespace svs::index::vamana {
5050

51+
template <typename Index, typename QueryType> class BatchIterator;
52+
5153
struct VamanaIndexParameters {
5254
// Members
5355
public:
@@ -887,6 +889,14 @@ class VamanaIndex {
887889
// Call extension for distance computation
888890
return extensions::get_distance_ext(data_, distance_, id, query);
889891
}
892+
893+
template <typename QueryType>
894+
auto make_batch_iterator(
895+
std::span<const QueryType> query,
896+
size_t extra_search_buffer_capacity = svs::UNSIGNED_INTEGER_PLACEHOLDER
897+
) const {
898+
return BatchIterator(*this, query, extra_search_buffer_capacity);
899+
}
890900
};
891901

892902
// Shared documentation for assembly methods.

0 commit comments

Comments
 (0)