Indexes and maintenance

group Indexes and maintenance

Create and inspect indexes, wait for builds, and optimize tables.

Enums

enum LanceDBCompactionField

Compaction option fields of LanceDBCompactionOptions.

Every bit makes the matching field an override. A field whose bit is not set keeps the LanceDB default for compacting a table, so an omitted option stays distinct from a value that happens to equal the default.

Values:

enumerator LANCEDB_COMPACTION_TARGET_ROWS_PER_FRAGMENT
enumerator LANCEDB_COMPACTION_MAX_ROWS_PER_GROUP
enumerator LANCEDB_COMPACTION_MAX_BYTES_PER_FILE
enumerator LANCEDB_COMPACTION_MATERIALIZE_DELETIONS
enumerator LANCEDB_COMPACTION_MATERIALIZE_DELETIONS_THRESHOLD
enumerator LANCEDB_COMPACTION_NUM_THREADS
enumerator LANCEDB_COMPACTION_BATCH_SIZE
enum LanceDBPruneField

Prune option fields of LanceDBPruneOptions.

Every bit makes the matching field an override. A field whose bit is not set keeps the LanceDB default, so an omitted option stays distinct from an explicit false or an explicit age.

Values:

enumerator LANCEDB_PRUNE_OLDER_THAN
enumerator LANCEDB_PRUNE_DELETE_UNVERIFIED
enumerator LANCEDB_PRUNE_ERROR_IF_TAGGED_OLD_VERSIONS

Functions

LanceDBError lancedb_table_create_vector_index(const LanceDBTable *table, const char *const *columns, size_t num_columns, LanceDBIndexType index_type, const LanceDBVectorIndexConfig *config, char **error_message)

Create a vector index on table columns.

If error_message is provided and an error occurs, the caller must free the error message with lancedb_free_string().

Parameters:
  • table – - pointer to LanceDBTable

  • columns – - array of null-terminated C strings containing column names

  • num_columns – - number of columns in the array

  • index_type – - type of vector index to create

  • config – - pointer to LanceDBVectorIndexConfig or NULL for defaults

  • error_message – - optional pointer to receive detailed error message (NULL to ignore)

Returns:

Error code indicating success or failure

LanceDBError lancedb_table_create_scalar_index(const LanceDBTable *table, const char *const *columns, size_t num_columns, LanceDBIndexType index_type, const LanceDBScalarIndexConfig *config, char **error_message)

Create a scalar index on table columns.

If error_message is provided and an error occurs, the caller must free the error message with lancedb_free_string().

Parameters:
  • table – - pointer to LanceDBTable

  • columns – - array of null-terminated C strings containing column names

  • num_columns – - number of columns in the array

  • index_type – - type of scalar index to create

  • config – - pointer to LanceDBScalarIndexConfig or NULL for defaults

  • error_message – - optional pointer to receive detailed error message (NULL to ignore)

Returns:

Error code indicating success or failure

LanceDBError lancedb_table_create_fts_index(const LanceDBTable *table, const char *const *columns, size_t num_columns, const LanceDBFtsIndexConfig *config, char **error_message)

Create a full-text search index on table columns.

If error_message is provided and an error occurs, the caller must free the error message with lancedb_free_string().

Parameters:
  • table – - pointer to LanceDBTable

  • columns – - array of null-terminated C strings containing column names

  • num_columns – - number of columns in the array

  • config – - pointer to LanceDBFtsIndexConfig or NULL for defaults

  • error_message – - optional pointer to receive detailed error message (NULL to ignore)

Returns:

Error code indicating success or failure

LanceDBIndexOptions lancedb_index_options_default(void)

Return the default index creation options.

Every optional field is unset, so the SDK defaults apply.

LanceDBError lancedb_table_create_index(const LanceDBTable *table, const char *const *columns, size_t num_columns, LanceDBIndexType index_type, const LanceDBIndexOptions *options, char **error_message)

Create any supported index with a custom name, replace choice, creation wait and per-type tuning parameters.

The index type selects which tuning fields are used: IVF types use the IVF fields, PQ and HNSW types use their additional fields, FTS uses the fts_* fields, and scalar types use only name, replace and wait_timeout_ms. A NULL options pointer behaves like lancedb_index_options_default(). LANCEDB_INDEX_AUTO passes the SDK’s Auto index through; it is not remapped to a concrete index type.

wait_timeout_ms is an SDK polling budget for index creation, not a wall-clock guarantee and not a cancellation. Zero does not wait. Native tables build synchronously and ignore the value. A remote server that returns a job ID waits for that job with the SDK timeout; reaching the budget returns LANCEDB_TIMEOUT but does not cancel the submitted build. A legacy remote server without a job ID polls the named index (custom name or SDK default name) instead; that poll reads the index’s current num_unindexed_rows, so concurrent writes can extend it and a same-name prior index can satisfy it before this submission finishes. The SDK submits the create/replace request before checking its two-hour budget cap, so an over-cap error can arrive after the server accepted the request.

Values outside the documented ranges, invalid UTF-8, unsupported index types and SDK errors are returned through error_message when provided.

If error_message is provided and an error occurs, the caller must free the error message with lancedb_free_string().

Parameters:
  • table – - pointer to LanceDBTable

  • columns – - array of null-terminated C strings containing column names

  • num_columns – - number of columns in the array

  • index_type – - LanceDBIndexType value selecting the index kind

  • options – - pointer to LanceDBIndexOptions or NULL for the SDK defaults

  • error_message – - optional pointer to receive detailed error message (NULL to ignore)

Returns:

Error code indicating success or failure

LanceDBError lancedb_table_create_index_with_builder_options(const LanceDBTable *table, const char *const *columns, size_t num_columns, LanceDBIndexType index_type, const LanceDBIndexOptions *options, int train, int exist_ok, char **error_message)

Create any supported index with explicit train and exist_ok builder choices.

Takes the same table, columns, index type, tuning options and error handling as lancedb_table_create_index(). train and exist_ok use -1 for the SDK default, 0 for false and 1 for true. The SDK defaults are train = true, exist_ok = false and replace = true.

On an embedded table, train = 0 creates an empty index: its statistics report zero indexed rows and every table row unindexed. exist_ok = 1 preserves an existing index with the requested name, or with the SDK default name when the options name is empty or NULL, and returns success without rebuilding it. It takes precedence over replace = 1, so no replacement or training happens.

A remote LanceDB Enterprise endpoint cannot honor train = 0 as an empty local index. The SDK does not send train, logs a warning, and the endpoint creates the index and populates it in the background. For exist_ok = 1, the SDK sends an exist_ok query parameter and disables replace in that request.

The SDK documents train as not yet supported for vector indices. A NULL options pointer behaves like lancedb_index_options_default(). Values outside -1, 0 and 1, other invalid options and SDK errors are returned through error_message when provided. wait_timeout_ms and all other behavior are the same as lancedb_table_create_index().

If error_message is provided and an error occurs, the caller must free the error message with lancedb_free_string().

LanceDBError lancedb_table_list_indices(const LanceDBTable *table, char ***indices_out, size_t *count_out, char **error_message)

List all indices on the table.

The caller is responsible for freeing the returned strings and array using lancedb_free_index_list(). If error_message is provided and an error occurs, the caller must free the error message with lancedb_free_string().

Parameters:
  • table – - pointer to LanceDBTable

  • indices_out – - pointer to receive array of index info strings

  • count_out – - pointer to receive the count of indices

  • error_message – - optional pointer to receive detailed error message (NULL to ignore)

Returns:

Error code indicating success or failure

LanceDBError lancedb_table_prewarm_index(const LanceDBTable *table, const char *index_name, char **error_message)

Prewarm a named index.

Loads the index into memory and caches it, so the first query does not pay for the load.

If error_message is provided and an error occurs, the caller must free the error message with lancedb_free_string().

Parameters:
  • table – - pointer to LanceDBTable

  • index_name – - null-terminated C string containing the index name

  • error_message – - optional pointer to receive detailed error message (NULL to ignore)

Returns:

LANCEDB_SUCCESS if the index was prewarmed, LANCEDB_INDEX_NOT_FOUND if the index does not exist, other error codes on failure

LanceDBError lancedb_table_drop_index(const LanceDBTable *table, const char *index_name, char **error_message)

Drop an index.

If error_message is provided and an error occurs, the caller must free the error message with lancedb_free_string().

Parameters:
  • table – - pointer to LanceDBTable

  • index_name – - null-terminated C string containing the index name

  • error_message – - optional pointer to receive detailed error message (NULL to ignore)

Returns:

Error code indicating success or failure

LanceDBError lancedb_table_optimize(const LanceDBTable *table, LanceDBOptimizeType optimize_type, char **error_message)

Optimize table (rebuild indices and compact files).

If error_message is provided and an error occurs, the caller must free the error message with lancedb_free_string().

Parameters:
  • table – - pointer to LanceDBTable

  • optimize_type – - type of optimization to perform

  • error_message – - optional pointer to receive detailed error message (NULL to ignore)

Returns:

Error code indicating success or failure

LanceDBError lancedb_table_optimize_with_action(const LanceDBTable *table, const LanceDBOptimizeConfig *config, LanceDBOptimizeStats *stats_out, char **error_message)

Optimize table with a configurable action and return its statistics.

Unlike lancedb_table_optimize(), which runs each action with its defaults and discards the statistics, this entry point applies the action’s options and reports what the SDK did. LANCEDB_OPTIMIZE_ALL runs compaction, pruning and index optimization with their defaults, exactly like lancedb_table_optimize(LANCEDB_OPTIMIZE_ALL).

The SDK decides which actions and options a table backend supports: an Enterprise table only hosts LANCEDB_OPTIMIZE_COMPACT and returns LANCEDB_NOT_SUPPORTED for the other actions. Its compaction returns once the server accepts the job, with zeroed placeholder metrics while the compaction may still be running; a local table reports the work it did.

Invalid input is rejected with LANCEDB_INVALID_ARGUMENT before any optimization runs: an action value that is not a LanceDBOptimizeType enumerator, an unknown set_fields bit, a size that does not fit in size_t, a boolean other than 0 and 1, or a negative prune age. On error, stats_out is left unchanged.

If error_message is provided and an error occurs, the caller must free the error message with lancedb_free_string().

Parameters:
  • table – - pointer to LanceDBTable

  • config – - pointer to LanceDBOptimizeConfig, which must not be NULL

  • stats_out – - pointer to receive the statistics, which must not be NULL

  • error_message – - optional pointer to receive detailed error message (NULL to ignore)

Returns:

Error code indicating success or failure

void lancedb_free_index_list(char **indices, size_t count)

Free index list array returned by lancedb_table_list_indices.

Parameters:
  • indices – - array of string pointers returned by lancedb_table_list_indices

  • count – - number of strings in the array

LanceDBError lancedb_table_index_stats(const LanceDBTable *table, const char *index_name, LanceDBIndexStats *stats_out, char **error_message)

Get statistics for a named index on the table.

The stats are read directly from the LanceDB manifest (no external state needed). If error_message is provided and an error occurs, the caller must free the error message with lancedb_free_string().

Parameters:
  • table – - pointer to LanceDBTable

  • index_name – - null-terminated C string containing the index name

  • stats_out – - pointer to receive the index statistics

  • error_message – - optional pointer to receive detailed error message (NULL to ignore)

Returns:

LANCEDB_SUCCESS if stats retrieved, LANCEDB_INDEX_NOT_FOUND if index doesn’t exist

LanceDBError lancedb_table_index_statistics(const LanceDBTable *table, const char *index_name, const LanceDBIndexStatistics **stats_out, char **error_message)

Get the statistics the Rust SDK reports for a named index.

Unlike lancedb_table_index_stats(), which returns only the row counts, this entry point returns the complete SDK result with its optional values.

On success, *stats_out is NULL when the index does not exist and points to the read-only result otherwise, so a missing index is not an error. On failure, *stats_out is NULL as well, and error_message carries the reason when requested.

The result and the strings it borrows are owned by the library. Do not modify the result, write through the strings or free them individually; release the whole result with lancedb_free_index_statistics() once it is no longer used, and release it only once. If error_message is provided and an error occurs, the caller must free the error message with lancedb_free_string().

Parameters:
  • table – - pointer to LanceDBTable

  • index_name – - null-terminated C string containing the index name

  • stats_out – - pointer to receive the read-only statistics, or NULL when the index does not exist

  • error_message – - optional pointer to receive detailed error message (NULL to ignore)

Returns:

LANCEDB_SUCCESS when the statistics were read, including when the index does not exist, other error codes on failure

void lancedb_free_index_statistics(const LanceDBIndexStatistics *stats)

Release the statistics returned by lancedb_table_index_statistics.

The result and the strings it borrows become invalid. Do not free the strings individually and do not release the same result twice. Safe to call with a NULL pointer.

Parameters:

stats – - statistics returned by lancedb_table_index_statistics

LanceDBError lancedb_table_wait_for_index(const LanceDBTable *table, const char *const *index_names, size_t num_index_names, uint64_t timeout_ms, char **error_message)

Wait until the named indices are fully indexed.

Blocks the calling thread and polls the index statistics until every named index reports no unindexed rows, or until the budget runs out. Waiting does not build or extend an index, so an index that does not cover all the rows of the table never becomes fully indexed by waiting: use the index creation or optimization functions to (re)build it, and wait to learn when the build has committed.

The names are waited on in the same call, and every one of them must be an existing index. Waiting for all the indices of a table is not part of this function: pass the names returned by lancedb_table_list_indices(). There is no cancellation.

The budget decides whether another polling round starts; it is not a wall-clock bound. The listing and statistics requests of a round, and the diagnostics the SDK reads after the last one, finish after the budget has run out, and the call does not interrupt them.

If error_message is provided and an error occurs, the caller must free the error message with lancedb_free_string().

Parameters:
  • table – - pointer to LanceDBTable

  • index_names – - array of null-terminated C strings containing index names

  • num_index_names – - number of names in the array, at least 1

  • timeout_ms – - polling budget in milliseconds, greater than 0. The SDK starts a polling round while less than this much time has elapsed, sleeps one second between rounds, and caps the budget at two hours; a larger budget is rejected with the maximum the SDK reports

  • error_message – - optional pointer to receive detailed error message (NULL to ignore)

Returns:

LANCEDB_SUCCESS once every named index is fully indexed, LANCEDB_TIMEOUT when the budget runs out before that, LANCEDB_INVALID_ARGUMENT for invalid arguments, or the error code of the SDK failure

LanceDBError lancedb_table_list_indices_info(const LanceDBTable *table, const LanceDBIndexInfo **indices_out, size_t *count_out, char **error_message)

List every index on the table with its name, columns and index type.

Unlike lancedb_table_list_indices(), which returns only the names, this entry point returns the metadata required by callers that inspect the indices. The index type is the SDK’s type name and is preserved for types this library does not know about.

On success with no indices, count_out is 0 and indices_out is NULL. The caller must free the returned array using lancedb_free_index_info(). If error_message is provided and an error occurs, the caller must free the error message with lancedb_free_string().

Parameters:
  • table – - pointer to LanceDBTable

  • indices_out – - pointer to receive the array of index information

  • count_out – - pointer to receive the number of indices

  • error_message – - optional pointer to receive detailed error message (NULL to ignore)

Returns:

Error code indicating success or failure

void lancedb_free_index_info(const LanceDBIndexInfo *indices, size_t count)

Free index information array returned by lancedb_table_list_indices_info.

Safe to call with a NULL pointer.

Parameters:
  • indices – - array of LanceDBIndexInfo structs returned by lancedb_table_list_indices_info

  • count – - number of entries in the array

struct LanceDBCompactionOptions
#include <lancedb.h>

Compaction overrides, used by lancedb_table_optimize_with_action().

The fields follow the compaction options of the LanceDB SDK. set_fields selects the fields that are read; every other field keeps the SDK default. Sizes are checked against size_t before the compaction starts.

An Enterprise table plans compaction on the server. It accepts only the overrides the server supports and rejects the others with LANCEDB_NOT_SUPPORTED before submission. It also treats a target_rows_per_fragment equal to the SDK default (1048576) as omitted, even when its bit is set, so a table-level target can win over that value.

struct LanceDBPruneOptions
#include <lancedb.h>

Version pruning overrides, used by lancedb_table_optimize_with_action().

The fields follow the prune action of the LanceDB SDK. set_fields selects the fields that are read; every other field keeps the SDK default.

older_than_nanos is the minimum age of a prunable version, in nanoseconds, so a sub-second age keeps its exact length. The age must not be negative. When the bit is not set, the SDK default age applies. When it is set, zero means a cutoff at the current time: every version older than now is removed, while the latest version and protected versions still survive.

delete_unverified permits deleting files that are newer than the SDK’s safety margin for in-progress transactions; setting it can corrupt a dataset that another process is still writing, so leave it unset unless that is safe. Tagged versions are retained by default; error_if_tagged_old_versions makes the prune fail instead of silently retaining them.

struct LanceDBOptimizeConfig
#include <lancedb.h>

One configurable optimize action.

action selects the optimization, and the option struct of that action carries its overrides. The option struct of another action is ignored.

action is the raw integer value of a LanceDBOptimizeType enumerator. It is an int rather than the enum type so that this entry point receives the value a caller passes, including one outside the enumerators, and rejects it with LANCEDB_INVALID_ARGUMENT instead of an undefined enum conversion.

struct LanceDBCompactionMetrics
#include <lancedb.h>

Fragments and files that compaction rewrote.

struct LanceDBRemovalStats
#include <lancedb.h>

Files and versions that pruning removed.

struct LanceDBOptimizeStats
#include <lancedb.h>

Statistics of one optimize action.

The SDK reports compaction and pruning statistics only for an action that ran them, so each group carries its own presence flag. The values of a group whose flag is 0 are zero.

struct LanceDBIndexStats
#include <lancedb.h>

Index statistics structure.

struct LanceDBIndexStatistics
#include <lancedb.h>

Statistics of a single index, as reported by the Rust SDK.

The strings are borrowed from the result and are read-only: do not modify them, write through them or free them individually. They stay valid until the result is released with lancedb_free_index_statistics(), and the whole result must be treated as read-only.

The values the SDK reports as optional keep their presence: distance_type is NULL when the SDK reports no distance metric, and has_num_indices tells whether num_indices was reported. index_type is the SDK type name, for example “IVF_PQ”, “BTREE” or “FTS”.

struct LanceDBIndexInfo
#include <lancedb.h>

Information about one index on a table.

The strings and arrays are owned by the result and are valid until it is freed with lancedb_free_index_info().