1. Install LanceDB
Choose your language. Python uses Pandas to display the search results. TypeScript needs Node.js 22.18 or later to run the.mts example directly.
polars feature provides DataFrame output; remote also lets this example connect to Enterprise.
Python pre-release builds and older CPUs
Python pre-release builds and older CPUs
Python pre-release builds
To pick up the latest features and bug fixes before the next stable release, install a pre-release from LanceDB’s Fury index.lancedb. Install the optional pylance extra and
include the Lance preview index only when building query engines or connectors,
calling format-level lance APIs directly, converting plain-scan lazy blob
handles with to_pandas(), or reading legacy v1 blob bytes into pandas with
Python 0.41.0 or 0.42.0b8. Those clients use the native bytes path for supported
v2 blob queries; they still need pylance for legacy pandas bytes conversion:pylance releases; current Lance previews
are published to the lance-format index. By default, uv only considers versions
from the first index containing a package, which can select an old pylance or
backtrack to an older LanceDB release. unsafe-best-match searches all configured
indexes, like pip; use it only with indexes you trust. Install the extra rather
than an unconstrained pylance so LanceDB’s minimum supported version is enforced.Pre-release builds receive the same level of testing as stable releases, but their availability is not guaranteed
for more than 6 months after release. For real-world workloads, we recommend you use the latest stable release
as far as possible.
Older x86_64 CPUs
The defaultlancedb wheel targets x86-64-haswell (AVX2 + FMA + F16C). On older x86_64 CPUs without AVX2
(Intel Sandy Bridge, Ivy Bridge, Westmere; AMD Bulldozer, Piledriver, Steamroller), import lancedb crashes
with Illegal instruction.Install lancedb-compat instead. It exposes the same API (import lancedb still works), is built at the
x86-64-v2 baseline, and uses runtime SIMD dispatch to still use AVX2, FMA, or AVX-512 when available:lancedb/ namespace and conflict at install time, so pick one. To switch,
uninstall the other first (pip uninstall lancedb && pip install lancedb-compat).2. Connect to a database
Local directory
LanceDB creates anex_lancedb directory to store your tables. No server is needed.
Object storage
Use ans3://, gs://, or az:// URI in place of the local path. See Object storage for credentials and provider-specific options.
Enterprise
Use the database URI, API key, and endpoint provided by your administrator or the LanceDB team. Replace the placeholders below with those details. Use the deployment’s region if provided; otherwise keepus-east-1.
In application code, load credentials from environment variables or a secrets manager. See connection settings for an example.
3. Create a table and add data
Each row describes a frame from a robot video clip and stores an embedding alongside its video, caption, and quality stats.These embeddings are made up for this example. In your application, use an embedding model to generate them from your data.
Frame records
Frame records
frames table from those records:
frames table in the database you connect to.
Add one more frame:
4. Search the table
Find the two embeddings closest to the query embedding. This example uses a fixed embedding; it does not call an embedding model._distance column measures how far each result is from your query embedding, with smaller values indicating a closer match.
5. Curate data with SQL
Step 5 needs LanceDB Enterprise: SQL is an Enterprise feature. If you’re
using LanceDB Embedded, skip ahead to
Flatten nested fields below.
execute_query().
Now add a near-duplicate frame — frame 5 is one video frame after frame 2, with
an almost identical embedding — and build the vector index that dedupe reads:
duplicate_pairs,
resolution strategies, and tuning distance_threshold, and
Statistical Sampling for percentage samples,
repeatable draws, and sampling across a join.
6. Add a derived feature
Flatten nested fields
A UDF binds to top-level columns, so flatten the fields insidestats first.
This is a plain eager add_columns call, so it works the same on LanceDB
Embedded and LanceDB Enterprise — step 8 needs these columns
either way:
The rest of this step needs LanceDB Enterprise — Functions are an
Enterprise feature. If you’re using LanceDB Embedded, skip ahead to
step 7.
refresh_column fills only rows added since the last refresh and recomputes rows whose inputs changed, leaving unchanged rows alone. Run the same refresh as a background job instead, so it doesn’t block:
7. Store multimodal data
Store images, audio, or other binary data alongside vectors and metadata, in a column of raw bytes. This creates a new table from one image file — replace the path with one of your own:8. Train on your data
Read table data into PyTorch, projecting and shuffling only the columns a training step needs:StreamingDataset wraps a table for PyTorch training reads; columns projects before reading, so a training step touches only the columns it selects, not unused ones such as caption or embedding. It works the same way against LanceDB Embedded and LanceDB Enterprise. See PyTorch Data Loader for shuffling, transforms, resuming, and multi-worker loading, and Permutation for the lower-level row-ordering primitive it’s built on.
Where to go next
Basic table operations
Create, update, and manage your tables.
Build a RAG app
Use retrieved context in a language model application.
Indexing
Speed up queries on larger datasets.
Embedding models
Generate vectors from your own data.