This example demonstrates how to use LanceDB as a vector database/retriever within a VoltAgent application.
- Local & Serverless: Uses LanceDB which runs embedded locally—no Docker or API keys required (unless using LanceDB Cloud).
- Multimodal Ready: LanceDB is optimized for multimodal data (text, images, video), making this a future-proof foundation.
- Automatic Initialization: Automatically creates the knowledge base table and populates it with sample data on first run.
- Semantic Search: Uses OpenAI embeddings to retrieve relevant documents based on user queries.
- Two Agent Patterns:
- Assistant with Retriever: Automatically uses retrieved context for every message.
- Assistant with Tools: Autonomously decides when to use the retrieval tool.
- Node.js 20+
- OpenAI API Key (for embeddings and LLM)
-
Install dependencies:
npm install
-
Configure Environment: Copy
.env.exampleto.envand add your OpenAI API Key:cp .env.example .env
Edit
.env:OPENAI_API_KEY=sk-...
-
Run the Agent:
npm run dev
- The database is stored locally in
.voltagent/lancedb. - On startup,
src/retriever/index.tschecks if the table exists. - If not, it creates it and indexes the sample documents defined in the code.
- Agents can then query this local database with low latency.