Elffuss BraidHub

kikocis/lancedb public

fix: metric type for python/node search api (#1689)

Changesetf371856ec79ab1f844859c3ff3c39ade1ea8ae9f0713194a20b231bd672e5f2f
AuthorQianZhu <qian@lancedb.com> · 2024-09-24 16:10 -07:00
CommitterGitHub <noreply@github.com> · 2024-09-24 16:10 -07:00
Parentsa5725060d170

Browse the files at this changeset

4 files changed

modified node/src/remote/client.ts +4 −1
@@ -17,6 +17,7 @@
1717 import { tableFromIPC, type Table as ArrowTable } from 'apache-arrow'
1818
1919 import { type RemoteResponse, type RemoteRequest, Method } from '../middleware'
20+import { MetricType } from '..'
2021
2122 interface HttpLancedbClientMiddleware {
2223 onRemoteRequest(
@@ -152,6 +153,7 @@
152153 refineFactor?: number,
153154 columns?: string[],
154155 filter?: string,
156+ metricType?: MetricType,
155157 fastSearch?: boolean
156158 ): Promise<ArrowTable<any>> {
157159 const result = await this.post(
@@ -160,10 +162,11 @@
160162 vector,
161163 k,
162164 nprobes,
163- refineFactor,
165+ refine_factor: refineFactor,
164166 columns,
165167 filter,
166168 prefilter,
169+ metric: metricType,
167170 fast_search: fastSearch
168171 },
169172 undefined,
modified node/src/remote/index.ts +1 −0
@@ -239,6 +239,7 @@
239239 (this as any)._refineFactor,
240240 (this as any)._select,
241241 (this as any)._filter,
242+ (this as any)._metricType,
242243 (this as any)._fastSearch
243244 )
244245
modified python/python/lancedb/query.py +3 −3
@@ -576,12 +576,12 @@
576576 self._reranker = None
577577 self._str_query = str_query
578578
579- def metric(self, metric: Literal["L2", "cosine"]) -> LanceVectorQueryBuilder:
579+ def metric(self, metric: Literal["L2", "cosine", "dot"]) -> LanceVectorQueryBuilder:
580580 """Set the distance metric to use.
581581
582582 Parameters
583583 ----------
584- metric: "L2" or "cosine"
584+ metric: "L2" or "cosine" or "dot"
585585 The distance metric to use. By default "L2" is used.
586586
587587 Returns
@@ -589,7 +589,7 @@
589589 LanceVectorQueryBuilder
590590 The LanceQueryBuilder object.
591591 """
592- self._metric = metric
592+ self._metric = metric.lower()
593593 return self
594594
595595 def nprobes(self, nprobes: int) -> LanceVectorQueryBuilder:
modified rust/lancedb/src/lib.rs +1 −0
@@ -228,6 +228,7 @@
228228
229229 #[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
230230 #[non_exhaustive]
231+#[serde(rename_all = "lowercase")]
231232 pub enum DistanceType {
232233 /// Euclidean distance. This is a very common distance metric that
233234 /// accounts for both magnitude and direction when determining the distance