lance-format / lance-format/lance

Memory limited FTS training

Open
#5,502 5 comments 1 reaction 1 assignee View on GitHub

@Xuanwo is already working on this.

Since Dec 17, 2025.

A-index performance
Dominant language
Rust
Stars
7.1k
Forks
852
Avg merge
3d 18h
Merged PRs (30d)
272

Description

FTS index building memory use seems unbounded.

Peak memory use while building index

Input size FTS
1MB 107.76
10MB 443.46
100MB 930.68
1GB 4357.92
5GB 11591.92
10GB (OOM) > 64000
Benchmark script
from tempfile import TemporaryDirectory

import pyarrow as pa

import lance
from lance._datagen import rand_batches
import memtest

def measure_peak_memory(
    data_size: int,
    index_type: str,
) -> int:
    if index_type == "btree":
        schema = pa.schema([pa.field("col", pa.string())])
        data = rand_batches(schema, num_batches=data_size // (1024 * 1024), batch_size_bytes=1024 * 1024)
    elif index_type == "bitmap":
        schema = pa.schema([pa.field("col", pa.string(), metadata={b"lance-datagen:cardinality": b"1000"})])
        data = rand_batches(schema, num_batches=data_size // (1024 * 1024), batch_size_bytes=1024 * 1024)
    elif index_type == "inverted":
        schema = pa.schema([pa.field("col", pa.string(), metadata={"lance-datagen:content-type": "sentence"})])
        data = rand_batches(schema, num_batches=data_size // (1024 * 1024), batch_size_bytes=1024 * 1024)
    else:
        raise ValueError(f"Unsupported index type: {index_type}")
    with TemporaryDirectory() as tmpdir:
        ds = lance.write_dataset(data, tmpdir)
        with memtest.track() as get_stats:
            if index_type == "btree":
                ds.create_scalar_index("col", "btree", replace=True)
            elif index_type == "bitmap":
                ds.create_scalar_index("col", "bitmap", replace=True)
            elif index_type == "inverted":
                ds.create_scalar_index("col", "INVERTED", with_position=True, replace=True)
            stats = get_stats()
    return stats["peak_bytes"]

for size_mb in [1, 10, 100, 1024, 5 * 1024, 10 * 1024]:
    size_bytes = size_mb * 1024 * 1024
    for index in ["inverted"]:
        peak_mem = measure_peak_memory(size_bytes, index)
        print(f"Data Size: {size_mb} MB, Index: {index}, Peak Memory: {peak_mem / (1024 * 1024):.2f} MB")

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.