mirror of
https://github.com/lancedb/lancedb.git
synced 2026-11-13 14:16:54 +00:00
A broad documentation pass across the areas LanceDB Enterprise and Embedded diverge on most: **Data Curation** -- GPU Function execution, Slurm scheduling (and what Slurm is, for readers new to it), blob late materialization as its own page, joins, aggregation/profiling, sampling, near-duplicate detection, chunking, distributed shuffle, and IVF-partition clustering. **Feature Engineering** -- computed columns and materialized views, restructured to lead with the Function-based path and show the SQL form side by side with Python throughout; a single Auto Refresh page instead of duplicating scheduling details on every refresh page; adaptive execution; checkpointing; GPU and Slurm placement for refresh workers; a Training Cache page for the PyTorch data loader's automatic cache benefit. **Security & Governance** -- an Audit Log reference (schema, access, grants), Secrets promoted to an ordinary catalog object with their own SQL DDL and a vending/rotation guide, and privilege-table fixes verified against the authorization source. **Deployment & Maintenance** -- Horizontal Scaling and OpenTelemetry moved into a real Deployment area; Automated Cleanup folded into Intelligent Auto-Maintenance (every other maintenance decision already lived there); RTE Compaction and Advanced Conflict Resolution documented in depth. **Landing page** -- the Enterprise feature comparison table reorganized (several redundant or stale rows removed, several new areas added), and the "why Enterprise" bullets replaced with ones tied to a concrete page (Performance, Scale, Fault tolerance, Multicloud deployment, Simplify operations) instead of vague promises. Plus a full pass addressing lancedb-gatekeeper's review: a real test-safety bug (a quickstart test could silently overwrite and delete a deployment's own `frames` table), a fabricated SQL statement with no backing implementation, an actual dedup-guarantee bug in `take_row_ids`, and dozens of documentation-accuracy fixes verified against source rather than taken on faith -- each either fixed, or left with an explicit note on why it needs a feature or deployment owner's sign-off instead of being guessed at. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_018PXMCbRH6i5w47TsjeEUMT --------- Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
167 lines
7.1 KiB
Plaintext
167 lines
7.1 KiB
Plaintext
---
|
|
title: "Compaction and cleanup"
|
|
sidebarTitle: "Compaction"
|
|
description: "Merge small files, prune old versions, and fold new rows into existing indexes."
|
|
icon: broom
|
|
availability:
|
|
embedded: available
|
|
enterprise: available
|
|
---
|
|
|
|
import { PyStorageCompactionTuning, PyStorageRebuildVectorIndex, RsStorageCompactionTuning } from '/snippets/doc_storage_examples.mdx';
|
|
|
|
Every write commits a new table version, and versions accumulate: small files
|
|
from frequent appends, superseded files from updates and deletes, and rows added
|
|
since an index was built. In the embedded library, `optimize()` addresses all
|
|
three; a deployment handles them in the background and does not support
|
|
`optimize()`.
|
|
|
|
Run optimization as regular table maintenance, particularly after many small
|
|
writes or a large ingest.
|
|
|
|
{/*
|
|
Draft for the LanceDB Embedded compaction SQ partition check release. Keep this section
|
|
unpublished until that behavior ships.
|
|
|
|
### Recover from an oversized SQ partition {#oversized-sq-partition}
|
|
|
|
Compacting a table with an IVF scalar-quantized (SQ) vector index can stop
|
|
before rewriting files if an affected partition is too large to remap. The
|
|
error identifies the index, segment, partition size, and vector dimension
|
|
instead of letting the remap fail at Arrow's fixed-size-list `u32`
|
|
child-array limit.
|
|
|
|
Rebuild the affected vector index with enough IVF partitions to keep each
|
|
partition at or below `floor(u32::MAX / dimension)` vectors, then retry the
|
|
optimize. Rebuilding with the default IVF partitioning can also choose enough
|
|
partitions.
|
|
*/}
|
|
|
|
## Optimize a table {#what-it-does}
|
|
|
|
<CodeGroup>
|
|
```python Python icon="python"
|
|
table.optimize()
|
|
```
|
|
</CodeGroup>
|
|
|
|
Three operations, in one call:
|
|
|
|
| | |
|
|
| --- | --- |
|
|
| **Compaction** | merges small files into larger ones |
|
|
| **Prune** | removes versions older than the retention window (see [Garbage Collection](/maintenance/cleanup)) |
|
|
| **Index** | folds newly added rows into existing indexes (see [Incremental Indexing](/indexing/incremental-indexing)) |
|
|
|
|
Compaction itself is only the first of the three: merging small fragments back
|
|
into larger ones, which is what keeps a scan from opening more files than it
|
|
needs to.
|
|
|
|
<Note>
|
|
**Enterprise job type:** `compact`. Runs automatically as data accumulates,
|
|
separately from [`cleanup`](/maintenance/cleanup). The two are distinct jobs
|
|
even though `optimize()` bundles both in one LanceDB Embedded call.
|
|
</Note>
|
|
|
|
## Retraining indexes {#retrain}
|
|
|
|
Folding new rows into an index preserves the structure the index was trained on.
|
|
When the data distribution has shifted enough that the index's clusters are a
|
|
poor fit, recreate the index with `replace=True` to train it on the current data.
|
|
The deprecated `retrain` argument to `optimize()` does not rebuild indexes.
|
|
|
|
This example assumes a populated table whose `vector` column has an IVF_FLAT
|
|
index configured for L2 distance and four partitions:
|
|
|
|
<CodeGroup>
|
|
<CodeBlock filename="Python" language="Python" icon="python">
|
|
{PyStorageRebuildVectorIndex}
|
|
</CodeBlock>
|
|
</CodeGroup>
|
|
|
|
Use your index's column, type, distance metric, and training settings when
|
|
rebuilding it. Recreating an index is more expensive than a normal optimize,
|
|
and can help after a large ingest that changed the data distribution.
|
|
|
|
## When to run it {#when}
|
|
|
|
In the embedded library there is no background compactor: `optimize()` runs
|
|
when you call it. A deployment compacts a table automatically once enough small
|
|
fragments accumulate, unless its operator turns this off.
|
|
|
|
Frequent small appends are what make it necessary, because each one commits
|
|
files. A table written in a few large batches needs it rarely; one taking
|
|
continuous small writes needs it on a schedule.
|
|
|
|
Opening a table in LanceDB Embedded logs a warning at most once per table per
|
|
process when at least 100 fragments have fewer than 100,000 rows each. Set
|
|
`LANCEDB_LOG=warn` to surface this log if your logger hides warnings by default.
|
|
|
|
<Note>
|
|
Compaction rewrites files, which conflicts with a concurrent
|
|
[computed-column refresh](/feature-engineering/add-computed-column) or
|
|
[view refresh](/feature-engineering/refresh-materialized-view) planned against the
|
|
version it replaces. Sequence them rather than running both at once.
|
|
</Note>
|
|
|
|
See [Garbage Collection](/maintenance/cleanup) for pruning old versions, and
|
|
[Incremental Indexing](/indexing/incremental-indexing) for the index-folding half of
|
|
`optimize()`.
|
|
|
|
## Performance {#performance}
|
|
|
|
Two things accumulate on a long-lived table as more and more data gets added to it:
|
|
|
|
- **Many small fragments build up as you write**, slowing down queries that have to scan across more files. **Compaction** merges them back into larger fragments.
|
|
- **Old versions build up as the table changes**, growing disk usage beyond the live data size (LanceDB retains them for time-travel and rollback). **Cleanup** prunes versions older than a retention window.
|
|
|
|
In LanceDB Embedded, you run them yourself via `optimize()`, which bundles both into a single call:
|
|
|
|
<CodeGroup>
|
|
```python Python icon="python"
|
|
from datetime import timedelta
|
|
table.optimize() # 7-day default retention
|
|
table.optimize(cleanup_older_than=timedelta(days=1)) # reclaim space sooner
|
|
```
|
|
</CodeGroup>
|
|
|
|
The best practice is to run `optimize()` after large writes or on a schedule. It also bundles incremental index updates. See [Incremental Indexing](/indexing/incremental-indexing) for the breakdown. Updates also move rows out of the vector index, so they remain searchable but unindexed. Update or rebuild the index after large update batches.
|
|
|
|
{/*
|
|
Draft for the Python compaction_options release. Keep this section unpublished
|
|
until the first supported release is confirmed.
|
|
|
|
### Tune compaction for wide rows {#tune-wide-rows}
|
|
|
|
For an existing LanceDB Embedded table, derive a fragment row target from the expected
|
|
row size. These examples use rows averaging 1 KiB and a 64 KiB fragment
|
|
target; choose sizes for your workload. Smaller scan batches and one compaction
|
|
task at a time can also reduce memory use.
|
|
|
|
<CodeGroup>
|
|
<CodeBlock filename="Python" language="Python" icon="python">
|
|
{PyStorageCompactionTuning}
|
|
</CodeBlock>
|
|
<CodeBlock filename="Rust" language="Rust" icon="rust">
|
|
{RsStorageCompactionTuning}
|
|
</CodeBlock>
|
|
</CodeGroup>
|
|
|
|
The Rust example runs compaction only. Run pruning and index optimization
|
|
separately when needed; Python's `optimize()` includes those steps.
|
|
|
|
TypeScript's `optimize()` does not currently expose the fragment row target,
|
|
scan batch size, or compaction thread count. These tuning examples apply to
|
|
Python and Rust tables in LanceDB Embedded.
|
|
|
|
Planning remains row based. The row target bounds later passes after existing
|
|
oversized fragments have been rewritten; the first pass rewrites those
|
|
fragments whole, so peak memory can exceed the target. `max_bytes_per_file`
|
|
limits output file size rather than compaction memory.
|
|
|
|
The `max_source_rows` and `max_source_bytes` budgets admit whole planned tasks.
|
|
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.
|
|
*/}
|