Implementation:CrewAIInc CrewAI LanceDB Adapter
| Knowledge Sources | |
|---|---|
| Domains | Vector_Search, RAG, Embeddings |
| Last Updated | 2026-02-11 00:00 GMT |
Overview
Concrete adapter for LanceDB vector database integration provided by CrewAI.
Description
The LanceDBAdapter class implements the Adapter interface from CrewAI's RAG tool framework, providing seamless integration with LanceDB, a fast embedded vector database. It connects to a LanceDB instance using a configurable URI (file path or connection string), opens a specified table, and exposes methods for semantic search (query) and data ingestion (add). The adapter uses a configurable embedding function that defaults to OpenAI's text-embedding-ada-002 model to convert text queries into vector representations for similarity search. Results are retrieved via LanceDB's vector search with configurable top_k limit and returned as newline-joined text strings.
Usage
Import and instantiate LanceDBAdapter when you need to connect CrewAI's RAG tool pipeline to a LanceDB vector database for semantic retrieval. This is particularly suited for local or embedded deployments where a lightweight vector store is preferred over cloud-hosted alternatives.
Code Reference
Source Location
- Repository: CrewAI
- File: lib/crewai-tools/src/crewai_tools/adapters/lancedb_adapter.py
- Lines: 1-59
Signature
class LanceDBAdapter(Adapter):
uri: str | Path
table_name: str
embedding_function: Callable = Field(default_factory=_default_embedding_function)
top_k: int = 3
vector_column_name: str = "vector"
text_column_name: str = "text"
Import
from crewai_tools.adapters.lancedb_adapter import LanceDBAdapter
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| uri | Path | Yes | LanceDB connection URI (file path or connection string) |
| table_name | str | Yes | Name of the LanceDB table to open |
| embedding_function | Callable | No | Function to generate embeddings; defaults to OpenAI text-embedding-ada-002 |
| top_k | int | No | Number of top results to return from vector search (default: 3) |
| vector_column_name | str | No | Name of the vector column in the table (default: "vector") |
| text_column_name | str | No | Name of the text column in the table (default: "text") |
Outputs
| Name | Type | Description |
|---|---|---|
| query() return | str | Newline-joined text values from the top_k most similar results |
| add() return | None | Adds data directly to the underlying LanceDB table (pass-through) |
Usage Examples
Basic Usage
from crewai_tools.adapters.lancedb_adapter import LanceDBAdapter
# Connect to a local LanceDB instance
adapter = LanceDBAdapter(
uri="/path/to/lancedb",
table_name="my_documents",
top_k=5,
)
# Query for semantically similar content
results = adapter.query("What is the company refund policy?")
print(results)
Custom Embedding Function
from crewai_tools.adapters.lancedb_adapter import LanceDBAdapter
def custom_embeddings(texts):
# Custom embedding logic
return [[0.1, 0.2, ...] for _ in texts]
adapter = LanceDBAdapter(
uri="/path/to/lancedb",
table_name="my_documents",
embedding_function=custom_embeddings,
vector_column_name="embeddings",
text_column_name="content",
)