mirror of
https://github.com/lancedb/lancedb.git
synced 2026-12-03 07:45:17 +00:00
feat(query): stream query results with optional total hits (#5354)
## Summary An Embedded query can stream one page of results and report how many visible rows matched before offset and limit. This adds Rust `execute_with_metadata`, Python sync and async `to_result`, and TypeScript `toResult`. The existing query terminals continue to use their existing execution paths. Tracking defaults to Off. An exact count returns `eq(N)`. A positive cap C returns `eq(N)` below C and `gte(C)` as soon as C matches are proven, including equality. TypeScript exposes counts as bigint. Counts use the same snapshot as the result batches. The accessor reports pending until the stream reaches successful EOF. Explicit counts can add work after the last batch, especially when full-text counting needs to scan visible text. Closing an unfinished result cancels execution. Stream and metadata failures retain interruption details, including the request ID. Embedded supports scalar and row-level lexical counts. Unordered FTS retains its existing top-k and scoring policy. Enterprise and unsupported query shapes return a typed error when a count is requested. ## Dependency #5352 merged Lance v16.0.0-beta.7 into main, including [Lance #11680](https://github.com/lance-format/lance/pull/11680). This PR uses that dependency and its lockfiles. ## Validation The Linux-tested revision `bc39ad7ac` and rebased revision `24f4e90c2` have the same Git tree. The only change in `6932b3082` is the Python namespace regression fixture, which now resolves the local table without the optional pylance package. The revised test passed on managed Linux with CPython 3.11.18 both with pylance and pandas installed and after removing both packages. Managed Linux runs used the unmodified manifests and lockfiles from #5352 and the published `pylance 16.0.0b7` wheel. - The Rust metadata suite passed 57 tests, with two existing ignores. Coverage includes unordered FTS plans, top-k scores, physical row addresses under pagination, pending-read cancellation, and interruption after the last batch. - Python query, remote and namespace suites passed 1,163 tests. One optional slow test requires PyTorch, which was unavailable on this VM. The Node query, remote, table and error suites passed 913 tests, with three experimental cases skipped. - Regression tests reproduced the failures on the previous revision and verified the fixes. Python sync reranking and namespace FTS preserve an explicit empty page. Python sync and async scans expose `_rowaddr` alongside the pre-pagination count. Explicit counts are rejected before TypeScript auto-search issues an Enterprise request or invokes a vector embedding provider. Python and Node retain the server's 1,063-row first batch in Off mode. - A custom Python namespace opened through the public API receives the same computed projection in Off mode as with `to_batches()`. A Node result interrupted after another SDK load retains its original error class and request ID. Both regressions were reproduced on the prior revision. - Workspace Clippy, formatting, Ruff, Biome, TypeScript checks, TypeDoc and strict MkDocs passed. All 287 generated TypeDoc files matched the committed files byte for byte.
This commit is contained in:
@@ -451,6 +451,49 @@ Empty results retain the query's output schema.
|
||||
|
||||
***
|
||||
|
||||
### toResult()
|
||||
|
||||
```ts
|
||||
toResult(options?): Promise<QueryResult>
|
||||
```
|
||||
|
||||
Stream one execution and read its metadata after successful exhaustion.
|
||||
Tracking is off by default. Set `trackTotalHits` to `true` for an exact count
|
||||
before offset and limit, or to a positive integer for a capped count.
|
||||
At the cap, `totalHits.relation` is `"gte"`.
|
||||
|
||||
Embedded supports counts for unfiltered scans, scans with deterministic scalar
|
||||
filters, and row-level full-text searches for a single term or a positive OR
|
||||
of terms with supported prefilters. Requesting a count on an Enterprise table
|
||||
or an unsupported query, such as vector or hybrid search, throws
|
||||
`UnsupportedMetadataError`.
|
||||
|
||||
Counting can continue after the last data batch. Consume the iterator to EOF
|
||||
or await `result.finish()` before calling `result.metadata()`.
|
||||
|
||||
#### Parameters
|
||||
|
||||
* **options?**
|
||||
|
||||
* **options.trackTotalHits?**: `number` \| `bigint` \| `boolean`
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<[`QueryResult`](QueryResult.md)>
|
||||
|
||||
#### Example
|
||||
|
||||
```ts
|
||||
const result = await table.query().limit(1).toResult({ trackTotalHits: 100n });
|
||||
const hits = (await result.finish()).totalHits;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
`StandardQueryBase.toResult`
|
||||
|
||||
***
|
||||
|
||||
### useRTE()
|
||||
|
||||
```ts
|
||||
|
||||
@@ -56,6 +56,7 @@ try {
|
||||
- [`LanceRuntimeError`](LanceRuntimeError.md)
|
||||
- [`NotAComputedColumnError`](NotAComputedColumnError.md)
|
||||
- [`NotSupportedError`](NotSupportedError.md)
|
||||
- [`UnsupportedMetadataError`](UnsupportedMetadataError.md)
|
||||
- [`ObjectStoreError`](ObjectStoreError.md)
|
||||
- [`OtherError`](OtherError.md)
|
||||
- [`RetryError`](RetryError.md)
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
[**@lancedb/lancedb**](../README.md) • **Docs**
|
||||
|
||||
***
|
||||
|
||||
[@lancedb/lancedb](../globals.md) / MetadataCancelledError
|
||||
|
||||
# Class: MetadataCancelledError
|
||||
|
||||
## Extends
|
||||
|
||||
- `Error`
|
||||
|
||||
## Constructors
|
||||
|
||||
### new MetadataCancelledError()
|
||||
|
||||
```ts
|
||||
new MetadataCancelledError(message?): MetadataCancelledError
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
* **message?**: `string`
|
||||
|
||||
#### Returns
|
||||
|
||||
[`MetadataCancelledError`](MetadataCancelledError.md)
|
||||
|
||||
#### Inherited from
|
||||
|
||||
`Error.constructor`
|
||||
|
||||
### new MetadataCancelledError()
|
||||
|
||||
```ts
|
||||
new MetadataCancelledError(message?, options?): MetadataCancelledError
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
* **message?**: `string`
|
||||
|
||||
* **options?**: `ErrorOptions`
|
||||
|
||||
#### Returns
|
||||
|
||||
[`MetadataCancelledError`](MetadataCancelledError.md)
|
||||
|
||||
#### Inherited from
|
||||
|
||||
`Error.constructor`
|
||||
|
||||
## Properties
|
||||
|
||||
### cause?
|
||||
|
||||
```ts
|
||||
optional cause: unknown;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
`Error.cause`
|
||||
|
||||
***
|
||||
|
||||
### message
|
||||
|
||||
```ts
|
||||
message: string;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
`Error.message`
|
||||
|
||||
***
|
||||
|
||||
### name
|
||||
|
||||
```ts
|
||||
name: string;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
`Error.name`
|
||||
|
||||
***
|
||||
|
||||
### stack?
|
||||
|
||||
```ts
|
||||
optional stack: string;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
`Error.stack`
|
||||
|
||||
***
|
||||
|
||||
### prepareStackTrace()?
|
||||
|
||||
```ts
|
||||
static optional prepareStackTrace: (err, stackTraces) => any;
|
||||
```
|
||||
|
||||
Optional override for formatting stack traces
|
||||
|
||||
#### Parameters
|
||||
|
||||
* **err**: `Error`
|
||||
|
||||
* **stackTraces**: `CallSite`[]
|
||||
|
||||
#### Returns
|
||||
|
||||
`any`
|
||||
|
||||
#### See
|
||||
|
||||
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
|
||||
|
||||
#### Inherited from
|
||||
|
||||
`Error.prepareStackTrace`
|
||||
|
||||
***
|
||||
|
||||
### stackTraceLimit
|
||||
|
||||
```ts
|
||||
static stackTraceLimit: number;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
`Error.stackTraceLimit`
|
||||
|
||||
## Methods
|
||||
|
||||
### captureStackTrace()
|
||||
|
||||
```ts
|
||||
static captureStackTrace(targetObject, constructorOpt?): void
|
||||
```
|
||||
|
||||
Create .stack property on a target object
|
||||
|
||||
#### Parameters
|
||||
|
||||
* **targetObject**: `object`
|
||||
|
||||
* **constructorOpt?**: `Function`
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
#### Inherited from
|
||||
|
||||
`Error.captureStackTrace`
|
||||
@@ -0,0 +1,163 @@
|
||||
[**@lancedb/lancedb**](../README.md) • **Docs**
|
||||
|
||||
***
|
||||
|
||||
[@lancedb/lancedb](../globals.md) / MetadataPendingError
|
||||
|
||||
# Class: MetadataPendingError
|
||||
|
||||
## Extends
|
||||
|
||||
- `Error`
|
||||
|
||||
## Constructors
|
||||
|
||||
### new MetadataPendingError()
|
||||
|
||||
```ts
|
||||
new MetadataPendingError(message?): MetadataPendingError
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
* **message?**: `string`
|
||||
|
||||
#### Returns
|
||||
|
||||
[`MetadataPendingError`](MetadataPendingError.md)
|
||||
|
||||
#### Inherited from
|
||||
|
||||
`Error.constructor`
|
||||
|
||||
### new MetadataPendingError()
|
||||
|
||||
```ts
|
||||
new MetadataPendingError(message?, options?): MetadataPendingError
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
* **message?**: `string`
|
||||
|
||||
* **options?**: `ErrorOptions`
|
||||
|
||||
#### Returns
|
||||
|
||||
[`MetadataPendingError`](MetadataPendingError.md)
|
||||
|
||||
#### Inherited from
|
||||
|
||||
`Error.constructor`
|
||||
|
||||
## Properties
|
||||
|
||||
### cause?
|
||||
|
||||
```ts
|
||||
optional cause: unknown;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
`Error.cause`
|
||||
|
||||
***
|
||||
|
||||
### message
|
||||
|
||||
```ts
|
||||
message: string;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
`Error.message`
|
||||
|
||||
***
|
||||
|
||||
### name
|
||||
|
||||
```ts
|
||||
name: string;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
`Error.name`
|
||||
|
||||
***
|
||||
|
||||
### stack?
|
||||
|
||||
```ts
|
||||
optional stack: string;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
`Error.stack`
|
||||
|
||||
***
|
||||
|
||||
### prepareStackTrace()?
|
||||
|
||||
```ts
|
||||
static optional prepareStackTrace: (err, stackTraces) => any;
|
||||
```
|
||||
|
||||
Optional override for formatting stack traces
|
||||
|
||||
#### Parameters
|
||||
|
||||
* **err**: `Error`
|
||||
|
||||
* **stackTraces**: `CallSite`[]
|
||||
|
||||
#### Returns
|
||||
|
||||
`any`
|
||||
|
||||
#### See
|
||||
|
||||
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
|
||||
|
||||
#### Inherited from
|
||||
|
||||
`Error.prepareStackTrace`
|
||||
|
||||
***
|
||||
|
||||
### stackTraceLimit
|
||||
|
||||
```ts
|
||||
static stackTraceLimit: number;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
`Error.stackTraceLimit`
|
||||
|
||||
## Methods
|
||||
|
||||
### captureStackTrace()
|
||||
|
||||
```ts
|
||||
static captureStackTrace(targetObject, constructorOpt?): void
|
||||
```
|
||||
|
||||
Create .stack property on a target object
|
||||
|
||||
#### Parameters
|
||||
|
||||
* **targetObject**: `object`
|
||||
|
||||
* **constructorOpt?**: `Function`
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
#### Inherited from
|
||||
|
||||
`Error.captureStackTrace`
|
||||
@@ -525,6 +525,49 @@ Empty results retain the query's output schema.
|
||||
|
||||
***
|
||||
|
||||
### toResult()
|
||||
|
||||
```ts
|
||||
toResult(options?): Promise<QueryResult>
|
||||
```
|
||||
|
||||
Stream one execution and read its metadata after successful exhaustion.
|
||||
Tracking is off by default. Set `trackTotalHits` to `true` for an exact count
|
||||
before offset and limit, or to a positive integer for a capped count.
|
||||
At the cap, `totalHits.relation` is `"gte"`.
|
||||
|
||||
Embedded supports counts for unfiltered scans, scans with deterministic scalar
|
||||
filters, and row-level full-text searches for a single term or a positive OR
|
||||
of terms with supported prefilters. Requesting a count on an Enterprise table
|
||||
or an unsupported query, such as vector or hybrid search, throws
|
||||
`UnsupportedMetadataError`.
|
||||
|
||||
Counting can continue after the last data batch. Consume the iterator to EOF
|
||||
or await `result.finish()` before calling `result.metadata()`.
|
||||
|
||||
#### Parameters
|
||||
|
||||
* **options?**
|
||||
|
||||
* **options.trackTotalHits?**: `number` \| `bigint` \| `boolean`
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<[`QueryResult`](QueryResult.md)>
|
||||
|
||||
#### Example
|
||||
|
||||
```ts
|
||||
const result = await table.query().limit(1).toResult({ trackTotalHits: 100n });
|
||||
const hits = (await result.finish()).totalHits;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
`StandardQueryBase.toResult`
|
||||
|
||||
***
|
||||
|
||||
### useRTE()
|
||||
|
||||
```ts
|
||||
|
||||
@@ -258,6 +258,45 @@ Empty results retain the query's output schema.
|
||||
|
||||
***
|
||||
|
||||
### toResult()
|
||||
|
||||
```ts
|
||||
toResult(options?): Promise<QueryResult>
|
||||
```
|
||||
|
||||
Stream one execution and read its metadata after successful exhaustion.
|
||||
Tracking is off by default. Set `trackTotalHits` to `true` for an exact count
|
||||
before offset and limit, or to a positive integer for a capped count.
|
||||
At the cap, `totalHits.relation` is `"gte"`.
|
||||
|
||||
Embedded supports counts for unfiltered scans, scans with deterministic scalar
|
||||
filters, and row-level full-text searches for a single term or a positive OR
|
||||
of terms with supported prefilters. Requesting a count on an Enterprise table
|
||||
or an unsupported query, such as vector or hybrid search, throws
|
||||
`UnsupportedMetadataError`.
|
||||
|
||||
Counting can continue after the last data batch. Consume the iterator to EOF
|
||||
or await `result.finish()` before calling `result.metadata()`.
|
||||
|
||||
#### Parameters
|
||||
|
||||
* **options?**
|
||||
|
||||
* **options.trackTotalHits?**: `number` \| `bigint` \| `boolean`
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<[`QueryResult`](QueryResult.md)>
|
||||
|
||||
#### Example
|
||||
|
||||
```ts
|
||||
const result = await table.query().limit(1).toResult({ trackTotalHits: 100n });
|
||||
const hits = (await result.finish()).totalHits;
|
||||
```
|
||||
|
||||
***
|
||||
|
||||
### withRowId()
|
||||
|
||||
```ts
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
[**@lancedb/lancedb**](../README.md) • **Docs**
|
||||
|
||||
***
|
||||
|
||||
[@lancedb/lancedb](../globals.md) / QueryResult
|
||||
|
||||
# Class: QueryResult
|
||||
|
||||
One execution with pull-driven batches and final metadata.
|
||||
|
||||
## Implements
|
||||
|
||||
- `AsyncIterableIterator`<`RecordBatch`>
|
||||
|
||||
## Accessors
|
||||
|
||||
### batches
|
||||
|
||||
```ts
|
||||
get batches(): AsyncIterableIterator<RecordBatch<any>>
|
||||
```
|
||||
|
||||
#### Returns
|
||||
|
||||
`AsyncIterableIterator`<`RecordBatch`<`any`>>
|
||||
|
||||
## Methods
|
||||
|
||||
### \[asyncIterator\]()
|
||||
|
||||
```ts
|
||||
asyncIterator: AsyncIterableIterator<RecordBatch<any>>
|
||||
```
|
||||
|
||||
#### Returns
|
||||
|
||||
`AsyncIterableIterator`<`RecordBatch`<`any`>>
|
||||
|
||||
#### Implementation of
|
||||
|
||||
`AsyncIterableIterator.[asyncIterator]`
|
||||
|
||||
***
|
||||
|
||||
### close()
|
||||
|
||||
```ts
|
||||
close(): Promise<void>
|
||||
```
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<`void`>
|
||||
|
||||
***
|
||||
|
||||
### finish()
|
||||
|
||||
```ts
|
||||
finish(): Promise<QueryMetadata>
|
||||
```
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<[`QueryMetadata`](../interfaces/QueryMetadata.md)>
|
||||
|
||||
***
|
||||
|
||||
### metadata()
|
||||
|
||||
```ts
|
||||
metadata(): QueryMetadata
|
||||
```
|
||||
|
||||
Access the successful terminal metadata without polling the stream.
|
||||
|
||||
#### Returns
|
||||
|
||||
[`QueryMetadata`](../interfaces/QueryMetadata.md)
|
||||
|
||||
***
|
||||
|
||||
### next()
|
||||
|
||||
```ts
|
||||
next(): Promise<IteratorResult<RecordBatch<any>, any>>
|
||||
```
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<`IteratorResult`<`RecordBatch`<`any`>, `any`>>
|
||||
|
||||
#### Implementation of
|
||||
|
||||
`AsyncIterableIterator.next`
|
||||
|
||||
***
|
||||
|
||||
### return()
|
||||
|
||||
```ts
|
||||
return(): Promise<IteratorResult<RecordBatch<any>, any>>
|
||||
```
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<`IteratorResult`<`RecordBatch`<`any`>, `any`>>
|
||||
|
||||
#### Implementation of
|
||||
|
||||
`AsyncIterableIterator.return`
|
||||
@@ -277,6 +277,49 @@ Empty results retain the query's output schema.
|
||||
|
||||
***
|
||||
|
||||
### toResult()
|
||||
|
||||
```ts
|
||||
toResult(options?): Promise<QueryResult>
|
||||
```
|
||||
|
||||
Stream one execution and read its metadata after successful exhaustion.
|
||||
Tracking is off by default. Set `trackTotalHits` to `true` for an exact count
|
||||
before offset and limit, or to a positive integer for a capped count.
|
||||
At the cap, `totalHits.relation` is `"gte"`.
|
||||
|
||||
Embedded supports counts for unfiltered scans, scans with deterministic scalar
|
||||
filters, and row-level full-text searches for a single term or a positive OR
|
||||
of terms with supported prefilters. Requesting a count on an Enterprise table
|
||||
or an unsupported query, such as vector or hybrid search, throws
|
||||
`UnsupportedMetadataError`.
|
||||
|
||||
Counting can continue after the last data batch. Consume the iterator to EOF
|
||||
or await `result.finish()` before calling `result.metadata()`.
|
||||
|
||||
#### Parameters
|
||||
|
||||
* **options?**
|
||||
|
||||
* **options.trackTotalHits?**: `number` \| `bigint` \| `boolean`
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<[`QueryResult`](QueryResult.md)>
|
||||
|
||||
#### Example
|
||||
|
||||
```ts
|
||||
const result = await table.query().limit(1).toResult({ trackTotalHits: 100n });
|
||||
const hits = (await result.finish()).totalHits;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`QueryBase`](QueryBase.md).[`toResult`](QueryBase.md#toresult)
|
||||
|
||||
***
|
||||
|
||||
### useRTE()
|
||||
|
||||
```ts
|
||||
|
||||
@@ -0,0 +1,459 @@
|
||||
[**@lancedb/lancedb**](../README.md) • **Docs**
|
||||
|
||||
***
|
||||
|
||||
[@lancedb/lancedb](../globals.md) / UnsupportedMetadataError
|
||||
|
||||
# Class: UnsupportedMetadataError
|
||||
|
||||
The requested final metadata is unavailable for this query.
|
||||
|
||||
## Extends
|
||||
|
||||
- [`LanceError`](LanceError.md)
|
||||
|
||||
## Constructors
|
||||
|
||||
### new UnsupportedMetadataError()
|
||||
|
||||
```ts
|
||||
new UnsupportedMetadataError(message, options?): UnsupportedMetadataError
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
* **message**: `string`
|
||||
|
||||
* **options?**: [`LanceErrorOptions`](../interfaces/LanceErrorOptions.md)
|
||||
|
||||
#### Returns
|
||||
|
||||
[`UnsupportedMetadataError`](UnsupportedMetadataError.md)
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LanceError`](LanceError.md).[`constructor`](LanceError.md#constructors)
|
||||
|
||||
## Properties
|
||||
|
||||
### cause?
|
||||
|
||||
```ts
|
||||
optional cause: unknown;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LanceError`](LanceError.md).[`cause`](LanceError.md#cause)
|
||||
|
||||
***
|
||||
|
||||
### code
|
||||
|
||||
```ts
|
||||
readonly code: string;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LanceError`](LanceError.md).[`code`](LanceError.md#code)
|
||||
|
||||
***
|
||||
|
||||
### columnName?
|
||||
|
||||
```ts
|
||||
readonly optional columnName: string;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LanceError`](LanceError.md).[`columnName`](LanceError.md#columnname)
|
||||
|
||||
***
|
||||
|
||||
### connectFailures?
|
||||
|
||||
```ts
|
||||
readonly optional connectFailures: number;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LanceError`](LanceError.md).[`connectFailures`](LanceError.md#connectfailures)
|
||||
|
||||
***
|
||||
|
||||
### databaseName?
|
||||
|
||||
```ts
|
||||
readonly optional databaseName: string;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LanceError`](LanceError.md).[`databaseName`](LanceError.md#databasename)
|
||||
|
||||
***
|
||||
|
||||
### errorCode?
|
||||
|
||||
```ts
|
||||
readonly optional errorCode: string;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LanceError`](LanceError.md).[`errorCode`](LanceError.md#errorcode)
|
||||
|
||||
***
|
||||
|
||||
### functionName?
|
||||
|
||||
```ts
|
||||
readonly optional functionName: string;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LanceError`](LanceError.md).[`functionName`](LanceError.md#functionname)
|
||||
|
||||
***
|
||||
|
||||
### grpcCode?
|
||||
|
||||
```ts
|
||||
readonly optional grpcCode: number;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LanceError`](LanceError.md).[`grpcCode`](LanceError.md#grpccode)
|
||||
|
||||
***
|
||||
|
||||
### indexName?
|
||||
|
||||
```ts
|
||||
readonly optional indexName: string;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LanceError`](LanceError.md).[`indexName`](LanceError.md#indexname)
|
||||
|
||||
***
|
||||
|
||||
### jobId?
|
||||
|
||||
```ts
|
||||
readonly optional jobId: string;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LanceError`](LanceError.md).[`jobId`](LanceError.md#jobid)
|
||||
|
||||
***
|
||||
|
||||
### jobRequestId?
|
||||
|
||||
```ts
|
||||
readonly optional jobRequestId: string;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LanceError`](LanceError.md).[`jobRequestId`](LanceError.md#jobrequestid)
|
||||
|
||||
***
|
||||
|
||||
### maxConnectFailures?
|
||||
|
||||
```ts
|
||||
readonly optional maxConnectFailures: number;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LanceError`](LanceError.md).[`maxConnectFailures`](LanceError.md#maxconnectfailures)
|
||||
|
||||
***
|
||||
|
||||
### maxReadFailures?
|
||||
|
||||
```ts
|
||||
readonly optional maxReadFailures: number;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LanceError`](LanceError.md).[`maxReadFailures`](LanceError.md#maxreadfailures)
|
||||
|
||||
***
|
||||
|
||||
### maxRequestFailures?
|
||||
|
||||
```ts
|
||||
readonly optional maxRequestFailures: number;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LanceError`](LanceError.md).[`maxRequestFailures`](LanceError.md#maxrequestfailures)
|
||||
|
||||
***
|
||||
|
||||
### message
|
||||
|
||||
```ts
|
||||
message: string;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LanceError`](LanceError.md).[`message`](LanceError.md#message)
|
||||
|
||||
***
|
||||
|
||||
### name
|
||||
|
||||
```ts
|
||||
name: string;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LanceError`](LanceError.md).[`name`](LanceError.md#name)
|
||||
|
||||
***
|
||||
|
||||
### namespacePath?
|
||||
|
||||
```ts
|
||||
readonly optional namespacePath: string[];
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LanceError`](LanceError.md).[`namespacePath`](LanceError.md#namespacepath)
|
||||
|
||||
***
|
||||
|
||||
### path?
|
||||
|
||||
```ts
|
||||
readonly optional path: string;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LanceError`](LanceError.md).[`path`](LanceError.md#path)
|
||||
|
||||
***
|
||||
|
||||
### phase?
|
||||
|
||||
```ts
|
||||
readonly optional phase: string;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LanceError`](LanceError.md).[`phase`](LanceError.md#phase)
|
||||
|
||||
***
|
||||
|
||||
### readFailures?
|
||||
|
||||
```ts
|
||||
readonly optional readFailures: number;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LanceError`](LanceError.md).[`readFailures`](LanceError.md#readfailures)
|
||||
|
||||
***
|
||||
|
||||
### requestFailures?
|
||||
|
||||
```ts
|
||||
readonly optional requestFailures: number;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LanceError`](LanceError.md).[`requestFailures`](LanceError.md#requestfailures)
|
||||
|
||||
***
|
||||
|
||||
### requestId?
|
||||
|
||||
```ts
|
||||
readonly optional requestId: string;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LanceError`](LanceError.md).[`requestId`](LanceError.md#requestid)
|
||||
|
||||
***
|
||||
|
||||
### resourceKind?
|
||||
|
||||
```ts
|
||||
readonly optional resourceKind: string;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LanceError`](LanceError.md).[`resourceKind`](LanceError.md#resourcekind)
|
||||
|
||||
***
|
||||
|
||||
### resourceName?
|
||||
|
||||
```ts
|
||||
readonly optional resourceName: string;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LanceError`](LanceError.md).[`resourceName`](LanceError.md#resourcename)
|
||||
|
||||
***
|
||||
|
||||
### retryable?
|
||||
|
||||
```ts
|
||||
readonly optional retryable: boolean;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LanceError`](LanceError.md).[`retryable`](LanceError.md#retryable)
|
||||
|
||||
***
|
||||
|
||||
### sqlJobId?
|
||||
|
||||
```ts
|
||||
readonly optional sqlJobId: string;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LanceError`](LanceError.md).[`sqlJobId`](LanceError.md#sqljobid)
|
||||
|
||||
***
|
||||
|
||||
### stack?
|
||||
|
||||
```ts
|
||||
optional stack: string;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LanceError`](LanceError.md).[`stack`](LanceError.md#stack)
|
||||
|
||||
***
|
||||
|
||||
### statusCode?
|
||||
|
||||
```ts
|
||||
readonly optional statusCode: number;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LanceError`](LanceError.md).[`statusCode`](LanceError.md#statuscode)
|
||||
|
||||
***
|
||||
|
||||
### tableName?
|
||||
|
||||
```ts
|
||||
readonly optional tableName: string;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LanceError`](LanceError.md).[`tableName`](LanceError.md#tablename)
|
||||
|
||||
***
|
||||
|
||||
### code
|
||||
|
||||
```ts
|
||||
readonly static code: "UnsupportedMetadata" = "UnsupportedMetadata";
|
||||
```
|
||||
|
||||
#### Overrides
|
||||
|
||||
[`LanceError`](LanceError.md).[`code`](LanceError.md#code-1)
|
||||
|
||||
***
|
||||
|
||||
### prepareStackTrace()?
|
||||
|
||||
```ts
|
||||
static optional prepareStackTrace: (err, stackTraces) => any;
|
||||
```
|
||||
|
||||
Optional override for formatting stack traces
|
||||
|
||||
#### Parameters
|
||||
|
||||
* **err**: `Error`
|
||||
|
||||
* **stackTraces**: `CallSite`[]
|
||||
|
||||
#### Returns
|
||||
|
||||
`any`
|
||||
|
||||
#### See
|
||||
|
||||
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LanceError`](LanceError.md).[`prepareStackTrace`](LanceError.md#preparestacktrace)
|
||||
|
||||
***
|
||||
|
||||
### stackTraceLimit
|
||||
|
||||
```ts
|
||||
static stackTraceLimit: number;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LanceError`](LanceError.md).[`stackTraceLimit`](LanceError.md#stacktracelimit)
|
||||
|
||||
## Methods
|
||||
|
||||
### captureStackTrace()
|
||||
|
||||
```ts
|
||||
static captureStackTrace(targetObject, constructorOpt?): void
|
||||
```
|
||||
|
||||
Create .stack property on a target object
|
||||
|
||||
#### Parameters
|
||||
|
||||
* **targetObject**: `object`
|
||||
|
||||
* **constructorOpt?**: `Function`
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LanceError`](LanceError.md).[`captureStackTrace`](LanceError.md#capturestacktrace)
|
||||
@@ -836,6 +836,49 @@ Empty results retain the query's output schema.
|
||||
|
||||
***
|
||||
|
||||
### toResult()
|
||||
|
||||
```ts
|
||||
toResult(options?): Promise<QueryResult>
|
||||
```
|
||||
|
||||
Stream one execution and read its metadata after successful exhaustion.
|
||||
Tracking is off by default. Set `trackTotalHits` to `true` for an exact count
|
||||
before offset and limit, or to a positive integer for a capped count.
|
||||
At the cap, `totalHits.relation` is `"gte"`.
|
||||
|
||||
Embedded supports counts for unfiltered scans, scans with deterministic scalar
|
||||
filters, and row-level full-text searches for a single term or a positive OR
|
||||
of terms with supported prefilters. Requesting a count on an Enterprise table
|
||||
or an unsupported query, such as vector or hybrid search, throws
|
||||
`UnsupportedMetadataError`.
|
||||
|
||||
Counting can continue after the last data batch. Consume the iterator to EOF
|
||||
or await `result.finish()` before calling `result.metadata()`.
|
||||
|
||||
#### Parameters
|
||||
|
||||
* **options?**
|
||||
|
||||
* **options.trackTotalHits?**: `number` \| `bigint` \| `boolean`
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<[`QueryResult`](QueryResult.md)>
|
||||
|
||||
#### Example
|
||||
|
||||
```ts
|
||||
const result = await table.query().limit(1).toResult({ trackTotalHits: 100n });
|
||||
const hits = (await result.finish()).totalHits;
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
`StandardQueryBase.toResult`
|
||||
|
||||
***
|
||||
|
||||
### useRTE()
|
||||
|
||||
```ts
|
||||
|
||||
@@ -56,6 +56,8 @@
|
||||
- [MatchQuery](classes/MatchQuery.md)
|
||||
- [MaterializedView](classes/MaterializedView.md)
|
||||
- [MergeInsertBuilder](classes/MergeInsertBuilder.md)
|
||||
- [MetadataCancelledError](classes/MetadataCancelledError.md)
|
||||
- [MetadataPendingError](classes/MetadataPendingError.md)
|
||||
- [MultiMatchQuery](classes/MultiMatchQuery.md)
|
||||
- [NativeJsHeaderProvider](classes/NativeJsHeaderProvider.md)
|
||||
- [NotAComputedColumnError](classes/NotAComputedColumnError.md)
|
||||
@@ -69,6 +71,7 @@
|
||||
- [PhraseQuery](classes/PhraseQuery.md)
|
||||
- [Query](classes/Query.md)
|
||||
- [QueryBase](classes/QueryBase.md)
|
||||
- [QueryResult](classes/QueryResult.md)
|
||||
- [RetryError](classes/RetryError.md)
|
||||
- [Scannable](classes/Scannable.md)
|
||||
- [SchemaError](classes/SchemaError.md)
|
||||
@@ -84,6 +87,7 @@
|
||||
- [Tags](classes/Tags.md)
|
||||
- [TakeQuery](classes/TakeQuery.md)
|
||||
- [TimeoutError](classes/TimeoutError.md)
|
||||
- [UnsupportedMetadataError](classes/UnsupportedMetadataError.md)
|
||||
- [VectorColumnOptions](classes/VectorColumnOptions.md)
|
||||
- [VectorQuery](classes/VectorQuery.md)
|
||||
|
||||
@@ -186,6 +190,7 @@
|
||||
- [PrewarmDataResult](interfaces/PrewarmDataResult.md)
|
||||
- [PrewarmPruningSummary](interfaces/PrewarmPruningSummary.md)
|
||||
- [QueryExecutionOptions](interfaces/QueryExecutionOptions.md)
|
||||
- [QueryMetadata](interfaces/QueryMetadata.md)
|
||||
- [RTEStats](interfaces/RTEStats.md)
|
||||
- [RTEWriteSpec](interfaces/RTEWriteSpec.md)
|
||||
- [RTreeOptions](interfaces/RTreeOptions.md)
|
||||
@@ -217,6 +222,7 @@
|
||||
- [TokenCacheOptions](interfaces/TokenCacheOptions.md)
|
||||
- [TokenResponse](interfaces/TokenResponse.md)
|
||||
- [TokenizeOptions](interfaces/TokenizeOptions.md)
|
||||
- [TotalHits](interfaces/TotalHits.md)
|
||||
- [UpdateFieldMetadataResult](interfaces/UpdateFieldMetadataResult.md)
|
||||
- [UpdateOptions](interfaces/UpdateOptions.md)
|
||||
- [UpdateResult](interfaces/UpdateResult.md)
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
[**@lancedb/lancedb**](../README.md) • **Docs**
|
||||
|
||||
***
|
||||
|
||||
[@lancedb/lancedb](../globals.md) / QueryMetadata
|
||||
|
||||
# Interface: QueryMetadata
|
||||
|
||||
## Properties
|
||||
|
||||
### totalHits?
|
||||
|
||||
```ts
|
||||
readonly optional totalHits: TotalHits;
|
||||
```
|
||||
@@ -0,0 +1,23 @@
|
||||
[**@lancedb/lancedb**](../README.md) • **Docs**
|
||||
|
||||
***
|
||||
|
||||
[@lancedb/lancedb](../globals.md) / TotalHits
|
||||
|
||||
# Interface: TotalHits
|
||||
|
||||
## Properties
|
||||
|
||||
### relation
|
||||
|
||||
```ts
|
||||
readonly relation: "eq" | "gte";
|
||||
```
|
||||
|
||||
***
|
||||
|
||||
### value
|
||||
|
||||
```ts
|
||||
readonly value: bigint;
|
||||
```
|
||||
@@ -910,6 +910,37 @@ of raw SQL strings with [where][lancedb.query.LanceQueryBuilder.where] and
|
||||
|
||||
::: lancedb.query.Query
|
||||
|
||||
Use `query.to_result(track_total_hits=True)` to stream a page and read its exact
|
||||
pre-pagination count after EOF. A positive integer up to `2**64 - 1` requests a
|
||||
capped count. At the cap, `relation` is `"gte"`. Call `result.close()` or use a
|
||||
context manager to cancel an unfinished read.
|
||||
|
||||
Embedded scalar queries and supported row-level lexical queries can request counts.
|
||||
A requested count on an unsupported plan raises
|
||||
`lancedb.exceptions.UnsupportedMetadata` before yielding batches. The rich terminal
|
||||
supports `with_row_address()` on plain Embedded scans. Each returned row's
|
||||
`_rowaddr` identifies its physical fragment and offset in the query snapshot.
|
||||
`with_fragments()` and `fragment_ids()` raise `UnsupportedMetadata`.
|
||||
Before EOF, `metadata()` raises `MetadataPending`.
|
||||
An early close raises `MetadataCancelled` on subsequent access. Stream failures
|
||||
retain the underlying exception, including its request ID when supplied. An
|
||||
explicit count can still take time or fail after the final data batch. For
|
||||
example, a full-text query may scan visible text to establish the count.
|
||||
|
||||
```python
|
||||
with table.search().where("year >= 2020").limit(10).to_result(track_total_hits=100) as result:
|
||||
for batch in result.batches:
|
||||
print(batch.num_rows)
|
||||
hits = result.metadata().total_hits
|
||||
print(hits.relation, hits.value) # "gte", 100 if at least 100 rows match
|
||||
```
|
||||
|
||||
::: lancedb.query_result.QueryResult
|
||||
|
||||
::: lancedb.query_result.QueryMetadata
|
||||
|
||||
::: lancedb.query_result.TotalHits
|
||||
|
||||
::: lancedb.query.ColumnOrdering
|
||||
|
||||
::: lancedb.query.LanceQueryBuilder
|
||||
@@ -1469,6 +1500,17 @@ to return the entire (typically filtered) table. Vector searches return the
|
||||
rows nearest to a query vector and can be created with the
|
||||
[AsyncTable.vector_search][lancedb.table.AsyncTable.vector_search] method.
|
||||
|
||||
Use an async context manager to release an unfinished query when leaving the
|
||||
loop early. Read the count after the iterator reaches EOF.
|
||||
|
||||
```python
|
||||
async with await table.query().limit(10).to_result(track_total_hits=True) as result:
|
||||
async for batch in result.batches:
|
||||
print(batch.num_rows)
|
||||
print(result.metadata().total_hits.value)
|
||||
```
|
||||
|
||||
::: lancedb.query_result.AsyncQueryResult
|
||||
|
||||
::: lancedb.query.AsyncQuery
|
||||
options:
|
||||
|
||||
Reference in New Issue
Block a user