mirror of
https://github.com/lancedb/lancedb.git
synced 2026-11-27 04:53:59 +00:00
refactor(sdk)!: standardize compaction APIs on Optimize
BREAKING CHANGE: Replace compact_async/compactAsync with optimize_async/optimizeAsync, Rust compact(overrides) with optimize(overrides), and Python compact_files() with optimize(action="rewrite_data"). No compatibility aliases are retained.
This commit is contained in:
@@ -305,40 +305,6 @@ It is a no-op when no writers are cached.
|
||||
|
||||
***
|
||||
|
||||
### compactAsync()
|
||||
|
||||
```ts
|
||||
compactAsync(_options?): Promise<Job<CompactionResult>>
|
||||
```
|
||||
|
||||
Submit remote compaction and return its durable job after acceptance.
|
||||
|
||||
Uses SQL OPTIMIZE, inheriting branch and namespace from this table. Requires
|
||||
a compatible remote server and table Ownership plus parent Usage. Local and
|
||||
historical-version handles are unsupported. Existing optimize() behavior is unchanged.
|
||||
Waiting tracks the rewrite itself and returns actual row/file statistics.
|
||||
Missing result payloads are errors; older workers can omit file counts.
|
||||
Status, progress, events and cancellation reuse the generic HTTP job APIs.
|
||||
Reopen with db.openJob<CompactionResult>(job.id!). A wait timeout does not cancel work.
|
||||
|
||||
#### Parameters
|
||||
|
||||
* **\_options?**: [`CompactionOptions`](../interfaces/CompactionOptions.md)
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<[`Job`](Job.md)<[`CompactionResult`](../interfaces/CompactionResult.md)>>
|
||||
|
||||
#### Example
|
||||
|
||||
```ts
|
||||
const job = await table.compactAsync({ targetRowsPerFragment: 1000 });
|
||||
const result = await job.wait();
|
||||
console.log(result.rowsSucceeded, result.fragmentsRemoved);
|
||||
```
|
||||
|
||||
***
|
||||
|
||||
### compactRTE()
|
||||
|
||||
```ts
|
||||
@@ -561,8 +527,8 @@ Drop one or more columns from the dataset
|
||||
|
||||
This is a metadata-only operation and does not remove the data from the
|
||||
underlying storage. In order to remove the data, you must subsequently
|
||||
call ``compact_files`` to rewrite the data without the removed columns and
|
||||
then call ``cleanup_files`` to remove the old files.
|
||||
call `optimize({ action: "rewrite_data" })` to rewrite the data without the
|
||||
removed columns, then prune old versions using Optimize cleanup options.
|
||||
|
||||
Local tables reject dropping source or vector columns referenced by
|
||||
`embedding_functions` schema metadata, preserving the embedding binding.
|
||||
@@ -1117,8 +1083,8 @@ Modeled after ``VACUUM`` in PostgreSQL.
|
||||
On a LanceDB Enterprise (remote) table, only compaction is currently
|
||||
supported. Pruning old versions and index optimization are silently
|
||||
skipped there instead of being attempted, so this call resolves
|
||||
successfully, with zeroed pruning statistics, once the compaction job
|
||||
has been submitted; it does not wait for that job to finish.
|
||||
successfully with placeholder statistics (not completed work) once the
|
||||
compaction job has been submitted; it does not wait for that job to finish.
|
||||
`compactionOptions` can tune the four per-job settings documented in
|
||||
[CompactionOptions](../interfaces/CompactionOptions.md). Older-server errors are propagated without
|
||||
retrying with the settings removed.
|
||||
@@ -1133,6 +1099,40 @@ retrying with the settings removed.
|
||||
|
||||
***
|
||||
|
||||
### optimizeAsync()
|
||||
|
||||
```ts
|
||||
optimizeAsync(_options?): Promise<Job<CompactionResult>>
|
||||
```
|
||||
|
||||
Submit remote compaction and return its durable job after acceptance.
|
||||
|
||||
Uses SQL OPTIMIZE, inheriting branch and namespace from this table. Requires
|
||||
a compatible remote server and table Ownership plus parent Usage. Local and
|
||||
historical-version handles are unsupported. Existing optimize() behavior is unchanged.
|
||||
Waiting tracks the rewrite itself and returns actual row/file statistics.
|
||||
Missing result payloads are errors; older workers can omit file counts.
|
||||
Status, progress, events and cancellation reuse the generic HTTP job APIs.
|
||||
Reopen with db.openJob<CompactionResult>(job.id!). A wait timeout does not cancel work.
|
||||
|
||||
#### Parameters
|
||||
|
||||
* **\_options?**: [`CompactionOptions`](../interfaces/CompactionOptions.md)
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<[`Job`](Job.md)<[`CompactionResult`](../interfaces/CompactionResult.md)>>
|
||||
|
||||
#### Example
|
||||
|
||||
```ts
|
||||
const job = await table.optimizeAsync({ targetRowsPerFragment: 1000 });
|
||||
const result = await job.wait();
|
||||
console.log(result.rowsSucceeded, result.fragmentsRemoved);
|
||||
```
|
||||
|
||||
***
|
||||
|
||||
### prewarmData()
|
||||
|
||||
#### prewarmData(options)
|
||||
|
||||
@@ -8,6 +8,18 @@
|
||||
|
||||
## Properties
|
||||
|
||||
### action?
|
||||
|
||||
```ts
|
||||
optional action: "rewrite_data";
|
||||
```
|
||||
|
||||
Run only data compaction, preserving versions and skipping separate index
|
||||
maintenance. Omit for Embedded's full maintenance cycle. Cannot be combined
|
||||
with cleanup options. Enterprise always submits data compaction only.
|
||||
|
||||
***
|
||||
|
||||
### cleanupOlderThan
|
||||
|
||||
```ts
|
||||
|
||||
@@ -142,14 +142,14 @@ indexes, and removes old table versions. LanceDB Enterprise schedules that work
|
||||
through separate background jobs and also accepts explicit compaction requests
|
||||
with compatible releases.
|
||||
|
||||
Python sync/async `compact_async()`, TypeScript `compactAsync()`, and Rust
|
||||
`Table::compact_async(CompactionOverrides)` return durable compaction job handles;
|
||||
waiting returns the committed rewrite statistics. Legacy remote `optimize()`
|
||||
and Rust `Table::compact()` return after submission with placeholder counts.
|
||||
Python sync/async `optimize_async()`, TypeScript `optimizeAsync()`, and Rust
|
||||
`Table::optimize_async(CompactionOverrides)` return durable compaction job handles;
|
||||
waiting returns the committed rewrite statistics. Remote `optimize()`
|
||||
returns after submission with placeholder counts.
|
||||
Remote optimize does not prune versions or optimize indexes;
|
||||
explicit requests for those unsupported operations are rejected. The synchronous
|
||||
Python `compact_files()` and `cleanup_old_versions()` helpers remain warning-only
|
||||
no-ops in LanceDB Enterprise.
|
||||
Python `cleanup_old_versions()` remains a warning-only no-op in LanceDB Enterprise.
|
||||
Use `optimize(action="rewrite_data")` for Embedded compaction only.
|
||||
|
||||
Manual compaction accepts four invocation options and inherits omitted fields
|
||||
from the selected branch's table tuning, then deployment/built-in defaults.
|
||||
|
||||
@@ -67,7 +67,7 @@ even though `optimize()` bundles both in one LanceDB Embedded call.
|
||||
|
||||
## Track on-demand Enterprise compaction {#compaction-jobs}
|
||||
|
||||
On compatible Enterprise deployments, `compact_async()` / `compactAsync()`
|
||||
On compatible Enterprise deployments, `optimize_async()` / `optimizeAsync()`
|
||||
submits SQL `OPTIMIZE ... REWRITE DATA` and returns a durable job handle.
|
||||
The table handle supplies the namespace and branch. The existing remote
|
||||
`optimize()` call keeps returning after submission with placeholder statistics;
|
||||
@@ -77,7 +77,7 @@ use the job-returning API to wait for the actual rewrite and obtain its result.
|
||||
```python Python
|
||||
from datetime import timedelta
|
||||
|
||||
job = table.compact_async(
|
||||
job = table.optimize_async(
|
||||
compaction_options={"target_rows_per_fragment": 1000, "batch_size": 128}
|
||||
)
|
||||
result = job.wait(timeout=timedelta(minutes=10))
|
||||
@@ -89,7 +89,7 @@ result = db.open_job(job.id).wait()
|
||||
```typescript TypeScript
|
||||
import type { CompactionResult } from "@lancedb/lancedb";
|
||||
|
||||
const job = await table.compactAsync({
|
||||
const job = await table.optimizeAsync({
|
||||
targetRowsPerFragment: 1000, batchSize: 128,
|
||||
});
|
||||
const result = await job.wait({ timeoutMs: 600_000 });
|
||||
@@ -104,7 +104,7 @@ use std::time::Duration;
|
||||
use lancedb::job::JobWaitOptions;
|
||||
use lancedb::table::{CompactionResult, optimize::CompactionOverrides};
|
||||
|
||||
let job = table.compact_async(CompactionOverrides {
|
||||
let job = table.optimize_async(CompactionOverrides {
|
||||
target_rows_per_fragment: Some(1000),
|
||||
batch_size: Some(128),
|
||||
..Default::default()
|
||||
@@ -374,7 +374,8 @@ different budget; toggling automatic enablement alone does not reset backoff.
|
||||
|
||||
SDKs forward supplied fields and leave inheritance to the server. An explicitly
|
||||
supplied SDK-default fragment target still overrides table tuning. Rust callers
|
||||
should use `Table::compact_async(CompactionOverrides)` for that distinction: the legacy
|
||||
can use `Table::optimize(CompactionOverrides)` or
|
||||
`Table::optimize_async(CompactionOverrides)` for that distinction: the legacy
|
||||
`OptimizeAction::Compact` path treats its default-valued Lance fragment target
|
||||
as unspecified because the options type has no presence bit.
|
||||
|
||||
@@ -480,3 +481,50 @@ If the first task exceeds a budget, that run performs no compaction. See the
|
||||
[CompactionOptions reference](https://lancedb.github.io/lancedb/python/python/#lancedb.table.CompactionOptions)
|
||||
for all options and their limits.
|
||||
*/}
|
||||
|
||||
## Optimize submission and job handles
|
||||
|
||||
Enterprise `optimize()` returns once the compaction request is accepted. Its
|
||||
statistics are placeholders, not completed-work metrics. Use the durable job
|
||||
method to wait for actual results:
|
||||
|
||||
```python
|
||||
# Submit and discard the handle.
|
||||
table.optimize(compaction_options={"target_rows_per_fragment": 1000})
|
||||
# Submit and retain status, cancellation, and actual results.
|
||||
job = table.optimize_async(compaction_options={"target_rows_per_fragment": 1000})
|
||||
result = job.wait()
|
||||
# Async Python: job = await table.optimize_async(); result = await job.wait()
|
||||
```
|
||||
|
||||
```typescript
|
||||
await table.optimize({ compactionOptions: { targetRowsPerFragment: 1000 } });
|
||||
const job = await table.optimizeAsync({ targetRowsPerFragment: 1000 });
|
||||
const result = await job.wait();
|
||||
```
|
||||
|
||||
```rust
|
||||
use lancedb::table::CompactionOverrides;
|
||||
|
||||
async fn optimize_table(table: &lancedb::Table) -> lancedb::Result<()> {
|
||||
table.optimize(CompactionOverrides::default()).await?;
|
||||
let job = table.optimize_async(CompactionOverrides::default()).await?;
|
||||
let result = job.wait().await?;
|
||||
println!("Committed {} rows", result.rows_succeeded);
|
||||
Ok(())
|
||||
}
|
||||
```
|
||||
|
||||
Embedded `optimize()` still waits for compaction, cleanup, and index maintenance,
|
||||
returning actual statistics. Select only data rewrites with Python
|
||||
`optimize(action="rewrite_data")`, TypeScript
|
||||
`optimize({ action: "rewrite_data" })`, or Rust
|
||||
`optimize(CompactionOverrides::default())`. Rewrite-only requests preserve old
|
||||
versions and skip the separate index maintenance phase. Cleanup arguments cannot
|
||||
be combined with a rewrite-only action.
|
||||
|
||||
The former `compact_async()` / `compactAsync()` methods are now
|
||||
`optimize_async()` / `optimizeAsync()`. Rust `compact(overrides)` becomes
|
||||
`optimize(overrides)`. Python `compact_files()` becomes
|
||||
`optimize(action="rewrite_data", compaction_options=...)`, with rewrite metrics
|
||||
under `stats.compaction`. The old names are removed without aliases.
|
||||
|
||||
Reference in New Issue
Block a user