lance-format / lance-format/lance

Default num_partitions inconsistent and maybe not correct for large scales

Open
#6,201 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

When creating a vector index, if the user does not specify the number of partitions, we have some inconsistent logic to determine the value.

In rust we hit recommended_num_partitions:

pub fn recommended_num_partitions(num_rows: usize, target_partition_size: usize) -> usize {
    // The maximum number of partitions is 4096 to avoid slow KMeans clustering,
    // bump it once we have better clustering algorithms.
    const MAX_PARTITIONS: usize = 4096;
    (num_rows / target_partition_size).clamp(1, MAX_PARTITIONS)
}

In python we hit _target_partition_size_to_num_partitions:

def _target_partition_size_to_num_partitions(
    num_rows: int, target_partition_size: Optional[int]
) -> int:
    if target_partition_size is None:
        target_partition_size = 8192
    num_partitions = num_rows // target_partition_size
    return max(1, num_partitions, 4096)

The first one clamps to 4096. The second one does not (perhaps it was meant to be max(1, min(num_partitions, 4096))?

Furthermore, silently clamping to 4096 is unlikely to provide good results at high scales. We should either warn that the user needs to think about this or use a better default (e.g. sqrt(num_partitions))

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.

Research direction

Start by comparing Rust's recommended_num_partitions with Python's _target_partition_size_to_num_partitions, including their behavior when the target size is omitted and when row counts are large. Decide and document the intended cap or scaling strategy, then make both paths consistent and verify the high-scale behavior with the relevant vector-index tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, rust
Domain
databases, machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.