Changesets · Branches · Tags · Compare
| Changeset | ffc27a8ff454402e1a15f587006a2fd430fcc89d38fb998fe0219aaca67e8620 |
|---|---|
| Author | Ayush Chaurasia <ayush.chaurarsia@gmail.com> · 2024-09-25 21:04 +05:30 |
| Committer | GitHub <noreply@github.com> · 2024-09-25 21:04 +05:30 |
| Parents | f371856ec79a |
3 files changed
modified python/python/lancedb/remote/table.py +11 −9
| @@ -26,7 +26,7 @@ | ||
| 26 | 26 | |
| 27 | 27 | from ..query import LanceVectorQueryBuilder, LanceQueryBuilder |
| 28 | 28 | from ..table import Query, Table, _sanitize_data |
| 29 | -from ..util import inf_vector_column_query, value_to_sql | |
| 29 | +from ..util import value_to_sql, infer_vector_column_name | |
| 30 | 30 | from .arrow import to_ipc_binary |
| 31 | 31 | from .client import ARROW_STREAM_CONTENT_TYPE |
| 32 | 32 | from .db import RemoteDBConnection |
| @@ -266,7 +266,7 @@ | ||
| 266 | 266 | |
| 267 | 267 | def search( |
| 268 | 268 | self, |
| 269 | - query: Union[VEC, str], | |
| 269 | + query: Union[VEC, str] = None, | |
| 270 | 270 | vector_column_name: Optional[str] = None, |
| 271 | 271 | query_type="auto", |
| 272 | 272 | fts_columns: Optional[Union[str, List[str]]] = None, |
| @@ -305,8 +305,6 @@ | ||
| 305 | 305 | - *default None*. |
| 306 | 306 | Acceptable types are: list, np.ndarray, PIL.Image.Image |
| 307 | 307 | |
| 308 | - - If None then the select/where/limit clauses are applied to filter | |
| 309 | - the table | |
| 310 | 308 | vector_column_name: str, optional |
| 311 | 309 | The name of the vector column to search. |
| 312 | 310 | |
| @@ -329,11 +327,15 @@ | ||
| 329 | 327 | - and also the "_distance" column which is the distance between the query |
| 330 | 328 | vector and the returned vector. |
| 331 | 329 | """ |
| 332 | - if vector_column_name is None and query is not None and query_type != "fts": | |
| 333 | - try: | |
| 334 | - vector_column_name = inf_vector_column_query(self.schema) | |
| 335 | - except Exception as e: | |
| 336 | - raise e | |
| 330 | + # empty query builder is not supported in saas, raise error | |
| 331 | + if query is None and query_type != "hybrid": | |
| 332 | + raise ValueError("Empty query is not supported") | |
| 333 | + vector_column_name = infer_vector_column_name( | |
| 334 | + schema=self.schema, | |
| 335 | + query_type=query_type, | |
| 336 | + query=query, | |
| 337 | + vector_column_name=vector_column_name, | |
| 338 | + ) | |
| 337 | 339 | |
| 338 | 340 | return LanceQueryBuilder.create( |
| 339 | 341 | self, |
modified python/python/lancedb/table.py +7 −8
| @@ -50,7 +50,7 @@ | ||
| 50 | 50 | from .util import ( |
| 51 | 51 | fs_from_uri, |
| 52 | 52 | get_uri_scheme, |
| 53 | - inf_vector_column_query, | |
| 53 | + infer_vector_column_name, | |
| 54 | 54 | join_uri, |
| 55 | 55 | safe_import_pandas, |
| 56 | 56 | safe_import_polars, |
| @@ -1630,13 +1630,12 @@ | ||
| 1630 | 1630 | and also the "_distance" column which is the distance between the query |
| 1631 | 1631 | vector and the returned vector. |
| 1632 | 1632 | """ |
| 1633 | - if ( | |
| 1634 | - vector_column_name is None and query is not None and query_type != "fts" | |
| 1635 | - ) or (vector_column_name is None and query_type == "hybrid"): | |
| 1636 | - try: | |
| 1637 | - vector_column_name = inf_vector_column_query(self.schema) | |
| 1638 | - except Exception as e: | |
| 1639 | - raise e | |
| 1633 | + vector_column_name = infer_vector_column_name( | |
| 1634 | + schema=self.schema, | |
| 1635 | + query_type=query_type, | |
| 1636 | + query=query, | |
| 1637 | + vector_column_name=vector_column_name, | |
| 1638 | + ) | |
| 1640 | 1639 | |
| 1641 | 1640 | return LanceQueryBuilder.create( |
| 1642 | 1641 | self, |
modified python/python/lancedb/util.py +18 −1
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | import warnings |
| 10 | 10 | from datetime import date, datetime |
| 11 | 11 | from functools import singledispatch |
| 12 | -from typing import Tuple, Union | |
| 12 | +from typing import Tuple, Union, Optional, Any | |
| 13 | 13 | from urllib.parse import urlparse |
| 14 | 14 | |
| 15 | 15 | import numpy as np |
| @@ -212,6 +212,23 @@ | ||
| 212 | 212 | return vector_col_name |
| 213 | 213 | |
| 214 | 214 | |
| 215 | +def infer_vector_column_name( | |
| 216 | + schema: pa.Schema, | |
| 217 | + query_type: str, | |
| 218 | + query: Optional[Any], # inferred later in query builder | |
| 219 | + vector_column_name: Optional[str], | |
| 220 | +): | |
| 221 | + if (vector_column_name is None and query is not None and query_type != "fts") or ( | |
| 222 | + vector_column_name is None and query_type == "hybrid" | |
| 223 | + ): | |
| 224 | + try: | |
| 225 | + vector_column_name = inf_vector_column_query(schema) | |
| 226 | + except Exception as e: | |
| 227 | + raise e | |
| 228 | + | |
| 229 | + return vector_column_name | |
| 230 | + | |
| 231 | + | |
| 215 | 232 | @singledispatch |
| 216 | 233 | def value_to_sql(value): |
| 217 | 234 | raise NotImplementedError("SQL conversion is not implemented for this type") |