Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: low recall if the num partitions is more than num rows #2386

Merged
merged 1 commit into from
May 23, 2024
Merged
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
2 changes: 1 addition & 1 deletion rust/lance/src/index/vector/ivf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2710,7 +2710,7 @@ mod tests {

let recall = results_set.intersection(&gt_set).count() as f32 / k as f32;
assert!(
recall >= 0.7,
recall >= 0.9,
"recall: {}\n results: {:?}\n\ngt: {:?}",
recall,
results,
Expand Down
15 changes: 8 additions & 7 deletions rust/lance/src/index/vector/ivf/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,10 @@ pub(super) async fn write_hnsw_quantization_index_partitions(
let mut aux_ivf = IvfData::empty();
let mut hnsw_metadata = Vec::with_capacity(ivf.num_partitions());
for (part_id, task) in tasks.into_iter().enumerate() {
let offset = writer.tell().await?;
let length = task.await??;
let offset = writer.len();
let num_rows = task.await??;

if length == 0 {
if num_rows == 0 {
ivf.add_partition(offset, 0);
aux_ivf.add_partition(0);
hnsw_metadata.push(HnswMetadata::default());
Expand All @@ -412,7 +412,8 @@ pub(super) async fn write_hnsw_quantization_index_partitions(
.try_collect::<Vec<_>>()
.await?;
writer.write(&batches).await?;
ivf.add_partition(offset, length as u32);

ivf.add_partition(offset, (writer.len() - offset) as u32);
hnsw_metadata.push(serde_json::from_str(
part_reader.schema().metadata[HNSW_METADATA_KEY].as_str(),
)?);
Expand All @@ -438,7 +439,6 @@ pub(super) async fn write_hnsw_quantization_index_partitions(
std::mem::drop(aux_part_reader);
object_store.delete(aux_part_file).await?;

let num_rows: usize = batches.iter().map(|b| b.num_rows()).sum();
aux_writer.write(&batches).await?;
aux_ivf.add_partition(num_rows as u32);
}
Expand All @@ -462,6 +462,7 @@ async fn build_hnsw_quantization_partition(
let row_ids_arrs = row_ids_array.iter().map(|a| a.as_ref()).collect::<Vec<_>>();
let row_ids = concat(&row_ids_arrs)?;
std::mem::drop(row_ids_array);
let num_rows = row_ids.len();

let projection = Arc::new(dataset.schema().project(&[column.as_ref()])?);
let mut vectors = dataset
Expand Down Expand Up @@ -499,8 +500,8 @@ async fn build_hnsw_quantization_partition(
)),
};

let (length, _) = futures::join!(build_hnsw, build_store);
length
futures::join!(build_hnsw, build_store).0?;
Ok(num_rows)
}

async fn build_and_write_hnsw(
Expand Down
Loading