mirror of
https://github.com/lancedb/lancedb.git
synced 2026-11-15 07:06:52 +00:00
feat: expose approx_mode on vector queries
`ApproxMode` landed in the Rust core in #3549, but the Python and Node.js bindings were never plumbed, so `approx_mode` is unreachable from either SDK. Both were built mirroring the existing `ef` plumbing. Co-authored-by: Leo <leo@insight.co>
This commit is contained in:
@@ -1308,6 +1308,28 @@ async def test_invalid_nprobes_async(table_async: AsyncTable):
|
||||
)
|
||||
|
||||
|
||||
def test_approx_mode_works_sync(table):
|
||||
for mode in ["fast", "normal", "accurate"]:
|
||||
LanceVectorQueryBuilder(table, [0, 0], "vector").approx_mode(mode).to_list()
|
||||
|
||||
|
||||
def test_invalid_approx_mode_sync(table):
|
||||
with pytest.raises(ValueError, match="approx_mode must be one of"):
|
||||
LanceVectorQueryBuilder(table, [0, 0], "vector").approx_mode("turbo").to_list()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_approx_mode_works_async(table_async: AsyncTable):
|
||||
for mode in ["fast", "normal", "accurate"]:
|
||||
await table_async.vector_search([0, 0]).approx_mode(mode).to_list()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_invalid_approx_mode_async(table_async: AsyncTable):
|
||||
with pytest.raises(ValueError, match="approx_mode must be one of"):
|
||||
table_async.vector_search([0, 0]).approx_mode("turbo")
|
||||
|
||||
|
||||
def test_query_builder_with_prefilter(table):
|
||||
df = (
|
||||
LanceVectorQueryBuilder(table, [0, 0], "vector")
|
||||
@@ -1962,6 +1984,9 @@ def test_query_serialization_sync(table: lancedb.table.Table):
|
||||
q = table.search([5.0, 6.0]).ef(7).to_query_object()
|
||||
check_set_props(q, ef=7, vector_column="vector", vector=[5.0, 6.0])
|
||||
|
||||
q = table.search([5.0, 6.0]).approx_mode("fast").to_query_object()
|
||||
check_set_props(q, approx_mode="fast", vector_column="vector", vector=[5.0, 6.0])
|
||||
|
||||
q = table.search([5.0, 6.0]).bypass_vector_index().to_query_object()
|
||||
check_set_props(
|
||||
q, bypass_vector_index=True, vector_column="vector", vector=[5.0, 6.0]
|
||||
@@ -2190,6 +2215,19 @@ async def test_query_serialization_async(table_async: AsyncTable):
|
||||
limit=10,
|
||||
)
|
||||
|
||||
q = (await table_async.search([5.0, 6.0])).approx_mode("fast").to_query_object()
|
||||
check_set_props(
|
||||
q,
|
||||
approx_mode="fast",
|
||||
vector=sample_vector,
|
||||
postfilter=False,
|
||||
minimum_nprobes=None,
|
||||
maximum_nprobes=None,
|
||||
with_row_id=False,
|
||||
bypass_vector_index=False,
|
||||
limit=10,
|
||||
)
|
||||
|
||||
q = (await table_async.search([5.0, 6.0])).bypass_vector_index().to_query_object()
|
||||
check_set_props(
|
||||
q,
|
||||
@@ -2228,6 +2266,20 @@ async def test_query_serialization_async(table_async: AsyncTable):
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_hybrid_query_serialization_async(table_async: AsyncTable):
|
||||
q = (
|
||||
table_async.query()
|
||||
.nearest_to([5.0, 6.0])
|
||||
.nearest_to_text(MatchQuery("dog", "text"))
|
||||
.ef(7)
|
||||
.approx_mode("fast")
|
||||
.to_query_object()
|
||||
)
|
||||
assert q.ef == 7
|
||||
assert q.approx_mode == "fast"
|
||||
|
||||
|
||||
def test_query_schema(tmp_path):
|
||||
db = lancedb.connect(tmp_path)
|
||||
tbl = db.create_table(
|
||||
|
||||
Reference in New Issue
Block a user