Compare commits

...

2 Commits

Author SHA1 Message Date
Xuanwo
a8f57e8043 Format code
Signed-off-by: Xuanwo <github@xuanwo.io>
2025-09-09 01:08:02 +08:00
Xuanwo
c36409d3b8 feat: Expose disableScoringAutoprojection to lancedb
Signed-off-by: Xuanwo <github@xuanwo.io>
2025-09-09 01:06:29 +08:00
5 changed files with 53 additions and 0 deletions

View File

@@ -363,6 +363,23 @@ export class StandardQueryBase<
return this.where(predicate); return this.where(predicate);
} }
/**
* Disable autoprojection of scoring columns.
*
* When you specify an explicit projection with {@link select} that does not
* include scoring columns (e.g. `_score` for FTS or `_distance` for vector
* search), Lance currently auto-includes those columns and emits a
* deprecation warning. Calling this method disables that behavior so the
* scoring columns are only returned if explicitly selected.
*/
disableScoringAutoprojection(): this {
this.doCall((inner: NativeQueryType) => {
// @ts-expect-error method is present on Query and VectorQuery only
inner.disableScoringAutoprojection();
});
return this;
}
fullTextSearch( fullTextSearch(
query: string | FullTextQuery, query: string | FullTextQuery,
options?: Partial<FullTextSearchOptions>, options?: Partial<FullTextSearchOptions>,

View File

@@ -88,6 +88,11 @@ impl Query {
self.inner = self.inner.clone().with_row_id(); self.inner = self.inner.clone().with_row_id();
} }
#[napi]
pub fn disable_scoring_autoprojection(&mut self) {
self.inner = self.inner.clone().disable_scoring_autoprojection();
}
#[napi(catch_unwind)] #[napi(catch_unwind)]
pub async fn execute( pub async fn execute(
&self, &self,
@@ -265,6 +270,11 @@ impl VectorQuery {
self.inner = self.inner.clone().with_row_id(); self.inner = self.inner.clone().with_row_id();
} }
#[napi]
pub fn disable_scoring_autoprojection(&mut self) {
self.inner = self.inner.clone().disable_scoring_autoprojection();
}
#[napi] #[napi]
pub fn rerank(&mut self, callbacks: RerankerCallbacks) { pub fn rerank(&mut self, callbacks: RerankerCallbacks) {
self.inner = self self.inner = self

View File

@@ -448,6 +448,15 @@ pub trait QueryBase {
/// the scores are converted to ranks and then normalized. If "Score", the /// the scores are converted to ranks and then normalized. If "Score", the
/// scores are normalized directly. /// scores are normalized directly.
fn norm(self, norm: NormalizeMethod) -> Self; fn norm(self, norm: NormalizeMethod) -> Self;
/// Disable autoprojection of scoring columns.
///
/// When an explicit projection is provided that does not include scoring
/// columns (e.g. `_score` for FTS or `_distance` for vector search), the
/// current default behavior is to auto-include those columns and emit a
/// deprecation warning. Calling this adopts the future behavior and avoids
/// the warning.
fn disable_scoring_autoprojection(self) -> Self;
} }
pub trait HasQuery { pub trait HasQuery {
@@ -507,6 +516,11 @@ impl<T: HasQuery> QueryBase for T {
self.mut_query().norm = Some(norm); self.mut_query().norm = Some(norm);
self self
} }
fn disable_scoring_autoprojection(mut self) -> Self {
self.mut_query().disable_scoring_autoprojection = true;
self
}
} }
/// Options for controlling the execution of a query /// Options for controlling the execution of a query
@@ -645,6 +659,10 @@ pub struct QueryRequest {
/// Configure how query results are normalized when doing hybrid search /// Configure how query results are normalized when doing hybrid search
pub norm: Option<NormalizeMethod>, pub norm: Option<NormalizeMethod>,
/// If true, do not auto-include scoring columns when they are
/// omitted from an explicit projection.
pub disable_scoring_autoprojection: bool,
} }
impl Default for QueryRequest { impl Default for QueryRequest {
@@ -660,6 +678,7 @@ impl Default for QueryRequest {
prefilter: true, prefilter: true,
reranker: None, reranker: None,
norm: None, norm: None,
disable_scoring_autoprojection: false,
} }
} }
} }

View File

@@ -372,6 +372,9 @@ impl<S: HttpSend> RemoteTable<S> {
params: &QueryRequest, params: &QueryRequest,
) -> Result<()> { ) -> Result<()> {
body["prefilter"] = params.prefilter.into(); body["prefilter"] = params.prefilter.into();
if params.disable_scoring_autoprojection {
body["disable_scoring_autoprojection"] = serde_json::Value::Bool(true);
}
if let Some(offset) = params.offset { if let Some(offset) = params.offset {
body["offset"] = serde_json::Value::Number(serde_json::Number::from(offset)); body["offset"] = serde_json::Value::Number(serde_json::Number::from(offset));
} }

View File

@@ -2331,6 +2331,10 @@ impl BaseTable for NativeTable {
scanner.full_text_search(fts.clone())?; scanner.full_text_search(fts.clone())?;
} }
if query.base.disable_scoring_autoprojection {
scanner.disable_scoring_autoprojection();
}
if let Some(refine_factor) = query.refine_factor { if let Some(refine_factor) = query.refine_factor {
scanner.refine(refine_factor); scanner.refine(refine_factor);
} }