mirror of
https://github.com/lancedb/lancedb.git
synced 2026-10-19 10:12:28 +00:00
feat(sql): bind query parameters over Flight DoExchange
execute_query / execute_query_async accept parameters: a one-row Arrow batch bound to the statement's $1 / $name placeholders. A statement with parameters is sent on one DoExchange (command descriptor + parameter schema, then the row) and its rows come back on the same call, so floats keep their exact bits and vectors stay compact FixedSizeLists instead of being spliced into SQL text. Statements without parameters keep the PollFlightInfo + DoGet path. Database::execute_query_async now takes an ExecuteQueryRequest.
This commit is contained in:
@@ -86,6 +86,15 @@ print(query.describe().status)
|
||||
for batch in query.reader():
|
||||
print(batch.num_rows)
|
||||
|
||||
# Values bind to $1 / $name placeholders and travel as Arrow, so a float32
|
||||
# stays a float32 and a vector stays a compact fixed-size list:
|
||||
import numpy as np
|
||||
|
||||
reader = db.execute_query(
|
||||
"SELECT id FROM docs ORDER BY distance(vector, $vector) LIMIT $k",
|
||||
parameters={"vector": np.random.rand(768).astype(np.float32), "k": 10},
|
||||
)
|
||||
|
||||
# The async connection exposes the same lifecycle without blocking:
|
||||
# async_db = await lancedb.connect_async(
|
||||
# "db://analytics",
|
||||
@@ -201,6 +210,8 @@ listing a storage directory.
|
||||
|
||||
::: lancedb.sql.QueryDescription
|
||||
|
||||
::: lancedb.sql.QueryParameters
|
||||
|
||||
## Materialized Views (Synchronous)
|
||||
|
||||
::: lancedb.materialized_view.MaterializedView
|
||||
|
||||
Reference in New Issue
Block a user