Elffuss BraidHub

kikocis/lancedb public

feat: allow fast_search on python remote table (#1747)

Add `fast_search` parameter to query builder and remote table to support
skipping flat search in remote search
Changeset51a5b30d4bbd34033f1a7c0f0deba88dc56994eaf32e6a7a36e98c1f90665a09
AuthorRyan Green <ryang@ryang.ca> · 2024-10-14 14:39 -06:00
CommitterGitHub <noreply@github.com> · 2024-10-14 14:39 -06:00
Parentsaba9e2e83ce6

Browse the files at this changeset

3 files changed

modified python/python/lancedb/query.py +16 −1
@@ -88,6 +88,11 @@
8888 tuning advice.
8989 offset: int
9090 The offset to start fetching results from
91+ fast_search: bool
92+ Skip a flat search of unindexed data. This will improve
93+ search performance but search results will not include unindexed data.
94+
95+ - *default False*.
9196 """
9297
9398 vector_column: Optional[str] = None
@@ -124,6 +129,8 @@
124129
125130 offset: int = 0
126131
132+ fast_search: bool = False
133+
127134
128135 class LanceQueryBuilder(ABC):
129136 """An abstract query builder. Subclasses are defined for vector search,
@@ -139,6 +146,7 @@
139146 vector_column_name: str,
140147 ordering_field_name: Optional[str] = None,
141148 fts_columns: Union[str, List[str]] = [],
149+ fast_search: bool = False,
142150 ) -> LanceQueryBuilder:
143151 """
144152 Create a query builder based on the given query and query type.
@@ -155,6 +163,8 @@
155163 If "auto", the query type is inferred based on the query.
156164 vector_column_name: str
157165 The name of the vector column to use for vector search.
166+ fast_search: bool
167+ Skip flat search of unindexed data.
158168 """
159169 # Check hybrid search first as it supports empty query pattern
160170 if query_type == "hybrid":
@@ -196,7 +206,9 @@
196206 else:
197207 raise TypeError(f"Unsupported query type: {type(query)}")
198208
199- return LanceVectorQueryBuilder(table, query, vector_column_name, str_query)
209+ return LanceVectorQueryBuilder(
210+ table, query, vector_column_name, str_query, fast_search
211+ )
200212
201213 @classmethod
202214 def _resolve_query(cls, table, query, query_type, vector_column_name):
@@ -565,6 +577,7 @@
565577 query: Union[np.ndarray, list, "PIL.Image.Image"],
566578 vector_column: str,
567579 str_query: Optional[str] = None,
580+ fast_search: bool = False,
568581 ):
569582 super().__init__(table)
570583 self._query = query
@@ -575,6 +588,7 @@
575588 self._prefilter = False
576589 self._reranker = None
577590 self._str_query = str_query
591+ self._fast_search = fast_search
578592
579593 def metric(self, metric: Literal["L2", "cosine", "dot"]) -> LanceVectorQueryBuilder:
580594 """Set the distance metric to use.
@@ -675,6 +689,7 @@
675689 vector_column=self._vector_column,
676690 with_row_id=self._with_row_id,
677691 offset=self._offset,
692+ fast_search=self._fast_search,
678693 )
679694 result_set = self._table._execute_query(query, batch_size)
680695 if self._reranker is not None:
modified python/python/lancedb/remote/__init__.py +2 −0
@@ -50,6 +50,8 @@
5050
5151 vector_column: str = VECTOR_COLUMN_NAME
5252
53+ fast_search: bool = False
54+
5355
5456 @attrs.define
5557 class VectorQueryResult:
modified python/python/lancedb/remote/table.py +8 −0
@@ -270,6 +270,7 @@
270270 vector_column_name: Optional[str] = None,
271271 query_type="auto",
272272 fts_columns: Optional[Union[str, List[str]]] = None,
273+ fast_search: bool = False,
273274 ) -> LanceVectorQueryBuilder:
274275 """Create a search query to find the nearest neighbors
275276 of the given query vector. We currently support [vector search][search]
@@ -314,6 +315,12 @@
314315 - If the table has multiple vector columns then the *vector_column_name*
315316 needs to be specified. Otherwise, an error is raised.
316317
318+ fast_search: bool, optional
319+ Skip a flat search of unindexed data. This may improve
320+ search performance but search results will not include unindexed data.
321+
322+ - *default False*.
323+
317324 Returns
318325 -------
319326 LanceQueryBuilder
@@ -343,6 +350,7 @@
343350 query_type,
344351 vector_column_name=vector_column_name,
345352 fts_columns=fts_columns,
353+ fast_search=fast_search,
346354 )
347355
348356 def _execute_query(