mirror of
https://github.com/lancedb/lancedb.git
synced 2026-11-13 14:16:54 +00:00
feat: expose approx_mode on vector queries
`ApproxMode` landed in the Rust core in #3549, but the Python and Node.js bindings were never plumbed, so `approx_mode` is unreachable from either SDK. Both were built mirroring the existing `ef` plumbing. Co-authored-by: Leo <leo@insight.co>
This commit is contained in:
@@ -16,6 +16,7 @@ use arrow::array::make_array;
|
||||
use arrow::pyarrow::FromPyArrow;
|
||||
use arrow::pyarrow::IntoPyArrow;
|
||||
use arrow::pyarrow::ToPyArrow;
|
||||
use lancedb::ApproxMode;
|
||||
use lancedb::index::scalar::{
|
||||
BooleanQuery, BoostQuery, CombinedFieldsQuery, DocumentGranularity, FtsQuery,
|
||||
FullTextSearchQuery, MatchQuery, MultiMatchQuery, Occur, Operator, PhraseQuery,
|
||||
@@ -370,6 +371,7 @@ pub struct PyQueryRequest {
|
||||
pub lower_bound: Option<f32>,
|
||||
pub upper_bound: Option<f32>,
|
||||
pub ef: Option<usize>,
|
||||
pub approx_mode: Option<String>,
|
||||
pub refine_factor: Option<u32>,
|
||||
pub distance_type: Option<String>,
|
||||
pub bypass_vector_index: Option<bool>,
|
||||
@@ -403,6 +405,7 @@ impl From<AnyQuery> for PyQueryRequest {
|
||||
lower_bound: None,
|
||||
upper_bound: None,
|
||||
ef: None,
|
||||
approx_mode: None,
|
||||
refine_factor: None,
|
||||
distance_type: None,
|
||||
bypass_vector_index: None,
|
||||
@@ -432,6 +435,7 @@ impl From<AnyQuery> for PyQueryRequest {
|
||||
lower_bound: vector_query.lower_bound,
|
||||
upper_bound: vector_query.upper_bound,
|
||||
ef: vector_query.ef,
|
||||
approx_mode: vector_query.approx_mode.map(|m| m.to_string()),
|
||||
refine_factor: vector_query.refine_factor,
|
||||
distance_type: vector_query.distance_type.map(|d| d.to_string()),
|
||||
bypass_vector_index: Some(!vector_query.use_index),
|
||||
@@ -1069,6 +1073,12 @@ impl VectorQuery {
|
||||
self.inner = self.inner.clone().ef(ef as usize);
|
||||
}
|
||||
|
||||
pub fn approx_mode(&mut self, approx_mode: String) -> PyResult<()> {
|
||||
let approx_mode = ApproxMode::try_from(approx_mode.as_str()).infer_error()?;
|
||||
self.inner = self.inner.clone().approx_mode(approx_mode);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn bypass_vector_index(&mut self) {
|
||||
self.inner = self.inner.clone().bypass_vector_index()
|
||||
}
|
||||
@@ -1246,6 +1256,10 @@ impl HybridQuery {
|
||||
self.inner_vec.ef(ef);
|
||||
}
|
||||
|
||||
pub fn approx_mode(&mut self, approx_mode: String) -> PyResult<()> {
|
||||
self.inner_vec.approx_mode(approx_mode)
|
||||
}
|
||||
|
||||
pub fn bypass_vector_index(&mut self) {
|
||||
self.inner_vec.bypass_vector_index();
|
||||
}
|
||||
@@ -1291,6 +1305,7 @@ impl HybridQuery {
|
||||
req.maximum_nprobes = vec_req.maximum_nprobes;
|
||||
req.search_effort = vec_req.search_effort;
|
||||
req.ef = vec_req.ef;
|
||||
req.approx_mode = vec_req.approx_mode;
|
||||
req.refine_factor = vec_req.refine_factor;
|
||||
req.lower_bound = vec_req.lower_bound;
|
||||
req.upper_bound = vec_req.upper_bound;
|
||||
|
||||
Reference in New Issue
Block a user