From d5021356b417078cbed5f9a6af604d334a9529b3 Mon Sep 17 00:00:00 2001 From: Bert Date: Tue, 24 Sep 2024 13:28:54 -0300 Subject: [PATCH] feat: add fast_search to vectordb (#1693) --- node/src/query.ts | 11 +++++++++++ node/src/remote/client.ts | 6 ++++-- node/src/remote/index.ts | 3 ++- rust/ffi/node/src/query.rs | 7 +++++++ 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/node/src/query.ts b/node/src/query.ts index 2338c051..4c4e0216 100644 --- a/node/src/query.ts +++ b/node/src/query.ts @@ -33,6 +33,7 @@ export class Query { private _filter?: string private _metricType?: MetricType private _prefilter: boolean + private _fastSearch: boolean protected readonly _embeddings?: EmbeddingFunction constructor (query?: T, tbl?: any, embeddings?: EmbeddingFunction) { @@ -46,6 +47,7 @@ export class Query { this._metricType = undefined this._embeddings = embeddings this._prefilter = false + this._fastSearch = false } /*** @@ -110,6 +112,15 @@ export class Query { return this } + /** + * Skip searching un-indexed data. This can make search faster, but will miss + * any data that is not yet indexed. + */ + fastSearch (value: boolean): Query { + this._fastSearch = value + return this + } + /** * Execute the query and return the results as an Array of Objects */ diff --git a/node/src/remote/client.ts b/node/src/remote/client.ts index 27e1c039..dbd30893 100644 --- a/node/src/remote/client.ts +++ b/node/src/remote/client.ts @@ -151,7 +151,8 @@ export class HttpLancedbClient { prefilter: boolean, refineFactor?: number, columns?: string[], - filter?: string + filter?: string, + fastSearch?: boolean ): Promise> { const result = await this.post( `/v1/table/${tableName}/query/`, @@ -162,7 +163,8 @@ export class HttpLancedbClient { refineFactor, columns, filter, - prefilter + prefilter, + fast_search: fastSearch }, undefined, undefined, diff --git a/node/src/remote/index.ts b/node/src/remote/index.ts index 11e20a2f..38bc7a78 100644 --- a/node/src/remote/index.ts +++ b/node/src/remote/index.ts @@ -238,7 +238,8 @@ export class RemoteQuery extends Query { (this as any)._prefilter, (this as any)._refineFactor, (this as any)._select, - (this as any)._filter + (this as any)._filter, + (this as any)._fastSearch ) return data.toArray().map((entry: Record) => { diff --git a/rust/ffi/node/src/query.rs b/rust/ffi/node/src/query.rs index 7ec5a375..5aec3d3b 100644 --- a/rust/ffi/node/src/query.rs +++ b/rust/ffi/node/src/query.rs @@ -46,6 +46,10 @@ impl JsQuery { .get::(&mut cx, "_prefilter")? .value(&mut cx); + let fast_search = query_obj + .get_opt::(&mut cx, "_fastSearch")? + .map(|val| val.value(&mut cx)); + let is_electron = cx .argument::(1) .or_throw(&mut cx)? @@ -70,6 +74,9 @@ impl JsQuery { if let Some(limit) = limit { builder = builder.limit(limit as usize); }; + if let Some(true) = fast_search { + builder = builder.fast_search(); + } let query_vector = query_obj.get_opt::(&mut cx, "_queryVector")?; if let Some(query) = query_vector.map(|q| convert::js_array_to_vec(q.deref(), &mut cx)) {