Builds on #4359 (which added the Arrow 19-21 test aliases) and makes the package genuinely work across the whole peer range: * Resolve the library's own `apache-arrow` to 21.2.0 (devDependency) so the main CI jobs build, type-check and test on the newest release, and widen the peer range to `>=15.0.0 <22.0.0` instead of an exact pin. * Add a CI job that re-installs with `apache-arrow` resolved to 19.0.1 and 20.0.0 and runs the suite, covering what a consumer on those versions gets. * Arrow 21 overrides `Symbol.hasInstance` on Schema/Field/Table/RecordBatch/ Data so `instanceof` matches objects from another copy of the library, but not on DataType. The sanitizer's short-circuits therefore returned foreign schemas unchanged and Arrow's builders then failed with "Unrecognized type 'NONE'". Check the real prototype chain instead. * Sanitize the types added in Arrow 20/21 (LargeList, Utf8View, BinaryView, IntervalMonthDayNano), looked up dynamically so the library still compiles and runs on older Arrow releases, with a clear error when the installed Arrow lacks the type. Carry `variadicBuffers` through `Data`. * Loosen `FieldLike` so a branded DataType from another Arrow copy still type-checks; export the new `DataTypeLike`. * Share the Arrow version list between test files, exercise embedding function types per version in the registry tests, and add sanitize and end-to-end coverage for the new column types. * Enable `skipLibCheck`: flatbuffers 25 (via Arrow 21) ships declarations that need TypeScript 5.7+. * Record the new dev dependencies in the third-party license inventory. Co-Authored-By: Vincent Koc <vincentkoc@ieee.org> Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
7.7 KiB
@lancedb/lancedb • Docs
@lancedb/lancedb / TakeQuery
Class: TakeQuery
A query that returns a subset of the rows in the table.
Extends
QueryBase<NativeTakeQuery>
Properties
inner
protected inner: TakeQuery | Promise<TakeQuery>;
Inherited from
Methods
analyzePlan()
analyzePlan(distributedMetrics?): Promise<string>
Executes the query and returns the physical query plan annotated with runtime metrics.
This is useful for debugging and performance analysis, as it shows how the query was executed and includes metrics such as elapsed time, rows processed, and I/O statistics.
Parameters
- distributedMetrics?:
AnalyzePlanDistributedMetricsHow distributed worker metrics are displayed for remote query plans. Defaults to"aggregate".
Returns
Promise<string>
A query execution plan with runtime metrics for each step.
Example
import * as lancedb from "@lancedb/lancedb"
const db = await lancedb.connect("./.lancedb");
const table = await db.createTable("my_table", [
{ vector: [1.1, 0.9], id: "1" },
]);
const plan = await table.query().nearestTo([0.5, 0.2]).analyzePlan();
Example output (with runtime metrics inlined):
AnalyzeExec verbose=true, metrics=[]
ProjectionExec: expr=[id@3 as id, vector@0 as vector, _distance@2 as _distance], metrics=[output_rows=1, elapsed_compute=3.292µs]
Take: columns="vector, _rowid, _distance, (id)", metrics=[output_rows=1, elapsed_compute=66.001µs, batches_processed=1, bytes_read=8, iops=1, requests=1]
CoalesceBatchesExec: target_batch_size=1024, metrics=[output_rows=1, elapsed_compute=3.333µs]
GlobalLimitExec: skip=0, fetch=10, metrics=[output_rows=1, elapsed_compute=167ns]
FilterExec: _distance@2 IS NOT NULL, metrics=[output_rows=1, elapsed_compute=8.542µs]
SortExec: TopK(fetch=10), expr=[_distance@2 ASC NULLS LAST], metrics=[output_rows=1, elapsed_compute=63.25µs, row_replacements=1]
KNNVectorDistance: metric=l2, metrics=[output_rows=1, elapsed_compute=114.333µs, output_batches=1]
LanceScan: uri=/path/to/data, projection=[vector], row_id=true, row_addr=false, ordered=false, metrics=[output_rows=1, elapsed_compute=103.626µs, bytes_read=549, iops=2, requests=2]
Inherited from
execute()
protected execute(options?): AsyncGenerator<RecordBatch<any>, void, unknown>
Execute the query and return the results as an
Parameters
- options?:
Partial<QueryExecutionOptions>
Returns
AsyncGenerator<RecordBatch<any>, void, unknown>
See
- AsyncIterator of
- RecordBatch.
By default, LanceDb will use many threads to calculate results and, when the result set is large, multiple batches will be processed at one time. This readahead is limited however and backpressure will be applied if this stream is consumed slowly (this constrains the maximum memory used by a single query)
Inherited from
explainPlan()
explainPlan(verbose): Promise<string>
Generates an explanation of the query execution plan.
Parameters
- verbose:
boolean=falseIf true, provides a more detailed explanation. Defaults to false.
Returns
Promise<string>
A Promise that resolves to a string containing the query execution plan explanation.
Example
import * as lancedb from "@lancedb/lancedb"
const db = await lancedb.connect("./.lancedb");
const table = await db.createTable("my_table", [
{ vector: [1.1, 0.9], id: "1" },
]);
const plan = await table.query().nearestTo([0.5, 0.2]).explainPlan();
Inherited from
outputSchema()
outputSchema(): Promise<Schema<any>>
Returns the schema of the output that will be returned by this query.
This can be used to inspect the types and names of the columns that will be returned by the query before executing it.
Returns
Promise<Schema<any>>
An Arrow Schema describing the output columns.
Inherited from
select()
select(columns): this
Return only the specified columns.
By default a query will return all columns from the table. However, this can have a very significant impact on latency. LanceDb stores data in a columnar fashion. This means we can finely tune our I/O to select exactly the columns we need.
As a best practice you should always limit queries to the columns that you need. If you pass in an array of column names then only those columns will be returned.
You can also use this method to create new "dynamic" columns based on your existing columns.
For example, you may not care about "a" or "b" but instead simply want "a + b". This is often
seen in the SELECT clause of an SQL query (e.g. SELECT a+b FROM my_table).
To create dynamic columns you can pass in a Map<string, string>. A column will be returned for each entry in the map. The key provides the name of the column. The value is an SQL string used to specify how the column is calculated.
For example, an SQL query might state SELECT a + b AS combined, c. The equivalent
input to this method would be:
Parameters
- columns:
string|string[] |Map<string,string> |Record<string,string>
Returns
this
Example
new Map([["combined", "a + b"], ["c", "c"]])
Columns will always be returned in the order given, even if that order is different than
the order used when adding the data.
Note that you can pass in a `Record<string, string>` (e.g. an object literal). This method
uses `Object.entries` which should preserve the insertion order of the object. However,
object insertion order is easy to get wrong and `Map` is more foolproof.
Inherited from
toArray()
toArray(options?): Promise<any[]>
Collect the results as an array of objects.
Parameters
- options?:
Partial<QueryExecutionOptions>
Returns
Promise<any[]>
Inherited from
toArrow()
toArrow(options?): Promise<Table<any>>
Collect the results as an Arrow
Parameters
- options?:
Partial<QueryExecutionOptions>
Returns
Promise<Table<any>>
See
ArrowTable.
Inherited from
useLsm()
useLsm(enable): this
Control MemWAL read routing for this take query.
false bypasses the MemWAL and reads the base table only — the escape hatch,
since take-by-row-id/offset is not supported on the LSM scanner and, on a
MemWAL table, auto-routes to it and errors otherwise.
Parameters
- enable:
booleanfalsereads the base table only.
Returns
this
withRowId()
withRowId(): this
Whether to return the row id in the results.
This column can be used to match results between different queries. For example, to match results from a full text search and a vector search in order to perform hybrid search.
Returns
this