Skip to content

Commit 52b27c7

Browse files
committed
fix hamming
Signed-off-by: BubbleCal <bubble-cal@outlook.com>
1 parent b10f1e5 commit 52b27c7

File tree

1 file changed

+38
-17
lines changed
  • rust/lance/src/index/vector

1 file changed

+38
-17
lines changed

rust/lance/src/index/vector/ivf.rs

+38-17
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use lance_file::{
3636
format::MAGIC,
3737
writer::{FileWriter, FileWriterOptions},
3838
};
39-
use lance_index::vector::flat::index::{FlatIndex, FlatQuantizer};
39+
use lance_index::vector::flat::index::{FlatBinQuantizer, FlatIndex, FlatQuantizer};
4040
use lance_index::vector::ivf::storage::IvfModel;
4141
use lance_index::vector::pq::storage::transpose;
4242
use lance_index::vector::quantizer::QuantizationType;
@@ -402,25 +402,46 @@ pub(crate) async fn optimize_vector_indices_v2(
402402
};
403403
let indices_to_merge = existing_indices[start_pos..].to_vec();
404404
let merged_num = indices_to_merge.len();
405+
406+
let (_, element_type) = get_vector_type(dataset.schema(), vector_column)?;
405407
match index_type {
406408
// IVF_FLAT
407409
(SubIndexType::Flat, QuantizationType::Flat) => {
408-
IvfIndexBuilder::<FlatIndex, FlatQuantizer>::new_incremental(
409-
dataset.clone(),
410-
vector_column.to_owned(),
411-
index_dir,
412-
distance_type,
413-
shuffler,
414-
(),
415-
)?
416-
.with_ivf(ivf_model.clone())
417-
.with_quantizer(quantizer.try_into()?)
418-
.with_existing_indices(indices_to_merge)
419-
.retrain(retrain)
420-
.shuffle_data(unindexed)
421-
.await?
422-
.build()
423-
.await?;
410+
if element_type == DataType::UInt8 {
411+
IvfIndexBuilder::<FlatIndex, FlatBinQuantizer>::new_incremental(
412+
dataset.clone(),
413+
vector_column.to_owned(),
414+
index_dir,
415+
distance_type,
416+
shuffler,
417+
(),
418+
)?
419+
.with_ivf(ivf_model.clone())
420+
.with_quantizer(quantizer.try_into()?)
421+
.with_existing_indices(indices_to_merge)
422+
.retrain(retrain)
423+
.shuffle_data(unindexed)
424+
.await?
425+
.build()
426+
.await?;
427+
} else {
428+
IvfIndexBuilder::<FlatIndex, FlatQuantizer>::new_incremental(
429+
dataset.clone(),
430+
vector_column.to_owned(),
431+
index_dir,
432+
distance_type,
433+
shuffler,
434+
(),
435+
)?
436+
.with_ivf(ivf_model.clone())
437+
.with_quantizer(quantizer.try_into()?)
438+
.with_existing_indices(indices_to_merge)
439+
.retrain(retrain)
440+
.shuffle_data(unindexed)
441+
.await?
442+
.build()
443+
.await?;
444+
}
424445
}
425446
// IVF_PQ
426447
(SubIndexType::Flat, QuantizationType::Product) => {

0 commit comments

Comments
 (0)