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:
Leo
2026-11-03 12:45:52 +08:00
committed by GitHub
co-authored by Leo
parent f9389f113e
commit f2bcb156ad
13 changed files with 326 additions and 12 deletions
+17
View File
@@ -1626,6 +1626,23 @@ describe("When creating an index", () => {
// test ef
rst = await tbl.query().limit(2).nearestTo(queryVec).ef(100).toArrow();
expect(rst.numRows).toBe(2);
// test approxMode
for (const mode of ["fast", "normal", "accurate"] as const) {
rst = await tbl
.query()
.limit(2)
.nearestTo(queryVec)
.approxMode(mode)
.toArrow();
expect(rst.numRows).toBe(2);
}
expect(() =>
tbl
.query()
.nearestTo(queryVec)
.approxMode("turbo" as "fast"),
).toThrow("approx_mode must be one of");
});
it("should be able to query unindexed data", async () => {
+21
View File
@@ -926,6 +926,27 @@ export class VectorQuery extends StandardQueryBase<NativeVectorQuery> {
return this;
}
/**
* Set the speed / accuracy tradeoff to use for approximate search
*
* This currently affects RQ-quantized indexes, such as IVF_RQ, and
* prefiltered search on HNSW indexes, where "fast" enables the ACORN
* traversal. Other index types ignore this setting.
*
* "fast" favors lower latency and may reduce recall, "normal" (the default)
* uses the index's default balance, and "accurate" favors higher recall and
* may increase latency.
*
* @example
* ```ts
* table.vectorSearch([0.1, 0.2]).approxMode("fast").limit(10);
* ```
*/
approxMode(approxMode: "fast" | "normal" | "accurate"): VectorQuery {
super.doCall((inner) => inner.approxMode(approxMode));
return this;
}
/**
* Set the vector column to query
*
+8
View File
@@ -15,6 +15,7 @@ use arrow_array::{
};
use arrow_buffer::ScalarBuffer;
use half::f16;
use lancedb::ApproxMode;
use lancedb::index::scalar::{
BooleanQuery, BoostQuery, FtsQuery, FullTextSearchQuery, MatchQuery, MultiMatchQuery, Occur,
Operator, PhraseQuery,
@@ -352,6 +353,13 @@ impl VectorQuery {
self.inner = self.inner.clone().ef(ef as usize);
}
#[napi]
pub fn approx_mode(&mut self, approx_mode: String) -> napi::Result<()> {
let approx_mode = ApproxMode::try_from(approx_mode.as_str()).default_error()?;
self.inner = self.inner.clone().approx_mode(approx_mode);
Ok(())
}
#[napi]
pub fn bypass_vector_index(&mut self) {
self.inner = self.inner.clone().bypass_vector_index()