LanceDB vector store backend for fabricatio RAG
Project description
fabricatio-lancedb
LanceDB vector store backend for Fabricatio RAG. Provides async Rust-backed table operations — creation, document insertion, vector similarity search, and index rebuilding — plus Python-side RAG capability mixins and document models.
Architecture
The package has two layers:
| Layer | Language | Key Types | Purpose |
|---|---|---|---|
| Rust (PyO3) | Rust | VectorStoreService, VectorStoreTable, StoreDocument, SearchedDocument |
High-performance LanceDB table ops with async execution |
| Python | Python | LancedbRAG, LancedbDocumentModel, LancedbConfig |
RAG capability, document models, configuration |
The Rust layer manages LanceDB connections and tables. The Python layer
implements the fabricatio-rag RAG interface on top of those primitives:
batching embeddings, inserting documents, and searching by vector.
Installation
pip install fabricatio[lancedb]
# or
uv pip install fabricatio[lancedb]
For all Fabricatio extras:
pip install fabricatio[full]
Configuration
Configure the LanceDB database URI and default table name via environment,
.env, fabricatio.toml, or pyproject.toml:
FABRICATIO_LANCEDB__DATABASE_URI=./lance.db
FABRICATIO_LANCEDB__DEFAULT_TABLE_NAME=my_docs
In fabricatio.toml:
[lancedb]
database_uri = "./lance.db"
default_table_name = "my_docs"
The config fields:
| Field | Default | Description |
|---|---|---|
database_uri |
"./lance.db" |
LanceDB connection URI (local path or S3 s3://bucket/path) |
default_table_name |
"default" |
Table name used when none is specified |
Access at runtime:
from fabricatio_lancedb.config import lancedb_config
print(lancedb_config.database_uri)
Usage
Low-level Rust API
Direct table operations with async Rust execution:
import asyncio
from fabricatio_lancedb.rust import VectorStoreService, VectorStoreTable, StoreDocument
async def main():
# Connect to LanceDB
service = await VectorStoreService.connect("./lance.db")
# Create a table for 1536-dim embeddings (OpenAI text-embedding-3-small)
table = await service.create_table("my_table", ndim=1536)
# Add documents
docs = [
StoreDocument(
content="LanceDB is a fast, open-source vector database.",
vector=[0.1] * 1536,
),
StoreDocument.with_metadata(
content="Fabricatio is an LLM application framework.",
vector=[0.2] * 1536,
metadata={"source": "docs", "version": "1.0"},
),
]
ids = await table.add_documents(docs)
print(f"Inserted: {ids}")
# Search by embedding
results = await table.search_document(embedding=[0.15] * 1536, limit=5)
for r in results:
print(f"{r.id}: {r.content[:60]}...")
print(f" metadata: {r.access_metadata()}")
# Rebuild the index after bulk inserts with rebuild_index=False
await table.rebuild_index()
asyncio.run(main())
RAG capability (high-level)
Integrate with Fabricatio's RAG system using the LancedbRAG mixin:
from fabricatio_lancedb.capabilities.lancedb import LancedbRAG, LancedbAddRAGConfig, LancedbFetchRAGConfig
from fabricatio_lancedb.models.lancedb import LancedbDocumentModel
class MyDoc(LancedbDocumentModel):
"""Custom document with additional fields."""
title: str = ""
class MyRAGRole(SomeBaseRole, LancedbRAG[MyDoc, LancedbAddRAGConfig, LancedbFetchRAGConfig[MyDoc]]):
pass
async def run():
role = MyRAGRole()
# Add a document — handles embedding batching internally
await role.add_document(
MyDoc(content="Semantic search with LanceDB and Fabricatio.", title="Intro"),
config=LancedbAddRAGConfig(table_name="docs", embedding_batch_size=20),
)
# Fetch relevant documents
results = await role.afetch_document(
"how does semantic search work",
config=LancedbFetchRAGConfig(document_model=MyDoc, limit=10),
)
for doc in results:
print(f"[{doc.title}] {doc.content}")
Cached service helper
Reuse connections across calls:
from fabricatio_lancedb.inited_service import get_service
service = await get_service("s3://my-bucket/lancedb")
table = await service.open_table("production_docs")
API Reference
Rust layer (fabricatio_lancedb.rust)
VectorStoreService
| Method | Signature | Returns | Description |
|---|---|---|---|
connect |
(uri: str) -> Awaitable[Self] |
VectorStoreService |
Static — connect to a LanceDB instance |
create_table |
(table_name: str, ndim: int) -> Awaitable[VectorStoreTable] |
VectorStoreTable |
Create a new table with the given vector dimension |
open_table |
(table_name: str) -> Awaitable[VectorStoreTable] |
VectorStoreTable |
Open an existing table |
create_or_open_table |
(table_name: str, ndim: int) -> Awaitable[VectorStoreTable] |
VectorStoreTable |
Create if absent, otherwise open |
VectorStoreTable
| Method | Signature | Returns | Description |
|---|---|---|---|
add_documents |
(documents: list[StoreDocument], rebuild_index: bool = True) -> Awaitable[list[str]] |
Document IDs | Insert documents; set rebuild_index=False for bulk inserts |
search_document |
(embedding: list[float], limit: int) -> Awaitable[list[SearchedDocument]] |
Search results | Nearest-neighbor vector search |
rebuild_index |
() -> Awaitable[None] |
None | Rebuild the vector index (no-op if <256 rows) |
StoreDocument
| Field | Type | Description |
|---|---|---|
content |
str |
Document text content |
vector |
list[float] |
Dense embedding vector |
metadata |
str | None |
Optional JSON-serialized metadata |
Static constructor StoreDocument.with_metadata(content, vector, metadata: dict) serializes
the metadata dict to JSON.
SearchedDocument
| Property | Type | Description |
|---|---|---|
id |
str |
UUID document identifier |
content |
str |
Matched document text |
timestamp |
int |
Microsecond-precision timestamp |
metadata |
str | None |
Raw JSON metadata string |
Method access_metadata() -> dict parses the JSON metadata into a Python dict.
Python layer
LancedbRAG
Extends RAG from fabricatio-rag with LanceDB storage.
| Method | Description |
|---|---|
add_document(data, config) |
Vectorize and insert one or more documents |
afetch_document(query, config) |
Vectorize a query string and return matching documents |
rebuild_index(table_name?) |
Rebuild the vector index on a table |
LancedbAddRAGConfig
Dataclass config for add_document:
| Field | Default | Description |
|---|---|---|
table_name |
lancedb_config.default_table_name |
Target table |
embedding_batch_size |
10 |
Documents per embedding batch |
embedding_parallel_size |
10 |
Max concurrent embedding calls |
rebuild_index |
False |
Rebuild index after insertion |
LancedbFetchRAGConfig
Dataclass config for afetch_document:
| Field | Default | Description |
|---|---|---|
table_name |
lancedb_config.default_table_name |
Source table |
document_model |
None (required) |
Document model class for deserialization |
limit |
15 |
Max results returned |
LancedbDocumentModel
Extends StoredDocumentModel and SearchedDocumentModel. Fields: content (str), metadata (dict | None).
| Method | Description |
|---|---|
prepare_insertion(vector) -> StoreDocument |
Build a Rust StoreDocument ready for insertion |
from_raw(raw: SearchedDocument) -> Self |
Deserialize a Rust SearchedDocument |
with_text_chunk(chunk: str) -> Self |
Create from a plain text chunk |
Schema
Each LanceDB table uses this Arrow schema:
| Column | Type | Nullable | Description |
|---|---|---|---|
item |
Utf8 |
no | Primary key (UUID v7) |
timestamp |
Time64(µs) |
no | Insertion timestamp |
vector |
FixedSizeList(Float32, ndim) |
no | Embedding vector |
content |
Utf8 |
no | Document text |
metadata |
Utf8 |
yes | JSON-serialized metadata |
Dependencies
fabricatio-core— core interfaces and configurationfabricatio-rag— base RAG abstractions (RAG, document models)more-itertools— chunked iteration for batch processingasync-lru— async LRU caching
Rust dependencies (via PyO3): lancedb, arrow, pyo3, tokio.
License
This project is licensed under the MIT License — see LICENSE.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fabricatio_lancedb-0.3.2-cp314-cp314-win_amd64.whl.
File metadata
- Download URL: fabricatio_lancedb-0.3.2-cp314-cp314-win_amd64.whl
- Upload date:
- Size: 51.0 MB
- Tags: CPython 3.14, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b8158d67ef1d04c10332ba35b990cd7fa4c73a8850eabd310994440af6a6e88
|
|
| MD5 |
e38574d7c24e3b4708edb585875f0eaa
|
|
| BLAKE2b-256 |
16a0a7549ccba851158498a002cbf82764e842cc76fb1a5c72b14df637921463
|
File details
Details for the file fabricatio_lancedb-0.3.2-cp314-cp314-manylinux_2_38_x86_64.whl.
File metadata
- Download URL: fabricatio_lancedb-0.3.2-cp314-cp314-manylinux_2_38_x86_64.whl
- Upload date:
- Size: 53.7 MB
- Tags: CPython 3.14, manylinux: glibc 2.38+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce346f2a7ee827972edba4dc92ca71c4c6abd34645ae65929c4fa0d0a553b335
|
|
| MD5 |
aa5075eb46171a06dfdefe7c3185479e
|
|
| BLAKE2b-256 |
57da4c66901f855e4c859a16f2d40478fc9a73654d7e72ae4738b1b13b965f5f
|
File details
Details for the file fabricatio_lancedb-0.3.2-cp314-cp314-manylinux_2_38_aarch64.whl.
File metadata
- Download URL: fabricatio_lancedb-0.3.2-cp314-cp314-manylinux_2_38_aarch64.whl
- Upload date:
- Size: 46.6 MB
- Tags: CPython 3.14, manylinux: glibc 2.38+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
264db70a3e1620a1c4b55b9415e9b94540b732b1291b8df294fda855773260d1
|
|
| MD5 |
11fb2ce453b4ccb23198af752060a381
|
|
| BLAKE2b-256 |
b988e43a2a308313f706d3ff01e3980c538326d4f000e212fbff768e4b6fdf51
|
File details
Details for the file fabricatio_lancedb-0.3.2-cp314-cp314-macosx_11_0_arm64.whl.
File metadata
- Download URL: fabricatio_lancedb-0.3.2-cp314-cp314-macosx_11_0_arm64.whl
- Upload date:
- Size: 46.9 MB
- Tags: CPython 3.14, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56571a0f393d57f8265a12bf7bd5fe2c7c4bcbaa9d59e8bb27c5b79afc76f33a
|
|
| MD5 |
5b805fb37f1cf80e4f0ecbbab94d17c9
|
|
| BLAKE2b-256 |
19b6cd607af9b4cfe2b288ee07c18b627651ed1c6f6fea45360c74c00f4b676f
|
File details
Details for the file fabricatio_lancedb-0.3.2-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: fabricatio_lancedb-0.3.2-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 51.0 MB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82e72d3ae47d7d098f799a182430066bce5701b596d601c63031e237dc55c5b7
|
|
| MD5 |
35a5ffce379df966692967d4522c69c6
|
|
| BLAKE2b-256 |
dc908e174524218ffad997d99a37c0ad3a4faae5d3a09e96917197643d80f829
|
File details
Details for the file fabricatio_lancedb-0.3.2-cp313-cp313-manylinux_2_38_x86_64.whl.
File metadata
- Download URL: fabricatio_lancedb-0.3.2-cp313-cp313-manylinux_2_38_x86_64.whl
- Upload date:
- Size: 53.7 MB
- Tags: CPython 3.13, manylinux: glibc 2.38+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d10e734cd5cc8deeeacc6c2c3daa7989c54e2c631ec023c37ffd36299b3b152
|
|
| MD5 |
fbb3391095298c41ab191624e7e914e8
|
|
| BLAKE2b-256 |
20645ed7569005622703400df20640c4f06af127d7c4176c6c44c35fe890d314
|
File details
Details for the file fabricatio_lancedb-0.3.2-cp313-cp313-manylinux_2_38_aarch64.whl.
File metadata
- Download URL: fabricatio_lancedb-0.3.2-cp313-cp313-manylinux_2_38_aarch64.whl
- Upload date:
- Size: 46.6 MB
- Tags: CPython 3.13, manylinux: glibc 2.38+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1cc66ffba2d1bf9619815bd30b24d2a73ec5bd2f003b27035ac55fd9dfd982b0
|
|
| MD5 |
fe6ec4274ff4a7e100c5e640ac364a77
|
|
| BLAKE2b-256 |
fcfa23238570885e3630e6beaba0e5586ee8656a877059ca36df7106e9811321
|
File details
Details for the file fabricatio_lancedb-0.3.2-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: fabricatio_lancedb-0.3.2-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 46.9 MB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81f6df28e77634654e5f2e824e7693be54496d2e079a4682d9f8b6bf1c8969b9
|
|
| MD5 |
86e74d23c825e891d5336fe43c1772dd
|
|
| BLAKE2b-256 |
77ce5118b877f26ac2e1cb9cf9343ad605fe28b6ea10826ec401b30ae35b9e8f
|
File details
Details for the file fabricatio_lancedb-0.3.2-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: fabricatio_lancedb-0.3.2-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 51.0 MB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed033f8a4656c00b50edbedb35b30222801c77e319b94b070dd77c990879e674
|
|
| MD5 |
5d30d9b179970d1f27308eb66978fddf
|
|
| BLAKE2b-256 |
a9001ec26f642360b01115190282053f64e44b84ce81534a3a1d1e8272a3f5df
|
File details
Details for the file fabricatio_lancedb-0.3.2-cp312-cp312-manylinux_2_38_x86_64.whl.
File metadata
- Download URL: fabricatio_lancedb-0.3.2-cp312-cp312-manylinux_2_38_x86_64.whl
- Upload date:
- Size: 53.7 MB
- Tags: CPython 3.12, manylinux: glibc 2.38+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
446e04061b728b7d157beb0dd4ab2f6961a37080eeeea5acc17242569fd8f317
|
|
| MD5 |
41a187bed13239c16e5ba72493a0a26c
|
|
| BLAKE2b-256 |
8a3b23f8d702454de7071ca94632d59d2301936e056ce434eb8a7f01eb64a60a
|
File details
Details for the file fabricatio_lancedb-0.3.2-cp312-cp312-manylinux_2_38_aarch64.whl.
File metadata
- Download URL: fabricatio_lancedb-0.3.2-cp312-cp312-manylinux_2_38_aarch64.whl
- Upload date:
- Size: 46.6 MB
- Tags: CPython 3.12, manylinux: glibc 2.38+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
21fa2265bf648ebaaa22652770d0b8f50ea084b4375eab70586b46c999c058a2
|
|
| MD5 |
eb66334bf2721d437b19e01e077f794b
|
|
| BLAKE2b-256 |
df740ee9f0d197fd1f237adac1fb333bf4b102b414c67aa72450ebb047150633
|
File details
Details for the file fabricatio_lancedb-0.3.2-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: fabricatio_lancedb-0.3.2-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 46.9 MB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd48f5b0d8397d6cb6909a864bf58ebcbc1572be541d054144673d02b5f9f8fd
|
|
| MD5 |
b847b4699bfcb66e016472bdf26a15f6
|
|
| BLAKE2b-256 |
22359ac01391e904d1d5157a2d7e21182f2c078c49f1545953f31992efc99c2c
|