130 releases (18 breaking)

0.19.1 Oct 21, 2024
0.18.0 Sep 17, 2024
0.15.0 Jul 25, 2024
0.10.5 Mar 20, 2024
0.0.1-alpha0 Jul 28, 2022

#12 in Machine learning

Download history 772/week @ 2024-07-19 725/week @ 2024-07-26 1124/week @ 2024-08-02 903/week @ 2024-08-09 563/week @ 2024-08-16 410/week @ 2024-08-23 610/week @ 2024-08-30 1053/week @ 2024-09-06 852/week @ 2024-09-13 1078/week @ 2024-09-20 1085/week @ 2024-09-27 1054/week @ 2024-10-04 677/week @ 2024-10-11 636/week @ 2024-10-18 794/week @ 2024-10-25 450/week @ 2024-11-01

2,700 downloads per month
Used in 9 crates (4 directly)

Apache-2.0

4.5MB
98K SLoC

Rust Implementation of Lance Data Format

Lance Logo

A new columnar data format for data science and machine learning

Installation

Install using cargo:

cargo install lance

Examples

Create dataset

Suppose batches is an Arrow Vec<RecordBatch> and schema is Arrow SchemaRef:

use lance::{dataset::WriteParams, Dataset};

let write_params = WriteParams::default();
let mut reader = RecordBatchIterator::new(
    batches.into_iter().map(Ok),
    schema
);
Dataset::write(reader, &uri, Some(write_params)).await.unwrap();

Read

let dataset = Dataset::open(path).await.unwrap();
let mut scanner = dataset.scan();
let batches: Vec<RecordBatch> = scanner
    .try_into_stream()
    .await
    .unwrap()
    .map(|b| b.unwrap())
    .collect::<Vec<RecordBatch>>()
    .await;

Take

let values: Result<RecordBatch> = dataset.take(&[200, 199, 39, 40, 100], &projection).await;

Vector index

Assume "embeddings" is a FixedSizeListArray

use ::lance::index::vector::VectorIndexParams;

let params = VectorIndexParams::default();
params.num_partitions = 256;
params.num_sub_vectors = 16;

// this will Err if list_size(embeddings) / num_sub_vectors does not meet simd alignment
dataset.create_index(&["embeddings"], IndexType::Vector, None, &params, true).await;

Motivation

Why do we need a new format for data science and machine learning?

1. Reproducibility is a must-have

Versioning and experimentation support should be built into the dataset instead of requiring multiple tools.
It should also be efficient and not require expensive copying everytime you want to create a new version.
We call this "Zero copy versioning" in Lance. It makes versioning data easy without increasing storage costs.

2. Cloud storage is now the default

Remote object storage is the default now for data science and machine learning and the performance characteristics of cloud are fundamentally different.
Lance format is optimized to be cloud native. Common operations like filter-then-take can be order of magnitude faster using Lance than Parquet, especially for ML data.

3. Vectors must be a first class citizen, not a separate thing

The majority of reasonable scale workflows should not require the added complexity and cost of a specialized database just to compute vector similarity. Lance integrates optimized vector indices into a columnar format so no additional infrastructure is required to get low latency top-K similarity search.

4. Open standards is a requirement

The DS/ML ecosystem is incredibly rich and data must be easily accessible across different languages, tools, and environments. Lance makes Apache Arrow integration its primary interface, which means conversions to/from is 2 lines of code, your code does not need to change after conversion, and nothing is locked-up to force you to pay for vendor compute. We need open-source not fauxpen-source.

Dependencies

~64–93MB
~1.5M SLoC