Changesets · Branches · Tags · Compare
| Changeset | adee0434ac3dab17d9df5c44aa1dd299a287382429d5a96aec6b82c34eb9b3c1 |
|---|---|
| Author | Ayush Chaurasia <ayush.chaurarsia@gmail.com> · 2024-09-24 19:02 +05:30 |
| Committer | GitHub <noreply@github.com> · 2024-09-24 19:02 +05:30 |
| Parents | 6c24ed805bf1 |
2 files changed
modified python/python/lancedb/table.py +3 −1
| @@ -1630,7 +1630,9 @@ | ||
| 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 vector_column_name is None and query is not None and query_type != "fts": | |
| 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"): | |
| 1634 | 1636 | try: |
| 1635 | 1637 | vector_column_name = inf_vector_column_query(self.schema) |
| 1636 | 1638 | except Exception as e: |
modified python/python/tests/test_table.py +30 −1
| @@ -973,7 +973,36 @@ | ||
| 973 | 973 | .where("text='Arrrrggghhhhhhh'") |
| 974 | 974 | .to_list() |
| 975 | 975 | ) |
| 976 | - len(result) == 1 | |
| 976 | + assert len(result) == 1 | |
| 977 | + | |
| 978 | + # with explicit query type | |
| 979 | + vector_query = list(range(emb.ndims())) | |
| 980 | + result = ( | |
| 981 | + table.search(query_type="hybrid") | |
| 982 | + .vector(vector_query) | |
| 983 | + .text("Arrrrggghhhhhhh") | |
| 984 | + .to_arrow() | |
| 985 | + ) | |
| 986 | + assert len(result) > 0 | |
| 987 | + assert "_relevance_score" in result.column_names | |
| 988 | + | |
| 989 | + # with vector_column_name | |
| 990 | + result = ( | |
| 991 | + table.search(query_type="hybrid", vector_column_name="vector") | |
| 992 | + .vector(vector_query) | |
| 993 | + .text("Arrrrggghhhhhhh") | |
| 994 | + .to_arrow() | |
| 995 | + ) | |
| 996 | + assert len(result) > 0 | |
| 997 | + assert "_relevance_score" in result.column_names | |
| 998 | + | |
| 999 | + # fail if only text or vector is provided | |
| 1000 | + with pytest.raises(ValueError): | |
| 1001 | + table.search(query_type="hybrid").to_list() | |
| 1002 | + with pytest.raises(ValueError): | |
| 1003 | + table.search(query_type="hybrid").vector(vector_query).to_list() | |
| 1004 | + with pytest.raises(ValueError): | |
| 1005 | + table.search(query_type="hybrid").text("Arrrrggghhhhhhh").to_list() | |
| 977 | 1006 | |
| 978 | 1007 | |
| 979 | 1008 | @pytest.mark.parametrize( |