LanceDB.Query (LanceDB v0.2.0)

Copy Markdown View Source

Pure, reusable queries. Construction validates options without accessing storage.

all/1, stream/2, stream_batches/2, explain/2, analyze/1 and schema/1 execute the same query. Scan limits default to 100; use limit(query, nil) for an unlimited scan. Searches default to 10 results. Re-execution of a live table may observe new data; use a table snapshot for repeatable reads.

Both constructors take the table first: new(table, opts) builds a scan; new(table, source, opts) selects an explicit source. Immediate helpers such as search/3 and query/2 execute these same query values. Result maps have string keys; operational failures return LanceDB.Error, and stream failures raise it during enumeration.

Summary

Functions

Collects the complete query result in memory.

Executes once and returns execution diagnostics.

Runs independent vector queries immediately.

Explains this query without executing it.

Runs a full-text query immediately.

Selects hybrid search. Rerankers are supplied through options/2.

Runs a hybrid query immediately.

Sets the maximum result count; nil allows unlimited scans.

Selects document multivector search.

Runs document multivector search immediately.

Selects vector search, retaining filters, projections and explicit limits.

Selects independent searches for a batch of query vectors.

Constructs a scan. No database work occurs until execution.

Constructs a query from a table, explicit source, and keyword controls.

Sets the result offset.

Merges options, validating them against the selected query kind.

Sets explicit ordering, including per-column null placement.

Collects a scan immediately. Use new/2 for a reusable query.

Selects direct row-ID retrieval.

Selects direct physical-offset retrieval.

Returns an ArrowSchema describing the physical output. Convert explicitly with ArrowSchema.to_schema/1 before table creation.

Runs a vector query immediately, returning up to 10 rows by default. Without :vector_column, selects the unique column compatible with the search mode and query dimension. Ambiguous matches require an explicit column; dimension mismatches return an error naming the query and expected dimensions. See the search controls for projection, filtering, distances, index tuning, and deadlines.

Sets projected column names.

Sets SQL string or Expr projections.

Builds a lazy row stream; each enumeration executes the query again. The only stream option is :batch_size (default 1024); query controls belong to the query value. Batches bound returned rows, not query memory. Ending or halting enumeration closes the cursor and releases its read admission slot.

Builds a lazy stream of native Arrow batches. Use Source.batches for schema-compatible ingestion.

Retrieves rows by non-negative uint64 physical offsets, with the same options and result-set semantics as take_row_ids/3. Updates, deletions, and compaction can change offsets; use the same table version for collection and retrieval.

Retrieves rows by internal ID. IDs are non-negative uint64 integers from _rowid, not application keys. Accepts :columns or :select, :with_row_id, and :timeout_ms; there is no default row limit. Missing IDs contribute no rows, duplicates do not repeat rows, and output order is unspecified. Collect and use IDs against the same table version.

Selects full-text search with a string or structured FTS query.

Sets a cooperative execution deadline: nil disables it, otherwise supply a positive uint32 millisecond count. For streams it covers the cursor lifetime, including consumer pauses; it does not interrupt the caller's Elixir code.

Sets the SQL string or Expr predicate, replacing any previous predicate.

Types

t()

@opaque t()

Functions

all(query)

@spec all(t()) :: LanceDB.result([map()])

Collects the complete query result in memory.

analyze(query)

@spec analyze(t()) :: LanceDB.result(String.t())

Executes once and returns execution diagnostics.

batch_search(table, vectors, opts \\ [])

@spec batch_search(LanceDB.Table.t(), [[number()]], keyword()) ::
  LanceDB.result([map()])

Runs independent vector queries immediately.

explain(query, opts \\ [])

@spec explain(t(), keyword()) :: LanceDB.result(String.t())

Explains this query without executing it.

full_text_search(table, text, opts \\ [])

@spec full_text_search(LanceDB.Table.t(), LanceDB.FTS.input(), keyword()) ::
  LanceDB.result([map()])

Runs a full-text query immediately.

hybrid(query, vector, text)

@spec hybrid(t(), [number()], LanceDB.FTS.input()) :: t()

Selects hybrid search. Rerankers are supplied through options/2.

hybrid_search(table, vector, text, opts \\ [])

@spec hybrid_search(LanceDB.Table.t(), [number()], LanceDB.FTS.input(), keyword()) ::
  LanceDB.result([map()])

Runs a hybrid query immediately.

limit(query, limit)

@spec limit(t(), pos_integer() | nil) :: t()

Sets the maximum result count; nil allows unlimited scans.

multivector(query, vectors)

@spec multivector(t(), [[number()]]) :: t()

Selects document multivector search.

multivector_search(table, vectors, opts \\ [])

@spec multivector_search(LanceDB.Table.t(), [[number()]], keyword()) ::
  LanceDB.result([map()])

Runs document multivector search immediately.

nearest_to(query, vector)

@spec nearest_to(t(), [number()]) :: t()

Selects vector search, retaining filters, projections and explicit limits.

nearest_to_many(query, vectors)

@spec nearest_to_many(t(), [[number()]]) :: t()

Selects independent searches for a batch of query vectors.

new(table, opts \\ [])

@spec new(LanceDB.Table.t(), keyword()) :: t()

Constructs a scan. No database work occurs until execution.

new(table, source, opts)

@spec new(LanceDB.Table.t(), term(), keyword()) :: t()

Constructs a query from a table, explicit source, and keyword controls.

Sources are :scan, {:vector, values}, {:text, text}, {:hybrid, values, text}, {:batch, vectors}, {:multivector, vectors}, {:take, :row_ids, values}, or {:take, :row_offsets, values}. Each source accepts its corresponding immediate API's options. See the query guide and search guide. Construction validates arguments without accessing storage.

offset(query, offset)

@spec offset(t(), non_neg_integer()) :: t()

Sets the result offset.

options(query, opts)

@spec options(t(), keyword()) :: t()

Merges options, validating them against the selected query kind.

order_by(query, ordering)

@spec order_by(t(), keyword()) :: t()

Sets explicit ordering, including per-column null placement.

query(table, opts \\ [])

@spec query(LanceDB.Table.t(), keyword()) :: LanceDB.result([map()])

Collects a scan immediately. Use new/2 for a reusable query.

row_ids(query, ids)

@spec row_ids(t(), [non_neg_integer()]) :: t()

Selects direct row-ID retrieval.

row_offsets(query, offsets)

@spec row_offsets(t(), [non_neg_integer()]) :: t()

Selects direct physical-offset retrieval.

schema(query)

@spec schema(t()) :: LanceDB.result(LanceDB.ArrowSchema.t())

Returns an ArrowSchema describing the physical output. Convert explicitly with ArrowSchema.to_schema/1 before table creation.

search(table, vector, opts \\ [])

@spec search(LanceDB.Table.t(), [number()], keyword()) :: LanceDB.result([map()])

Runs a vector query immediately, returning up to 10 rows by default. Without :vector_column, selects the unique column compatible with the search mode and query dimension. Ambiguous matches require an explicit column; dimension mismatches return an error naming the query and expected dimensions. See the search controls for projection, filtering, distances, index tuning, and deadlines.

select(query, columns)

@spec select(t(), [atom() | String.t()]) :: t()

Sets projected column names.

select_as(query, expressions)

@spec select_as(t(), map() | list()) :: t()

Sets SQL string or Expr projections.

stream(query, opts \\ [])

@spec stream(t(), keyword()) :: Enumerable.t()

Builds a lazy row stream; each enumeration executes the query again. The only stream option is :batch_size (default 1024); query controls belong to the query value. Batches bound returned rows, not query memory. Ending or halting enumeration closes the cursor and releases its read admission slot.

stream_batches(query, opts \\ [])

@spec stream_batches(t(), keyword()) :: Enumerable.t()

Builds a lazy stream of native Arrow batches. Use Source.batches for schema-compatible ingestion.

take_offsets(table, offsets, opts \\ [])

@spec take_offsets(LanceDB.Table.t(), [non_neg_integer()], keyword()) ::
  LanceDB.result([map()])

Retrieves rows by non-negative uint64 physical offsets, with the same options and result-set semantics as take_row_ids/3. Updates, deletions, and compaction can change offsets; use the same table version for collection and retrieval.

take_row_ids(table, ids, opts \\ [])

@spec take_row_ids(LanceDB.Table.t(), [non_neg_integer()], keyword()) ::
  LanceDB.result([map()])

Retrieves rows by internal ID. IDs are non-negative uint64 integers from _rowid, not application keys. Accepts :columns or :select, :with_row_id, and :timeout_ms; there is no default row limit. Missing IDs contribute no rows, duplicates do not repeat rows, and output order is unspecified. Collect and use IDs against the same table version.

text(query, text)

@spec text(t(), LanceDB.FTS.input()) :: t()

Selects full-text search with a string or structured FTS query.

timeout(query, milliseconds)

@spec timeout(t(), pos_integer() | nil) :: t()

Sets a cooperative execution deadline: nil disables it, otherwise supply a positive uint32 millisecond count. For streams it covers the cursor lifetime, including consumer pauses; it does not interrupt the caller's Elixir code.

where(query, predicate)

@spec where(t(), String.t() | LanceDB.Expr.t() | nil) :: t()

Sets the SQL string or Expr predicate, replacing any previous predicate.