From 1beef5f6e3df0e87e78ca88b783d1966b314163b Mon Sep 17 00:00:00 2001 From: BubbleCal Date: Mon, 29 Sep 2025 17:08:12 +0800 Subject: [PATCH] fix Signed-off-by: BubbleCal --- nodejs/src/index.rs | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/nodejs/src/index.rs b/nodejs/src/index.rs index 37b775f6..b5dce075 100644 --- a/nodejs/src/index.rs +++ b/nodejs/src/index.rs @@ -5,7 +5,7 @@ use std::sync::Mutex; use lancedb::index::scalar::{BTreeIndexBuilder, FtsIndexBuilder}; use lancedb::index::vector::{ - IvfFlatIndexBuilder, IvfHnswPqIndexBuilder, IvfHnswSqIndexBuilder, IvfPqIndexBuilder, + IvfFlatIndexBuilder, IvfHnswPqIndexBuilder, IvfHnswSqIndexBuilder, IvfPqIndexBuilder, IvfRqIndexBuilder, }; use lancedb::index::Index as LanceDbIndex; use napi_derive::napi; @@ -65,6 +65,36 @@ impl Index { }) } + #[napi(factory)] + pub fn ivf_rq( + distance_type: Option, + num_partitions: Option, + num_bits: Option, + max_iterations: Option, + sample_rate: Option, + ) -> napi::Result { + let mut ivf_rq_builder = IvfRqIndexBuilder::default(); + if let Some(distance_type) = distance_type { + let distance_type = parse_distance_type(distance_type)?; + ivf_rq_builder = ivf_rq_builder.distance_type(distance_type); + } + if let Some(num_partitions) = num_partitions { + ivf_rq_builder = ivf_rq_builder.num_partitions(num_partitions); + } + if let Some(num_bits) = num_bits { + ivf_rq_builder = ivf_rq_builder.num_bits(num_bits); + } + if let Some(max_iterations) = max_iterations { + ivf_rq_builder = ivf_rq_builder.max_iterations(max_iterations); + } + if let Some(sample_rate) = sample_rate { + ivf_rq_builder = ivf_rq_builder.sample_rate(sample_rate); + } + Ok(Self { + inner: Mutex::new(Some(LanceDbIndex::IvfRq(ivf_rq_builder))), + }) + } + #[napi(factory)] pub fn ivf_flat( distance_type: Option,