LlamaIndex Vector Store - LanceDB

raw JSON →
0.5.0 verified Fri May 01 auth: no python

LanceDB vector store integration for LlamaIndex. Current version 0.5.0. Provides a LanceDBVectorStore class for storing and querying vector embeddings. Release cadence is irregular; follows LlamaIndex package structure. Supports hybrid search and column filtering in LanceDB.

pip install llama-index-vector-stores-lancedb
error ModuleNotFoundError: No module named 'llama_index.vector_stores.lancedb'
cause Package not installed correctly or import path is wrong for version < 0.4.0.
fix
Install the package: pip install llama-index-vector-stores-lancedb. For versions older than 0.4.0, use: from llama_index.vector_stores.lancedb.base import LanceDBVectorStore
error TypeError: LanceDBVectorStore.__init__() got an unexpected keyword argument 'connection'
cause The 'connection' parameter was removed in v0.4.0; constructor now expects 'uri' and 'table_name'.
fix
Change to: LanceDBVectorStore(uri='your_uri', table_name='your_table')
error lancedb.error.LanceError: Invalid argument: Dimension mismatch: expected 768 but got 1536
cause Embedding dimension provided to LanceDB table does not match the dimension of the vectors being inserted.
fix
Set the dimension explicitly when creating the vector store or table: LanceDBVectorStore(uri=uri, table_name=table_name, dim=1536)
breaking LanceDBVectorStore no longer accepts 'connection' parameter; use 'uri' instead. As of v0.4.0, the constructor requires 'uri' and 'table_name' directly.
fix Replace `LanceDBVectorStore(connection=db)` with `LanceDBVectorStore(uri=uri, table_name=table_name)`.
gotcha The vector dimension must match the embedding model dimension. LanceDB does not automatically validate dimensions; mismatches cause runtime errors.
fix Ensure embedding dimension passed to LanceDBVectorStore matches your embedding model's dimension. Default is 1536 for OpenAI but can be set via 'dim' parameter.
gotcha Table must exist before using LanceDBVectorStore; the store does not automatically create tables. Use lancedb.connect(uri).create_table(table_name, data) first.
fix Create the table explicitly using the LanceDB Python API before using the vector store.

Minimal working example: connect to LanceDB, create a vector store, build an index, and query.

import lancedb
from llama_index.core import SimpleDirectoryReader, StorageContext, VectorStoreIndex
from llama_index.vector_stores.lancedb import LanceDBVectorStore

# Create LanceDB connection and table
uri = "data/sample-lancedb"
db = lancedb.connect(uri)
table_name = "my_table"
table = db.create_table(table_name, data=[{"vector": [0.0]*768, "text": "placeholder"}], mode="overwrite")

# Initialize vector store
vector_store = LanceDBVectorStore(uri=uri, table_name=table_name)

# Create storage context
storage_context = StorageContext.from_defaults(vector_store=vector_store)

# Load documents and build index
documents = SimpleDirectoryReader("data").load_data()
index = VectorStoreIndex.from_documents(documents, storage_context=storage_context)

# Query
query_engine = index.as_query_engine()
response = query_engine.query("What is LanceDB?")
print(response)