Implementation:Lance format Lance Java CreateIndexOp
| Knowledge Sources | |
|---|---|
| Domains | Java_SDK, Dataset_Management |
| Last Updated | 2026-02-08 19:33 GMT |
Overview
Description
The CreateIndex class is an immutable operation that represents the creation and removal of indices on a Lance dataset. It implements the Operation interface and corresponds to the Rust CreateIndex struct in lance/rust/lance/src/dataset/transaction.rs. The class tracks both newly created indices and indices to be removed in a single atomic transaction, enabling index replacement workflows.
Instances are constructed through a builder pattern. Both the newIndices and removedIndices lists default to empty collections when not explicitly set.
Usage
Use CreateIndex when building or rebuilding vector or scalar indices on a Lance dataset. The operation supports adding new indices, removing old indices, or performing both simultaneously (for example, when replacing an IVF index with an HNSW index).
Code Reference
Source Location
java/src/main/java/org/lance/operation/CreateIndex.java
Signature
public class CreateIndex implements Operation {
public static Builder builder();
public List<Index> getNewIndices();
public List<Index> getRemovedIndices();
public String name(); // returns "CreateIndex"
}
Import
import org.lance.operation.CreateIndex;
I/O Contract
| Parameter | Type | Required | Description |
|---|---|---|---|
| newIndices | List<Index> |
No | Indices to create (defaults to empty list) |
| removedIndices | List<Index> |
No | Indices to remove (defaults to empty list) |
| Return | Type | Description |
|---|---|---|
| getNewIndices() | List<Index> |
The list of newly created indices |
| getRemovedIndices() | List<Index> |
The list of indices to remove |
| name() | String |
Returns "CreateIndex" for JNI dispatch
|
Usage Examples
// Create a new vector index
Index vectorIndex = buildVectorIndex("embedding_column");
CreateIndex createIndexOp = CreateIndex.builder()
.withNewIndices(List.of(vectorIndex))
.build();
// Replace an existing index with a new one
CreateIndex replaceIndexOp = CreateIndex.builder()
.withNewIndices(List.of(newIndex))
.withRemovedIndices(List.of(oldIndex))
.build();
String opName = replaceIndexOp.name(); // "CreateIndex"
Related Pages
- Lance_format_Lance_Java_RewriteOp -- Rewrite operation that may also remap indices after compaction
- Lance_format_Lance_Java_DeleteOp -- Delete operation that may affect index coverage