Skip to content

Commit edd3763

Browse files
authored
Add Vamana backwards compatibility data generation and tests (#409)
1 parent 241e504 commit edd3763

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

apis/python/src/tiledb/vector_search/ivf_pq_index.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ def create(
163163
"""
164164
warnings.warn("The IVF PQ index is not yet supported, please use with caution.")
165165
validate_storage_version(storage_version)
166+
# TODO(SC-49166): Support old storage versions with type-erased indexes.
167+
if storage_version == "0.1" or storage_version == "0.2":
168+
raise ValueError(
169+
f"Storage version {storage_version} is not supported for IVFPQIndex. IVFPQIndex requires storage version 0.3 or higher."
170+
)
166171
ctx = vspy.Ctx(config)
167172
if num_subspaces <= 0:
168173
raise ValueError(

apis/python/src/tiledb/vector_search/vamana_index.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ def create(
159159
If not provided, use the latest stable storage version.
160160
"""
161161
validate_storage_version(storage_version)
162+
# TODO(SC-49166): Support old storage versions with type-erased indexes.
163+
if storage_version == "0.1" or storage_version == "0.2":
164+
raise ValueError(
165+
f"Storage version {storage_version} is not supported for VamanaIndex. VamanaIndex requires storage version 0.3 or higher."
166+
)
162167
ctx = vspy.Ctx(config)
163168
index = vspy.IndexVamana(
164169
feature_type=np.dtype(vector_type).name,

apis/python/test/test_backwards_compatibility.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from tiledb.vector_search.flat_index import FlatIndex
44
from tiledb.vector_search.ivf_flat_index import IVFFlatIndex
55
from tiledb.vector_search.utils import load_fvecs
6+
from tiledb.vector_search.vamana_index import VamanaIndex
67

78
MINIMUM_ACCURACY = 0.85
89

@@ -60,6 +61,8 @@ def test_query_old_indices():
6061
index = IVFFlatIndex(uri=index_uri)
6162
elif "flat" in index_name:
6263
index = FlatIndex(uri=index_uri)
64+
elif "vamana" in index_name:
65+
index = VamanaIndex(uri=index_uri)
6366
else:
6467
assert False, f"Unknown index name: {index_name}"
6568

backwards-compatibility-data/generate_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def generate_indexes(version):
6666
queries = base[indices]
6767

6868
# Generate each index and query to make sure it works before we write it.
69-
index_types = ["FLAT", "IVF_FLAT"]
69+
index_types = ["FLAT", "IVF_FLAT", "VAMANA"]
7070
data_types = ["float32", "uint8"]
7171
for index_type in index_types:
7272
for data_type in data_types:

src/include/test/unit_backwards_compatibility.cc

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,26 @@ TEST_CASE("test_query_old_indices", "[backwards_compatibility]") {
118118
// TODO(paris): Fix flat_l2_index and re-enable. Right now it just tries
119119
// to load the URI as a tdbMatrix.
120120
} else if (index_uri.find("vamana") != std::string::npos) {
121-
// TODO(paris): Add once we save a vamana index in backwards
122-
// compatibility data.
121+
// First check that we can query the index.
122+
auto index = IndexVamana(ctx, index_uri);
123+
auto&& [scores, ids] = index.query(queries_feature_vector_array, 1);
124+
auto scores_span =
125+
MatrixView<siftsmall_feature_type, stdx::layout_left>{
126+
(siftsmall_feature_type*)scores.data(),
127+
extents(scores)[0],
128+
extents(scores)[1]};
129+
130+
auto ids_span = MatrixView<siftsmall_ids_type, stdx::layout_left>{
131+
(siftsmall_ids_type*)ids.data(), extents(ids)[0], extents(ids)[1]};
132+
133+
for (size_t i = 0; i < query_indices.size(); ++i) {
134+
CHECK(ids_span[0][i] == query_indices[i]);
135+
CHECK(scores_span[0][i] == 0);
136+
}
137+
138+
// Next check that we can load the metadata.
139+
auto metadata = vamana_index_metadata();
140+
metadata.load_metadata(read_group);
123141
} else {
124142
REQUIRE(false);
125143
}

0 commit comments

Comments
 (0)