mirror of
https://github.com/lancedb/lancedb.git
synced 2026-11-26 20:44:00 +00:00
Remote data prewarm used REST even though SQL supported filters and concurrency, and both maintenance APIs returned after acceptance without exposing a consistent typed completion handle. Compaction's legacy statistics therefore could not describe the work committed by its durable job. This PR adds job-returning compaction and data-prewarm methods across Rust, Python sync/async and TypeScript, and moves data-prewarm submission to SQL. Legacy methods retain return-after-acceptance behavior; data prewarm now requires a compatible SQL PREWARM server and Flight SQL connectivity. This consolidates #5037, #5055 and #4906. This was accomplished with the following changes: - Added `compact_async()` / `compactAsync()` and `prewarm_data_async()` / `prewarmDataAsync()`, retaining the command receipt's durable job ID. - Added `PrewarmDataOptions` for columns, a metadata-pruning filter and concurrency; both operations inherit database, namespace and branch from the table handle. - Added filter/concurrency arguments to legacy Python `prewarm_data()` and a TypeScript `prewarmData(options)` overload, preserving the columns-array form and discarding the handle after acceptance. - Added typed `CompactionResult` and `PrewarmDataResult` decoding, including reopened jobs; missing result payloads fail explicitly and omitted measurements remain unknown. - Reused the shared Job lifecycle for status, refresh, progress callbacks, cancellation and events; Python maintenance progress bars display rewritten rows or completed executors. - Added TypeScript `wait({ timeoutMs, onProgress })` and Rust `wait_with_options(JobWaitOptions)`, complementing Python's existing timeout argument without cancelling the durable job. - Validated single unambiguous receipts, preserved compaction option presence/default inheritance, and returned actionable unsupported-server errors without dropping options or falling back to REST. - Updated native bindings, API references and maintenance documentation with job methods, result semantics, tuning and compatibility requirements. ### Usage and behaviour **New** = added here; **Enhanced** = existing support extended; **Existing** = already on main. This table describes remote SDK behavior; server-side SQL/CLI capabilities are prerequisites, not additions made by this SDK PR. | Surface | Capability | Compact | Data prewarm | Assessment | | --- | --- | --- | --- | --- | | Rust / Python sync+async / TypeScript | Submission transport | Existing SQL OPTIMIZE | **New:** REST → SQL PREWARM | Both now submit through SQL | | All SDKs | Durable job-returning API | **New:** `compact_async` / `compactAsync` | **New:** `prewarm_data_async` / `prewarmDataAsync` | Same lifecycle model | | All SDKs | Options and target scope | **New handle:** four existing compaction overrides, with omitted fields inherited | **New options:** columns/filter/concurrency | Namespace and branch preserved for both | | Python / TypeScript | Legacy convenience calls | Existing optimize acceptance behavior preserved | **Enhanced:** legacy methods accept filter/concurrency and use SQL | Return after acceptance; no completion wait | | All SDKs | Typed successful result | **New:** committed rows, file/fragment changes, partial commit and `more_work` | **New:** pinned version, fragments and executor outcomes | Different measurements are intentional | | All SDKs | Status / refresh / progress | Existing Job APIs reused by **new** maintenance handle | Existing Job APIs reused by **new** maintenance handle | HTTP monitoring remains | | Python / TypeScript | Progress presentation | **Enhanced:** rewrite rows/groups | **Enhanced:** executor progress | Shared callbacks; Python bars use operation counters | | All SDKs | Bounded wait | Python existing; **new** TS/Rust timeout controls | Same shared timeout support | Timeout stops this wait; job continues | | All SDKs | Reopen and await typed outcome | **New:** compaction result decoding on reopened handle | **New:** prewarm result decoding on reopened handle | Rust selects the typed result explicitly | | All SDKs | Cancel / events | Existing shared APIs available on **new** handle | Same | HTTP underneath; permissions unchanged | | All SDKs | Typed preview helper | Unavailable | Unavailable | General SQL where exposed; no helper added | | Authorization | Submission | Existing table Ownership plus parent Usage | SQL path uses Select plus parent Usage | Intentional difference | | All SDKs | Local / historical handles | New durable API rejects them | New durable API rejects them | Remote current-branch jobs only | ```python from datetime import timedelta # Legacy convenience call: returns None after acceptance. table.prewarm_data(["payload"], filter="id >= 1000", concurrency=4) warm = table.prewarm_data_async(["payload"], filter="id >= 1000", concurrency=4) warmed = warm.wait(timeout=timedelta(minutes=10), progress=print) print(warmed.table_version, warmed.executors_completed) compact = table.compact_async(compaction_options={"max_source_rows": 1000000}) committed = compact.wait(timeout=timedelta(minutes=10), progress=print) print(committed.rows_succeeded, committed.fragments_removed, committed.more_work) reopened_result = db.open_job(compact.id).wait() ``` ```typescript await table.prewarmData({ columns: ["payload"], filter: "id >= 1000", concurrency: 4 }); const job = await table.prewarmDataAsync({ columns: ["payload"], filter: "id >= 1000", concurrency: 4, }); const result = await job.wait({ timeoutMs: 600_000, onProgress: console.log }); ``` ```rust use std::time::Duration; use lancedb::job::JobWaitOptions; let job = table.compact_async(Default::default()).await?; let result = job.wait_with_options( JobWaitOptions::new().timeout(Duration::from_secs(600)), ).await?; ``` Python async tables await both submission and Job methods. Rust's legacy `prewarm_data(columns)` keeps its columns-only signature; use `PrewarmDataOptions` on the new job-returning method for filtering/concurrency. Wait deadlines cover pending status requests and polling delays. Existing `wait()`, TypeScript `wait(callback)` and Rust `wait_with_progress(callback)` remain supported. Status/progress/refresh/cancel/events still use generic HTTP job APIs; those endpoints and their read/event/cancel permissions must remain available. Cancelling or timing out does not roll back committed work. Compaction results describe committed rewrites and include deletion files in file counts. Prewarm results describe work against a pinned snapshot, with partial executors included in completed executors; nonempty byte/range measurements remain unknown. Missing results require compatible server/worker support rather than placeholder zero statistics. Filtering uses conservative metadata pruning, not an exact row-filter scan. ### Testing Six checked-in live Python sync/async cases pass against matching server/worker builds for compaction, job-returning prewarm and legacy filtered submission. Ten additional live Node scenarios pass for legacy/default/options forms, filters/concurrency, empty plans, validation, persisted specifications and readback. Targeted regressions pass: Python remote maintenance (80), shared jobs (82), local prewarm rejection (4); Node remote (107) and prewarm API cases (28), plus the previously exercised Rust remote regressions. Tests cover receipt parsing, typed results, reopening, unknown measurements, timeouts, and legacy calls returning None/undefined without polling. Dependency pins are unchanged. Azure account-hint acknowledgment was verified locally with filesystem storage; real Azure-backed storage still needs deployment-specific validation.
100 lines
5.1 KiB
Plaintext
100 lines
5.1 KiB
Plaintext
---
|
|
title: "Incremental Indexing"
|
|
sidebarTitle: "Incremental Indexing"
|
|
description: "Keep an index up-to-date as new data arrives, without a full rebuild."
|
|
icon: "refresh"
|
|
keywords: ["reindexing", "re-index", "incremental indexing", "reindex", "index_remap", "spfresh_merge"]
|
|
availability:
|
|
embedded: available
|
|
enterprise: available
|
|
---
|
|
|
|
import {
|
|
PyReindexingIncremental as ReindexingIncremental,
|
|
} from '/snippets/indexing.mdx';
|
|
|
|
As you add new data to your LanceDB tables, your indexes may become outdated.
|
|
Reindexing is the process of updating the index to account for new data. This
|
|
applies to either a full-text search (FTS) index or a vector index.
|
|
Reindexing is an important operation to run periodically as your data grows,
|
|
as it has performance implications.
|
|
|
|
As data is being added and a reindex operation is running, LanceDB will
|
|
combine results from the existing index with exhaustive/flat search on the
|
|
new data. This is done to ensure that you're still retrieving results over
|
|
all your data, but it does come at a performance cost. The more data that you
|
|
add without reindexing, the impact on latency (due to exhaustive search) can
|
|
be noticeable.
|
|
|
|
Rather than dropping an existing index entirely and reindexing from scratch,
|
|
LanceDB supports **incremental indexing**.
|
|
|
|
<Note>
|
|
**Enterprise job types:** an index build runs as `reindex_` followed by the
|
|
algorithm, such as `reindex_ivf_pq`, `reindex_btree` or `reindex_fts`, and so
|
|
does folding new rows into an existing index. A create-only build, one that must
|
|
not replace an existing index, runs as `create_` followed by the algorithm
|
|
instead; Python's `create_scalar_index` and `create_fts_index` ask for that by
|
|
default. The name says which algorithm is building, not a separate feature.
|
|
</Note>
|
|
|
|
## Triggering an incremental update {#incremental-reindexing}
|
|
|
|
In the embedded library, you trigger an incremental indexing operation on
|
|
updated data with the `optimize()` method on a table. LanceDB Enterprise updates
|
|
indexes in the background. Its [manual `optimize()` path](/maintenance/compaction#enterprise-manual-compaction)
|
|
submits compaction only and does not trigger incremental index updates.
|
|
|
|
In LanceDB Embedded, table optimization performs three maintenance operations:
|
|
|
|
1. **Compaction**: merges small fragments into larger ones to improve read performance
|
|
2. **Pruning/Cleanup**: removes files from versions older than a retention window (7 days by default) -- see [Cleanup](/maintenance/cleanup) for how retention works
|
|
3. **Index update**: adds newly-ingested data to existing vector, scalar, and FTS indexes
|
|
|
|
<CodeGroup>
|
|
<CodeBlock filename="Python" language="Python" icon="python">
|
|
{ReindexingIncremental}
|
|
</CodeBlock>
|
|
</CodeGroup>
|
|
|
|
<Badge color="red">Enterprise</Badge>
|
|
|
|
LanceDB Enterprise supports incremental reindexing through an automated background process. Once enough new rows have been added to a table, the system automatically adds them to its indexes. As the dataset grows, indexes are asynchronously updated in the background.
|
|
|
|
- While indexes are being rebuilt, queries use brute force methods on unindexed rows, which may temporarily increase latency. If you can omit unindexed rows, set `fast_search=True` to search only indexed data.
|
|
This can return incomplete results while indexing catches up.
|
|
- Use `index_stats()` to view the number of unindexed rows. This will be zero when indexes are fully up-to-date. If you call `wait_for_index(...)`, it polls the same status and can time out while continuous writes keep adding unindexed rows.
|
|
- Rows below the deployment's threshold stay unindexed until more arrive, so the count can stay above zero without further writes. `FM` indexes are not updated in the background.
|
|
|
|
The benefit of using LanceDB Enterprise is that it automates the reindexing process
|
|
and operates continuously in the background, minimizing the impact on latency under high loads.
|
|
In LanceDB Embedded, you must manually manage the reindexing cadence based on your data growth and performance needs.
|
|
Opening a table in LanceDB Embedded logs a warning at most once per table per
|
|
process when any index has at least 1,000,000 unindexed rows. Set
|
|
`LANCEDB_LOG=warn` to surface this log if your logger hides warnings by default.
|
|
|
|
## Index maintenance jobs {#index}
|
|
|
|
Two further Enterprise job types keep an index correct as the rows underneath
|
|
it move, rather than adding new rows to it:
|
|
|
|
| Job type | What it does |
|
|
| --- | --- |
|
|
| `index_remap` | Reassigns index entries after row ids shift underneath an index (the kind of remap a delta compaction can require). |
|
|
| `spfresh_merge` | Merges SPFresh-managed segments for indexes that use it. |
|
|
|
|
See [Advanced Conflict Resolution](/enterprise/advanced-conflict-resolution)
|
|
for why `index_remap` exists as a separate, deferred job rather than
|
|
happening synchronously inside every compaction.
|
|
|
|
## What to read next {#next}
|
|
|
|
<CardGroup cols={2}>
|
|
<Card title="Distributed Indexing" icon="diagram-project" href="/enterprise/distributed-indexing">
|
|
How an index build itself scales across the jobs fleet.
|
|
</Card>
|
|
<Card title="GPU Indexing" icon="microchip" href="/indexing/gpu-indexing">
|
|
Building a vector index faster with GPU acceleration.
|
|
</Card>
|
|
</CardGroup>
|