File Format

Dataset Directory

A Lance Dataset is organized in a directory.

    data/*.lance  -- Data directory
    _versions/*.manifest -- Manifest file for each dataset version.
    _indices/{UUID-*}/index.idx -- Secondary index, each index per directory.
    _deletions/*.{arrow,bin} -- Deletion files, which contain ids of rows
      that have been deleted.

A Manifest file includes the metadata to describe a version of the dataset.

 1// Manifest is a global section shared between all the files.
 2message Manifest {
 3  // All fields of the dataset, including the nested fields.
 4  repeated lance.file.Field fields = 1;
 6  // Fragments of the dataset.
 7  repeated DataFragment fragments = 2;
 9  // Snapshot version number.
10  uint64 version = 3;
12  // The file position of the version auxiliary data.
13  //  * It is not inheritable between versions.
14  //  * It is not loaded by default during query.
15  uint64 version_aux_data = 4;
17  // Schema metadata.
18  map<string, bytes> metadata = 5;
20  message WriterVersion {
21    // The name of the library that created this file.
22    string library = 1;
23    // The version of the library that created this file. Because we cannot assume
24    // that the library is semantically versioned, this is a string. However, if it
25    // is semantically versioned, it should be a valid semver string without any 'v'
26    // prefix. For example: `2.0.0`, `2.0.0-rc.1`.
27    string version = 2;
28  }
30  // The version of the writer that created this file.
31  //
32  // This information may be used to detect whether the file may have known bugs
33  // associated with that writer.
34  WriterVersion writer_version = 13;
36  // If presented, the file position of the index metadata.
37  optional uint64 index_section = 6;
39  // Version creation Timestamp, UTC timezone
40  google.protobuf.Timestamp timestamp = 7;
42  // Optional version tag
43  string tag = 8;
45  // Feature flags for readers.
46  //
47  // A bitmap of flags that indicate which features are required to be able to
48  // read the table. If a reader does not recognize a flag that is set, it
49  // should not attempt to read the dataset.
50  //
51  // Known flags:
52  // * 1: deletion files are present
53  // * 2: move_stable_row_ids: row IDs are tracked and stable after move operations
54  //       (such as compaction), but not updates.
55  uint64 reader_feature_flags = 9;
57  // Feature flags for writers.
58  //
59  // A bitmap of flags that indicate which features are required to be able to
60  // write to the dataset. if a writer does not recognize a flag that is set, it
61  // should not attempt to write to the dataset.
62  //
63  // The flags are the same as for reader_feature_flags, although they will not
64  // always apply to both.
65  uint64 writer_feature_flags = 10;
67  // The highest fragment ID that has been used so far.
68  //
69  // This ID is not guaranteed to be present in the current version, but it may
70  // have been used in previous versions.
71  // 
72  // For a single file, will be zero.
73  uint32 max_fragment_id = 11;
75  // Path to the transaction file, relative to `{root}/_transactions`
76  //
77  // This contains a serialized Transaction message representing the transaction
78  // that created this version.
79  //
80  // May be empty if no transaction file was written.
81  //
82  // The path format is "{read_version}-{uuid}.txn" where {read_version} is the
83  // version of the table the transaction read from, and {uuid} is a 
84  // hyphen-separated UUID.
85  string transaction_file = 12;
87  // The next unused row id. If zero, then the table does not have any rows.
88  //
89  // This is only used if the "move_stable_row_ids" feature flag is set.
90  uint64 next_row_id = 14;
91} // Manifest


DataFragment represents a chunk of data in the dataset. Itself includes one or more DataFile, where each DataFile can contain several columns in the chunk of data. It also may include a DeletionFile, which is explained in a later section.

  1// Data fragment. A fragment is a set of files which represent the
  2// different columns of the same rows.
  3// If column exists in the schema, but the related file does not exist,
  4// treat this column as nulls.
  5message DataFragment {
  6  // Unique ID of each DataFragment
  7  uint64 id = 1;
  9  repeated DataFile files = 2;
 11  // File that indicates which rows, if any, should be considered deleted.
 12  DeletionFile deletion_file = 3;
 14  // TODO: What's the simplest way we can allow an inline tombstone bitmap?
 16  // A serialized RowIdSequence message (see rowids.proto).
 17  //
 18  // These are the row ids for the fragment, in order of the rows as they appear.
 19  // That is, if a fragment has 3 rows, and the row ids are [1, 42, 3], then the
 20  // first row is row 1, the second row is row 42, and the third row is row 3.
 21  oneof row_id_sequence {
 22    // If small (< 200KB), the row ids are stored inline.
 23    bytes inline_row_ids = 5;
 24    // Otherwise, stored as part of a file.
 25    ExternalFile external_row_ids = 6;
 26  } // row_id_sequence
 28  // Number of original rows in the fragment, this includes rows that are 
 29  // now marked with deletion tombstones. To compute the current number of rows, 
 30  // subtract `deletion_file.num_deleted_rows` from this value.
 31  uint64 physical_rows = 4;
 34// Lance Data File
 35message DataFile {
 36  // Relative path to the root.
 37  string path = 1;
 38  // The ids of the fields/columns in this file.
 39  //
 40  // In Lance v1 IDs are assigned based on position in the file, offset by the max
 41  // existing field id in the table (if any already). So when a fragment is first
 42  // created with one file of N columns, the field ids will be 1, 2, ..., N. If a
 43  // second, fragment is created with M columns, the field ids will be N+1, N+2,
 44  // ..., N+M.
 45  //
 46  // In Lance v1 there is one field for each field in the input schema, this includes
 47  // nested fields (both struct and list).  Fixed size list fields have only a single
 48  // field id (these are not considered nested fields in Lance v1).
 49  //
 50  // This allows column indices to be calculated from field IDs and the input schema.
 51  //
 52  // In Lance v2 the field IDs generally follow the same pattern but there is no
 53  // way to calculate the column index from the field ID.  This is because a given
 54  // field could be encoded in many different ways, some of which occupy a different
 55  // number of columns.  For example, a struct field could be encoded into N + 1 columns
 56  // or it could be encoded into a single packed column.  To determine column indices
 57  // the column_indices property should be used instead.
 58  //
 59  // In Lance v1 these ids must be sorted but might not always be contiguous.
 60  repeated int32 fields = 2;
 61  // The top-level column indices for each field in the file.
 62  //
 63  // If the data file is version 1 then this property will be empty
 64  //
 65  // Otherwise there must be one entry for each field in `fields`.
 66  //
 67  // Some fields may not correspond to a top-level column in the file.  In these cases
 68  // the index will -1.
 69  //
 70  // For example, consider the schema:
 71  //
 72  // - dimension: packed-struct (0):
 73  //   - x: u32 (1)
 74  //   - y: u32 (2)
 75  // - path: list<u32> (3)
 76  // - embedding: fsl<768> (4)
 77  //   - fp64
 78  // - borders: fsl<4> (5)
 79  //   - simple-struct (6)
 80  //     - margin: fp64 (7)
 81  //     - padding: fp64 (8)
 82  //
 83  // One possible column indices array could be:
 84  // [0, -1, -1, 1, 3, 4, 5, 6, 7]
 85  //
 86  // This reflects quite a few phenomenon:
 87  // - The packed struct is encoded into a single column and there is no top-level column
 88  //   for the x or y fields
 89  // - The variable sized list is encoded into two columns
 90  // - The embedding is encoded into a single column (common for FSL of primitive) and there
 91  //   is not "FSL column"
 92  // - The borders field actually does have an "FSL column"
 93  //
 94  // The column indices table may not have duplicates (other than -1)
 95  repeated int32 column_indices = 3;
 96  // The major file version used to create the file
 97  uint32 file_major_version = 4;
 98  // The minor file version used to create the file
 99  //
100  // If both `file_major_version` and `file_minor_version` are set to 0,
101  // then this is a version 0.1 or version 0.2 file.
102  uint32 file_minor_version = 5;
103} // DataFile

The overall structure of a fragment is shown below. One or more data files store the columns of a fragment. New columns can be added to a fragment by adding new data files. The deletion file (if present), stores the rows that have been deleted from the fragment.


Every row has a unique id, which is an u64 that is composed of two u32s: the fragment id and the local row id. The local row id is just the index of the row in the data files.

File Structure

Each .lance file is the container for the actual data.


At the tail of the file, a Metadata protobuf block is used to describe the structure of the data file.

 1message Metadata {
 2  // 4 was used for StatisticsMetadata in the past, but has been moved to prevent
 3  // a bug in older readers.
 4  reserved 4;
 6  // Position of the manifest in the file. If it is zero, the manifest is stored
 7  // externally.
 8  uint64 manifest_position = 1;
10  // Logical offsets of each chunk group, i.e., number of the rows in each
11  // chunk.
12  repeated int32 batch_offsets = 2;
14  // The file position that page table is stored.
15  //
16  // A page table is a matrix of N x M x 2, where N = num_fields, and M =
17  // num_batches. Each cell in the table is a pair of <position:int64,
18  // length:int64> of the page. Both position and length are int64 values. The
19  // <position, length> of all the pages in the same column are then
20  // contiguously stored.
21  //
22  // Every field that is a part of the file will have a run in the page table.
23  // This includes struct columns, which will have a run of length 0 since 
24  // they don't store any actual data.
25  //
26  // For example, for the column 5 and batch 4, we have:
27  // ```text
28  //   position = page_table[5][4][0];
29  //   length = page_table[5][4][1];
30  // ```
31  uint64 page_table_position = 3;
33  message StatisticsMetadata {
34    // The schema of the statistics.
35    //
36    // This might be empty, meaning there are no statistics. It also might not 
37    // contain statistics for every field.
38    repeated Field schema = 1;
40    // The field ids of the statistics leaf fields.
41    //
42    // This plays a similar role to the `fields` field in the DataFile message.
43    // Each of these field ids corresponds to a field in the stats_schema. There
44    // is one per column in the stats page table.
45    repeated int32 fields = 2;
47    // The file position of the statistics page table
48    //
49    // The page table is a matrix of N x 2, where N = length of stats_fields. This is
50    // the same layout as the main page table, except there is always only one
51    // batch.
52    //
53    // For example, to get the stats column 5, we have:
54    // ```text
55    //   position = stats_page_table[5][0];
56    //   length = stats_page_table[5][1];
57    // ```
58      uint64 page_table_position = 3;
59  }
61  StatisticsMetadata statistics = 5;
62} // Metadata

Optionally, a Manifest block can be stored after the Metadata block, to make the lance file self-describable.

In the end of the file, a Footer is written to indicate the closure of a file:

| 0 - 3 byte    | 4 - 7 byte     |
| metadata position (uint64)     |
| major version | minor version  |
|   Magic number "LANC"          |

Feature Flags

As the file format and dataset evolve, new feature flags are added to the format. There are two separate fields for checking for feature flags, depending on whether you are trying to read or write the table. Readers should check the reader_feature_flags to see if there are any flag it is not aware of. Writers should check writer_feature_flags. If either sees a flag they don’t know, they should return an “unsupported” error on any read or write operation.


Fields represent the metadata for a column. This includes the name, data type, id, nullability, and encoding.

Fields are listed in depth first order, and can be one of (1) parent (struct), (2) repeated (list/array), or (3) leaf (primitive). For example, the schema:

a: i32
b: struct {
    c: list<i32>
    d: i32

Would be represented as the following field list:
































Lance uses encodings that can render good both point query and scan performance. Generally, it requires:

  1. It takes no more than 2 disk reads to access any data points.

  2. It takes sub-linear computation (O(n)) to locate one piece of data.

Plain Encoding

Plain encoding stores Arrow array with fixed size values, such as primitive values, in contiguous space on disk. Because the size of each value is fixed, the offset of a particular value can be computed directly.

Null: TBD

Variable-Length Binary Encoding

For variable-length data types, i.e., (Large)Binary / (Large)String / (Large)List in Arrow, Lance uses variable-length encoding. Similar to Arrow in-memory layout, the on-disk layout include an offset array, and the actual data array. The offset array contains the absolute offset of each value appears in the file.

| offset array  | data array     |

If offsets[i] == offsets[i + 1], we treat the i-th value as Null.

Dictionary Encoding

Directory encoding is a composite encoding for a Arrow Dictionary Type, where Lance encodes the key and value separately using primitive encoding types, i.e., key are usually encoded with Plain Encoding.

Dataset Update and Schema Evolution

Lance supports fast dataset update and schema evolution via manipulating the Manifest metadata.

Appending is done by appending new Fragment to the dataset. While adding columns is done by adding new DataFile of the new columns to each Fragment. Finally, Overwrite a dataset can be done by resetting the Fragment list of the Manifest.



Rows can be marked deleted by adding a deletion file next to the data in the _deletions folder. These files contain the indices of rows that have between deleted for some fragment. For a given version of the dataset, each fragment can have up to one deletion file. Fragments that have no deleted rows have no deletion file.

Readers should filter out row ids contained in these deletion files during a scan or ANN search.

Deletion files come in two flavors:

  1. Arrow files: which store a column with a flat vector of indices

  2. Roaring bitmaps: which store the indices as compressed bitmaps.

Roaring Bitmaps are used for larger deletion sets, while Arrow files are used for small ones. This is because Roaring Bitmaps are known to be inefficient for small sets.

The filenames of deletion files are structured like:


Where fragment_id is the fragment the file corresponds to, read_version is the version of the dataset that it was created off of (usually one less than the version it was committed to), and random_id is a random i64 used to avoid collisions. The suffix is determined by the file type (.arrow for Arrow file, .bin for roaring bitmap).

 1// Deletion File
 3// The path of the deletion file is constructed as:
 4//   {root}/_deletions/{fragment_id}-{read_version}-{id}.{extension}
 5// where {extension} is `.arrow` or `.bin` depending on the type of deletion.
 6message DeletionFile {
 7  // Type of deletion file, which varies depending on what is the most efficient
 8  // way to store the deleted row offsets. If none, then will be unspecified. If there are
 9  // sparsely deleted rows, then ARROW_ARRAY is the most efficient. If there are
10  // densely deleted rows, then BIT_MAP is the most efficient.
11  enum DeletionFileType {
12    // Deletion file is a single Int32Array of deleted row offsets. This is stored as
13    // an Arrow IPC file with one batch and one column. Has a .arrow extension.
14    ARROW_ARRAY = 0;
15    // Deletion file is a Roaring Bitmap of deleted row offsets. Has a .bin extension.
16    BITMAP = 1;
17  }
19  // Type of deletion file. If it is unspecified, then the remaining fields will be missing.
20  DeletionFileType file_type = 1;
21  // The version of the dataset this deletion file was built from.
22  uint64 read_version = 2;
23  // An opaque id used to differentiate this file from others written by concurrent
24  // writers.
25  uint64 id = 3;
26  // The number of rows that are marked as deleted.
27  uint64 num_deleted_rows = 4;
28} // DeletionFile

Deletes can be materialized by re-writing data files with the deleted rows removed. However, this invalidates row indices and thus the ANN indices, which can be expensive to recompute.

Committing Datasets

A new version of a dataset is committed by writing a new manifest file to the _versions directory.

To prevent concurrent writers from overwriting each other, the commit process must be atomic and consistent for all writers. If two writers try to commit using different mechanisms, they may overwrite each other’s changes. For any storage system that natively supports atomic rename-if-not-exists or put-if-not-exists, these operations should be used. This is true of local file systems and cloud object stores, with the notable except of AWS S3. For ones that lack this functionality, an external locking mechanism can be configured by the user.

Conflict resolution

If two writers try to commit at the same time, one will succeed and the other will fail. The failed writer should attempt to retry the commit, but only if it’s changes are compatible with the changes made by the successful writer.

The changes for a given commit are recorded as a transaction file, under the _transactions prefix in the dataset directory. The transaction file is a serialized Transaction protobuf message. See the transaction.proto file for its definition.


The commit process is as follows:

  1. The writer finishes writing all data files.

  2. The writer creates a transaction file in the _transactions directory. This files describes the operations that were performed, which is used for two purposes: (1) to detect conflicts, and (2) to re-build the manifest during retries.

  3. Look for any new commits since the writer started writing. If there are any, read their transaction files and check for conflicts. If there are any conflicts, abort the commit. Otherwise, continue.

  4. Build a manifest and attempt to commit it to the next version. If the commit fails because another writer has already committed, go back to step 3.

When checking whether two transactions conflict, be conservative. If the transaction file is missing, assume it conflicts. If the transaction file has an unknown operation, assume it conflicts.

External Manifest Store

If the backing object store does not support *-if-not-exists operations, an external manifest store can be used to allow concurrent writers. An external manifest store is a KV store that supports put-if-not-exists operation. The external manifest store supplements but does not replace the manifests in object storage. A reader unaware of the external manifest store could read a table that uses it, but it might be up to one version behind the true latest version of the table.


The commit process is as follows:

  1. PUT_OBJECT_STORE mydataset.lance/_versions/{version}.manifest-{uuid} stage a new manifest in object store under a unique path determined by new uuid

  2. PUT_EXTERNAL_STORE base_uri, version, mydataset.lance/_versions/{version}.manifest-{uuid} commit the path of the staged manifest to the external store.

  3. COPY_OBJECT_STORE mydataset.lance/_versions/{version}.manifest-{uuid} mydataset.lance/_versions/{version}.manifest copy the staged manifest to the final path

  4. PUT_EXTERNAL_STORE base_uri, version, mydataset.lance/_versions/{version}.manifest update the external store to point to the final manifest

Note that the commit is effectively complete after step 2. If the writer fails after step 2, a reader will be able to detect the external store and object store are out-of-sync, and will try to synchronize the two stores. If the reattempt at synchronization fails, the reader will refuse to load. This is to ensure the that the dataset is always portable by copying the dataset directory without special tool.


The reader load process is as follows:

  1. GET_EXTERNAL_STORE base_uri, version, path then, if path does not end in a UUID return the path

  2. COPY_OBJECT_STORE mydataset.lance/_versions/{version}.manifest-{uuid} mydataset.lance/_versions/{version}.manifest reattempt synchronization

  3. PUT_EXTERNAL_STORE base_uri, version, mydataset.lance/_versions/{version}.manifest update the external store to point to the final manifest

  4. RETURN mydataset.lance/_versions/{version}.manifest always return the finalized path, return error if synchronization fails


Statistics are stored within Lance files. The statistics can be used to determine which pages can be skipped within a query. The null count, lower bound (min), and upper bound (max) are stored.

Statistics themselves are stored in Lance’s columnar format, which allows for selectively reading only relevant stats columns.

Statistic values

Three types of statistics are stored per column: null count, min value, max value. The min and max values are stored as their native data types in arrays.

There are special behavior for different data types to account for nulls:

For integer-based data types (including signed and unsigned integers, dates, and timestamps), if the min and max are unknown (all values are null), then the minimum/maximum representable values should be used instead.

For float data types, if the min and max are unknown, then use -Inf and +Inf, respectively. (-Inf and +Inf may also be used for min and max if those values are present in the arrays.) NaN values should be ignored for the purpose of min and max statistics. If the max value is zero (negative or positive), the max value should be recorded as +0.0. Likewise, if the min value is zero (positive or negative), it should be recorded as -0.0.

For binary data types, if the min or max are unknown or unrepresentable, then use null value. Binary data type bounds can also be truncated. For example, an array containing just the value "abcd" could have a truncated min of "abc" and max of "abd". If there is no truncated value greater than the maximum value, then instead use null for the maximum.


The min and max values are not guaranteed to be within the array; they are simply upper and lower bounds. Two common cases where they are not contained in the array is if the min or max original value was deleted and when binary data is truncated. Therefore, statistic should not be used to compute queries such as SELECT max(col) FROM table.

Page-level statistics format

Page-level statistics are stored as arrays within the Lance file. Each array contains one page long and is num_pages long. The page offsets are stored in an array just like the data page table. The offset to the statistics page table is stored in the metadata.

The schema for the statistics is:

<field_id_1>: struct
    null_count: i64
    min_value: <field_1_data_type>
    max_value: <field_1_data_type>
<field_id_N>: struct
    null_count: i64
    min_value: <field_N_data_type>
    max_value: <field_N_data_type>

Any number of fields may be missing, as statistics for some fields or of some kind may be skipped. In addition, readers should expect there may be extra fields that are not in this schema. These should be ignored. Future changes to the format may add additional fields, but these changes will be backwards compatible.

However, writers should not write extra fields that aren’t described in this document. Until they are defined in the specification, there is no guarantee that readers will be able to safely interpret new forms of statistics.

Feature: Move-Stable Row IDs

The row ids features assigns a unique u64 id to each row in the table. This id is stable after being moved (such as during compaction), but is not necessarily stable after a row is updated. (A future feature may make them stable after updates.) To make access fast, a secondary index is created that maps row ids to their locations in the table. The respective parts of these indices are stored in the respective fragment’s metadata.

row id

A unique auto-incrementing u64 id assigned to each row in the table.

row address

The current location of a row in the table. This is a u64 that can be thought of as a pair of two u32 values: the fragment id and the local row offset. For example, if the row address is (42, 9), then the row is in the 42rd fragment and is the 10th row in that fragment.

row id sequence

The sequence of row ids in a fragment.

row id index

A secondary index that maps row ids to row addresses. This index is constructed by reading all the row id sequences.

Assigning row ids

Row ids are assigned in a monotonically increasing sequence. The next row id is stored in the manifest as the field next_row_id. This starts at zero. When making a commit, the writer uses that field to assign row ids to new fragments. If the commit fails, the writer will re-read the new next_row_id, update the new row ids, and then try again. This is similar to how the max_fragment_id is used to assign new fragment ids.

When a row id updated, it it typically assigned a new row id rather than reusing the old one. This is because this feature doesn’t have a mechanism to update secondary indices that may reference the old values for the row id. By deleting the old row id and creating a new one, the secondary indices will avoid referencing stale data.

Row ID sequences

The row id values for a fragment are stored in a RowIdSequence protobuf message. This is described in the protos/rowids.proto file. Row id sequences are just arrays of u64 values, which have representations optimized for the common case where they are sorted and possibly contiguous. For example, a new fragment will have a row id sequence that is just a simple range, so it is stored as a start and end value.

These sequence messages are either stored inline in the fragment metadata, or are written to a separate file and referenced from the fragment metadata. This choice is typically made based on the size of the sequence. If the sequence is small, it is stored inline. If it is large, it is written to a separate file. By keeping the small sequences inline, we can avoid the overhead of additional IO operations.

  oneof row_id_sequence {
    // If small (< 200KB), the row ids are stored inline.
    bytes inline_row_ids = 5;
    // Otherwise, stored as part of a file.
    ExternalFile external_row_ids = 6;
  } // row_id_sequence

Row ID index

To ensure fast access to rows by their row id, a secondary index is created that maps row ids to their locations in the table. This index is built when a table is loaded, based on the row id sequences in the fragments. For example, if fragment 42 has a row id sequence of [0, 63, 10], then the index will have entries for 0 -> (42, 0), 63 -> (42, 1), 10 -> (42, 2). The exact form of this index is left up to the implementation, but it should be optimized for fast lookups.