Skip to content

Commit 817dc54

Browse files
author
Nikos Papailiou
committed
Fix segfault in finite ram queries
1 parent cae0cab commit 817dc54

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

apis/python/test/test_ingestion.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def test_ivf_flat_ingestion_u8(tmp_path):
7272
)
7373
assert np.array_equal(np.sort(result, axis=1), np.sort(gt_i, axis=1))
7474

75-
index_ram = IVFFlatIndex(uri=array_uri, dtype=dtype)
75+
index_ram = IVFFlatIndex(uri=array_uri, dtype=dtype, memory_budget=int(size / 10))
7676
result = np.transpose(
7777
index_ram.query(np.transpose(query_vectors), k=k, nprobe=partitions)
7878
)
@@ -114,7 +114,7 @@ def test_ivf_flat_ingestion_f32(tmp_path):
114114
)
115115
assert np.array_equal(np.sort(result, axis=1), np.sort(gt_i, axis=1))
116116

117-
index_ram = IVFFlatIndex(uri=array_uri, dtype=dtype)
117+
index_ram = IVFFlatIndex(uri=array_uri, dtype=dtype, memory_budget=int(size / 10))
118118
result = np.transpose(
119119
index_ram.query(np.transpose(query_vectors), k=k, nprobe=partitions)
120120
)
@@ -159,7 +159,7 @@ def test_ivf_flat_ingestion_fvec(tmp_path):
159159
)
160160
assert np.array_equal(np.sort(result, axis=1), np.sort(gt_i, axis=1))
161161

162-
index_ram = IVFFlatIndex(uri=array_uri, dtype=dtype)
162+
index_ram = IVFFlatIndex(uri=array_uri, dtype=dtype, memory_budget=int(size / 10))
163163
result = np.transpose(
164164
index_ram.query(np.transpose(query_vectors), k=k, nprobe=partitions)
165165
)

src/include/detail/ivf/qv.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -609,16 +609,16 @@ auto nuv_query_heap_finite_ram(
609609
_i.start();
610610

611611
size_t parts_per_thread =
612-
(size(active_partitions) + nthreads - 1) / nthreads;
612+
(shuffled_db.num_col_parts() + nthreads - 1) / nthreads;
613613

614614
std::vector<std::future<void>> futs;
615615
futs.reserve(nthreads);
616616

617617
for (size_t n = 0; n < nthreads; ++n) {
618618
auto first_part =
619-
std::min<size_t>(n * parts_per_thread, size(active_partitions));
619+
std::min<size_t>(n * parts_per_thread, shuffled_db.num_col_parts());
620620
auto last_part =
621-
std::min<size_t>((n + 1) * parts_per_thread, size(active_partitions));
621+
std::min<size_t>((n + 1) * parts_per_thread, shuffled_db.num_col_parts());
622622

623623
if (first_part != last_part) {
624624
futs.emplace_back(std::async(
@@ -794,16 +794,16 @@ auto qv_query_heap_finite_ram(
794794

795795
// size_t block_size = (size(active_partitions) + nthreads - 1) / nthreads;
796796
size_t parts_per_thread =
797-
(size(active_partitions) + nthreads - 1) / nthreads;
797+
(shuffled_db.num_col_parts() + nthreads - 1) / nthreads;
798798

799799
std::vector<std::future<void>> futs;
800800
futs.reserve(nthreads);
801801

802802
for (size_t n = 0; n < nthreads; ++n) {
803803
auto first_part =
804-
std::min<size_t>(n * parts_per_thread, size(active_partitions));
804+
std::min<size_t>(n * parts_per_thread, shuffled_db.num_col_parts());
805805
auto last_part =
806-
std::min<size_t>((n + 1) * parts_per_thread, size(active_partitions));
806+
std::min<size_t>((n + 1) * parts_per_thread, shuffled_db.num_col_parts());
807807

808808
if (first_part != last_part) {
809809
futs.emplace_back(

0 commit comments

Comments
 (0)