Changesets · Branches · Tags · Compare
| Changeset | 51a5b30d4bbd34033f1a7c0f0deba88dc56994eaf32e6a7a36e98c1f90665a09 |
|---|---|
| Author | Ryan Green <ryang@ryang.ca> · 2024-10-14 14:39 -06:00 |
| Committer | GitHub <noreply@github.com> · 2024-10-14 14:39 -06:00 |
| Parents | aba9e2e83ce6 |
3 files changed
modified python/python/lancedb/query.py +16 −1
| @@ -88,6 +88,11 @@ | ||
| 88 | 88 | tuning advice. |
| 89 | 89 | offset: int |
| 90 | 90 | 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*. | |
| 91 | 96 | """ |
| 92 | 97 | |
| 93 | 98 | vector_column: Optional[str] = None |
| @@ -124,6 +129,8 @@ | ||
| 124 | 129 | |
| 125 | 130 | offset: int = 0 |
| 126 | 131 | |
| 132 | + fast_search: bool = False | |
| 133 | + | |
| 127 | 134 | |
| 128 | 135 | class LanceQueryBuilder(ABC): |
| 129 | 136 | """An abstract query builder. Subclasses are defined for vector search, |
| @@ -139,6 +146,7 @@ | ||
| 139 | 146 | vector_column_name: str, |
| 140 | 147 | ordering_field_name: Optional[str] = None, |
| 141 | 148 | fts_columns: Union[str, List[str]] = [], |
| 149 | + fast_search: bool = False, | |
| 142 | 150 | ) -> LanceQueryBuilder: |
| 143 | 151 | """ |
| 144 | 152 | Create a query builder based on the given query and query type. |
| @@ -155,6 +163,8 @@ | ||
| 155 | 163 | If "auto", the query type is inferred based on the query. |
| 156 | 164 | vector_column_name: str |
| 157 | 165 | The name of the vector column to use for vector search. |
| 166 | + fast_search: bool | |
| 167 | + Skip flat search of unindexed data. | |
| 158 | 168 | """ |
| 159 | 169 | # Check hybrid search first as it supports empty query pattern |
| 160 | 170 | if query_type == "hybrid": |
| @@ -196,7 +206,9 @@ | ||
| 196 | 206 | else: |
| 197 | 207 | raise TypeError(f"Unsupported query type: {type(query)}") |
| 198 | 208 | |
| 199 | - return LanceVectorQueryBuilder(table, query, vector_column_name, str_query) | |
| 209 | + return LanceVectorQueryBuilder( | |
| 210 | + table, query, vector_column_name, str_query, fast_search | |
| 211 | + ) | |
| 200 | 212 | |
| 201 | 213 | @classmethod |
| 202 | 214 | def _resolve_query(cls, table, query, query_type, vector_column_name): |
| @@ -565,6 +577,7 @@ | ||
| 565 | 577 | query: Union[np.ndarray, list, "PIL.Image.Image"], |
| 566 | 578 | vector_column: str, |
| 567 | 579 | str_query: Optional[str] = None, |
| 580 | + fast_search: bool = False, | |
| 568 | 581 | ): |
| 569 | 582 | super().__init__(table) |
| 570 | 583 | self._query = query |
| @@ -575,6 +588,7 @@ | ||
| 575 | 588 | self._prefilter = False |
| 576 | 589 | self._reranker = None |
| 577 | 590 | self._str_query = str_query |
| 591 | + self._fast_search = fast_search | |
| 578 | 592 | |
| 579 | 593 | def metric(self, metric: Literal["L2", "cosine", "dot"]) -> LanceVectorQueryBuilder: |
| 580 | 594 | """Set the distance metric to use. |
| @@ -675,6 +689,7 @@ | ||
| 675 | 689 | vector_column=self._vector_column, |
| 676 | 690 | with_row_id=self._with_row_id, |
| 677 | 691 | offset=self._offset, |
| 692 | + fast_search=self._fast_search, | |
| 678 | 693 | ) |
| 679 | 694 | result_set = self._table._execute_query(query, batch_size) |
| 680 | 695 | if self._reranker is not None: |
modified python/python/lancedb/remote/__init__.py +2 −0
| @@ -50,6 +50,8 @@ | ||
| 50 | 50 | |
| 51 | 51 | vector_column: str = VECTOR_COLUMN_NAME |
| 52 | 52 | |
| 53 | + fast_search: bool = False | |
| 54 | + | |
| 53 | 55 | |
| 54 | 56 | @attrs.define |
| 55 | 57 | class VectorQueryResult: |
modified python/python/lancedb/remote/table.py +8 −0
| @@ -270,6 +270,7 @@ | ||
| 270 | 270 | vector_column_name: Optional[str] = None, |
| 271 | 271 | query_type="auto", |
| 272 | 272 | fts_columns: Optional[Union[str, List[str]]] = None, |
| 273 | + fast_search: bool = False, | |
| 273 | 274 | ) -> LanceVectorQueryBuilder: |
| 274 | 275 | """Create a search query to find the nearest neighbors |
| 275 | 276 | of the given query vector. We currently support [vector search][search] |
| @@ -314,6 +315,12 @@ | ||
| 314 | 315 | - If the table has multiple vector columns then the *vector_column_name* |
| 315 | 316 | needs to be specified. Otherwise, an error is raised. |
| 316 | 317 | |
| 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 | + | |
| 317 | 324 | Returns |
| 318 | 325 | ------- |
| 319 | 326 | LanceQueryBuilder |
| @@ -343,6 +350,7 @@ | ||
| 343 | 350 | query_type, |
| 344 | 351 | vector_column_name=vector_column_name, |
| 345 | 352 | fts_columns=fts_columns, |
| 353 | + fast_search=fast_search, | |
| 346 | 354 | ) |
| 347 | 355 | |
| 348 | 356 | def _execute_query( |