Schema evolution enables non-breaking modifications to a database table’s structure — such as adding columns, altering data types, or dropping fields — to adapt to evolving data requirements without service interruptions. LanceDB supports ACID-compliant schema evolution through granular operations (add/alter/drop columns), allowing you to:Documentation Index
Fetch the complete documentation index at: https://docs.lancedb.com/llms.txt
Use this file to discover all available pages before exploring further.
- Iterate Safely: Modify schemas in production with versioned datasets and backward compatibility
- Scale Seamlessly: Handle ML model iterations, regulatory changes, or feature additions
- Optimize Continuously: Remove unused fields or enforce new constraints without downtime
Schema evolution operations
LanceDB supports three primary schema evolution operations:- Adding new columns: Extend your table with additional attributes
- Altering existing columns: Change column names, data types, or nullability
- Dropping columns: Remove unnecessary columns from your schema
Add new columns
You can add new columns to a table with theadd_columns
method in Python, addColumns in TypeScript/JavaScript, or add_columns in Rust.
New columns are populated based on SQL expressions you provide.
Set up the example table
First, let’s create a sample table with product data to demonstrate schema evolution:Add derived columns
You can add new columns that are derived from existing data using SQL expressions:Add columns with default values
Add boolean columns with default values for status tracking:Add nullable columns
Add timestamp columns that can contain NULL values:Alter existing columns
You can alter columns using thealter_columns
method in Python, alterColumns in TypeScript/JavaScript, or alter_columns in Rust. This allows you to:
- Rename a column
- Change a column’s data type
- Modify nullability (whether a column can contain NULL values)
Set up the example table
Create a table with a custom schema to demonstrate column alterations:Rename columns
Change column names to better reflect their purpose:Change data types
Convert column data types for better performance or compatibility:Make columns nullable
You can alter columns to contain NULL values:Multiple changes at once
Apply several alterations in a single operation:Expression-based type changes
For transformations that are not simple casts (for example, converting"$100" to an integer), use a SQL-expression column add, then drop and rename:
Alter embedding types and dimensions
It’s quite common to need to change an embedding column’s schema, in case a new model becomes available with a different embedding dimension.- In Python, the example shows an in-place type update when the cast is compatible.
- In TypeScript and Rust, the example shows a dimension change (
384 -> 1024), which cannot be cast in-place.
Drop columns
You can remove columns using thedrop_columns
method in Python, dropColumns in TypeScript/JavaScript, or drop_columns in Rust.