Skip to content

Commit 6bb3ce1

Browse files
authored
Rename opt_l to l_search (#411)
1 parent 3323317 commit 6bb3ce1

File tree

7 files changed

+39
-39
lines changed

7 files changed

+39
-39
lines changed

apis/python/src/tiledb/vector_search/type_erased_module.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,13 +341,13 @@ void init_type_erased_module(py::module_& m) {
341341
[](IndexVamana& index,
342342
FeatureVectorArray& vectors,
343343
size_t top_k,
344-
size_t opt_l) {
345-
auto r = index.query(vectors, top_k, opt_l);
344+
size_t l_search) {
345+
auto r = index.query(vectors, top_k, l_search);
346346
return make_python_pair(std::move(r));
347347
},
348348
py::arg("vectors"),
349349
py::arg("top_k"),
350-
py::arg("opt_l"))
350+
py::arg("l_search"))
351351
.def(
352352
"write_index",
353353
[](IndexVamana& index,

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def query_internal(
9797
self,
9898
queries: np.ndarray,
9999
k: int = 10,
100-
opt_l: Optional[int] = 100,
100+
l_search: Optional[int] = 100,
101101
**kwargs,
102102
):
103103
"""
@@ -109,17 +109,17 @@ def query_internal(
109109
2D array of query vectors. This can be used as a batch query interface by passing multiple queries in one call.
110110
k: int
111111
Number of results to return per query vector.
112-
opt_l: int
112+
l_search: int
113113
How deep to search. Should be >= k, and if it's not, we will set it to k.
114114
"""
115115
if self.size == 0:
116116
return np.full((queries.shape[0], k), MAX_FLOAT32), np.full(
117117
(queries.shape[0], k), MAX_UINT64
118118
)
119119

120-
if opt_l < k:
121-
warnings.warn(f"opt_l ({opt_l}) should be >= k ({k}), setting to k")
122-
opt_l = k
120+
if l_search < k:
121+
warnings.warn(f"l_search ({l_search}) should be >= k ({k}), setting to k")
122+
l_search = k
123123

124124
if queries.ndim == 1:
125125
queries = np.array([queries])
@@ -128,7 +128,7 @@ def query_internal(
128128
queries = queries.copy(order="F")
129129
queries_feature_vector_array = vspy.FeatureVectorArray(queries)
130130

131-
distances, ids = self.index.query(queries_feature_vector_array, k, opt_l)
131+
distances, ids = self.index.query(queries_feature_vector_array, k, l_search)
132132

133133
return np.array(distances, copy=False), np.array(ids, copy=False)
134134

apis/python/test/test_ingestion.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,14 +1244,14 @@ def test_ingestion_with_additions_and_timetravel(tmp_path):
12441244

12451245
index_uri = move_local_index_to_new_location(index_uri)
12461246
index = index_class(uri=index_uri)
1247-
_, result = index.query(queries, k=k, nprobe=partitions, opt_l=k * 2)
1247+
_, result = index.query(queries, k=k, nprobe=partitions, l_search=k * 2)
12481248
assert 0.45 < accuracy(result, gt_i)
12491249

12501250
if index_type == "IVF_PQ":
12511251
# TODO(SC-48888): Fix consolidation for IVF_PQ.
12521252
continue
12531253
index = index.consolidate_updates()
1254-
_, result = index.query(queries, k=k, nprobe=partitions, opt_l=k * 2)
1254+
_, result = index.query(queries, k=k, nprobe=partitions, l_search=k * 2)
12551255
assert 0.45 < accuracy(result, gt_i)
12561256

12571257
assert vfs.dir_size(index_uri) > 0

apis/python/test/test_object_index.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def test_object_index(tmp_path):
263263

264264
evaluate_query(
265265
index_uri=index_uri,
266-
query_kwargs={"nprobe": 10, "opt_l": 250},
266+
query_kwargs={"nprobe": 10, "l_search": 250},
267267
dim_id=42,
268268
vector_dim_offset=0,
269269
)
@@ -273,7 +273,7 @@ def test_object_index(tmp_path):
273273
index.update_index(partitions=10)
274274
evaluate_query(
275275
index_uri=index_uri,
276-
query_kwargs={"nprobe": 10, "opt_l": 500},
276+
query_kwargs={"nprobe": 10, "l_search": 500},
277277
dim_id=42,
278278
vector_dim_offset=0,
279279
)
@@ -289,7 +289,7 @@ def test_object_index(tmp_path):
289289
index.update_index(partitions=10)
290290
evaluate_query(
291291
index_uri=index_uri,
292-
query_kwargs={"nprobe": 10, "opt_l": 500},
292+
query_kwargs={"nprobe": 10, "l_search": 500},
293293
dim_id=1042,
294294
vector_dim_offset=0,
295295
)
@@ -305,7 +305,7 @@ def test_object_index(tmp_path):
305305
index.update_index(partitions=10)
306306
evaluate_query(
307307
index_uri=index_uri,
308-
query_kwargs={"nprobe": 10, "opt_l": 500},
308+
query_kwargs={"nprobe": 10, "l_search": 500},
309309
dim_id=2042,
310310
vector_dim_offset=1000,
311311
)

apis/python/test/test_type_erased_module.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def test_construct_IndexVamana():
285285

286286

287287
def test_construct_IndexVamana_with_empty_vector(tmp_path):
288-
opt_l = 100
288+
l_search = 100
289289
k_nn = 10
290290
index_uri = os.path.join(tmp_path, "array")
291291
dimensions = 128
@@ -313,7 +313,7 @@ def test_construct_IndexVamana_with_empty_vector(tmp_path):
313313

314314
a.train(training_set)
315315

316-
s, t = a.query(query_set, k_nn, opt_l)
316+
s, t = a.query(query_set, k_nn, l_search)
317317

318318
intersections = vspy.count_intersections(t, groundtruth_set, k_nn)
319319
nt = np.double(t.num_vectors()) * np.double(k_nn)
@@ -322,7 +322,7 @@ def test_construct_IndexVamana_with_empty_vector(tmp_path):
322322

323323

324324
def test_inplace_build_query_IndexVamana():
325-
opt_l = 100
325+
l_search = 100
326326
k_nn = 10
327327

328328
a = vspy.IndexVamana(id_type="uint32", feature_type="float32")
@@ -335,7 +335,7 @@ def test_inplace_build_query_IndexVamana():
335335
assert groundtruth_set.feature_type_string() == "uint64"
336336

337337
a.train(training_set)
338-
s, t = a.query(query_set, k_nn, opt_l)
338+
s, t = a.query(query_set, k_nn, l_search)
339339

340340
intersections = vspy.count_intersections(t, groundtruth_set, k_nn)
341341

src/include/api/vamana_index.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,11 @@ class IndexVamana {
217217
[[nodiscard]] auto query(
218218
const QueryVectorArray& vectors,
219219
size_t top_k,
220-
std::optional<size_t> opt_L = std::nullopt) {
220+
std::optional<size_t> l_search = std::nullopt) {
221221
if (!index_) {
222222
throw std::runtime_error("Cannot query() because there is no index.");
223223
}
224-
return index_->query(vectors, top_k, opt_L);
224+
return index_->query(vectors, top_k, l_search);
225225
}
226226

227227
void write_index(
@@ -337,7 +337,7 @@ class IndexVamana {
337337
query(
338338
const QueryVectorArray& vectors,
339339
size_t top_k,
340-
std::optional<size_t> opt_L) = 0;
340+
std::optional<size_t> l_search) = 0;
341341

342342
virtual void write_index(
343343
const tiledb::Context& ctx,
@@ -424,7 +424,7 @@ class IndexVamana {
424424
[[nodiscard]] std::tuple<FeatureVectorArray, FeatureVectorArray> query(
425425
const QueryVectorArray& vectors,
426426
size_t top_k,
427-
std::optional<size_t> opt_L) override {
427+
std::optional<size_t> l_search) override {
428428
// @todo using index_type = size_t;
429429
auto dtype = vectors.feature_type();
430430

@@ -435,7 +435,7 @@ class IndexVamana {
435435
(float*)vectors.data(),
436436
extents(vectors)[0],
437437
extents(vectors)[1]}; // @todo ??
438-
auto [s, t] = impl_index_.query(qspan, top_k, opt_L);
438+
auto [s, t] = impl_index_.query(qspan, top_k, l_search);
439439
auto x = FeatureVectorArray{std::move(s)};
440440
auto y = FeatureVectorArray{std::move(t)};
441441
return {std::move(x), std::move(y)};
@@ -445,7 +445,7 @@ class IndexVamana {
445445
(uint8_t*)vectors.data(),
446446
extents(vectors)[0],
447447
extents(vectors)[1]}; // @todo ??
448-
auto [s, t] = impl_index_.query(qspan, top_k, opt_L);
448+
auto [s, t] = impl_index_.query(qspan, top_k, l_search);
449449
auto x = FeatureVectorArray{std::move(s)};
450450
auto y = FeatureVectorArray{std::move(t)};
451451
return {std::move(x), std::move(y)};

src/include/index/vamana_index.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,8 @@ class vamana_index {
467467

468468
template <query_vector_array Q>
469469
auto best_first_O2(
470-
const Q& queries, size_t k_nn, std::optional<size_t> opt_L) {
471-
size_t Lbuild = opt_L ? *opt_L : l_build_;
470+
const Q& queries, size_t k_nn, std::optional<size_t> l_search) {
471+
size_t Lbuild = l_search ? *l_search : l_build_;
472472

473473
auto top_k = ColMajorMatrix<id_type>(k_nn, ::num_vectors(queries));
474474
auto top_k_scores =
@@ -494,8 +494,8 @@ class vamana_index {
494494

495495
template <query_vector_array Q>
496496
auto best_first_O3(
497-
const Q& queries, size_t k_nn, std::optional<size_t> opt_L) {
498-
size_t Lbuild = opt_L ? *opt_L : l_build_;
497+
const Q& queries, size_t k_nn, std::optional<size_t> l_search) {
498+
size_t Lbuild = l_search ? *l_search : l_build_;
499499

500500
auto top_k = ColMajorMatrix<id_type>(k_nn, ::num_vectors(queries));
501501
auto top_k_scores =
@@ -521,8 +521,8 @@ class vamana_index {
521521

522522
template <query_vector_array Q>
523523
auto best_first_O4(
524-
const Q& queries, size_t k_nn, std::optional<size_t> opt_L) {
525-
size_t Lbuild = opt_L ? *opt_L : l_build_;
524+
const Q& queries, size_t k_nn, std::optional<size_t> l_search) {
525+
size_t Lbuild = l_search ? *l_search : l_build_;
526526

527527
auto top_k = ColMajorMatrix<id_type>(k_nn, ::num_vectors(queries));
528528
auto top_k_scores =
@@ -548,8 +548,8 @@ class vamana_index {
548548

549549
template <query_vector_array Q>
550550
auto best_first_O5(
551-
const Q& queries, size_t k_nn, std::optional<size_t> opt_L) {
552-
size_t Lbuild = opt_L ? *opt_L : l_build_;
551+
const Q& queries, size_t k_nn, std::optional<size_t> l_search) {
552+
size_t Lbuild = l_search ? *l_search : l_build_;
553553

554554
auto top_k = ColMajorMatrix<id_type>(k_nn, ::num_vectors(queries));
555555
auto top_k_scores =
@@ -578,18 +578,18 @@ class vamana_index {
578578
* @tparam Q Type of query set
579579
* @param query_set Container of query vectors
580580
* @param k How many nearest neighbors to return
581-
* @param opt_L How deep to search
581+
* @param l_search How deep to search
582582
* @return Tuple of top k scores and top k ids
583583
*/
584584
template <query_vector_array Q, class Distance = sum_of_squares_distance>
585585
auto query(
586586
const Q& query_set,
587587
size_t k,
588-
std::optional<size_t> opt_L = std::nullopt,
588+
std::optional<size_t> l_search = std::nullopt,
589589
Distance distance = Distance{}) {
590590
scoped_timer __{tdb_func__ + std::string{" (outer)"}};
591591

592-
size_t L = opt_L ? *opt_L : l_build_;
592+
size_t L = l_search ? *l_search : l_build_;
593593
// L = std::min<size_t>(L, l_build_);
594594

595595
auto top_k = ColMajorMatrix<id_type>(k, ::num_vectors(query_set));
@@ -646,16 +646,16 @@ class vamana_index {
646646
* @tparam Q Type of query vector
647647
* @param query_vec The vector to query
648648
* @param k How many nearest neighbors to return
649-
* @param opt_L How deep to search
649+
* @param l_search How deep to search
650650
* @return Top k scores and top k ids
651651
*/
652652
template <query_vector Q, class Distance = sum_of_squares_distance>
653653
auto query(
654654
const Q& query_vec,
655655
size_t k,
656-
std::optional<size_t> opt_L = std::nullopt,
656+
std::optional<size_t> l_search = std::nullopt,
657657
Distance distance = Distance{}) {
658-
size_t L = opt_L ? *opt_L : l_build_;
658+
size_t L = l_search ? *l_search : l_build_;
659659
auto&& [top_k_scores, top_k, V] = greedy_search(
660660
graph_, feature_vectors_, medoid_, query_vec, k, L, distance, true);
661661

0 commit comments

Comments
 (0)