Skip to content

Build a Chatbot in 10 Minutes

In this tutorial, we will build a simple Retrieval Augmented Generation (RAG) system using Embex and LanceDB (embedded, no setup required).

Install the libraries:

Terminal window
pip install embex lancedb sentence-transformers openai

Create a new file bot.py:

import asyncio
from embex import EmbexClient, Point
from sentence_transformers import SentenceTransformer
# 1. Setup
embedder = SentenceTransformer('all-MiniLM-L6-v2')
client = await EmbexClient.new_async("lancedb", "./chatbot_data")
collection = client.collection("knowledge_base")

Let’s add some knowledge.

async def ingest():
texts = [
"Embex is a unified vector database ORM.",
"It supports Qdrant, Chroma, and more.",
"Rust core makes it blazingly fast."
]
# Create DB
await collection.create(384) # dimensionality of all-MiniLM-L6-v2
# Embed and Insert
points = []
for i, text in enumerate(texts):
vector = embedder.encode(text).tolist()
points.append(Point(id=str(i), vector=vector, metadata={"text": text}))
await collection.insert(points)
print("Ingestion complete!")

Now let’s search.

async def search(query):
vector = embedder.encode(query).tolist()
results = await collection.search(vector, top_k=1)
if results:
best = results[0]
print(f"Query: {query}")
print(f"Answer: {best.metadata['text']}")
else:
print("I don't know.")
async def main():
await ingest()
await search("What makes Embex fast?")
if __name__ == "__main__":
asyncio.run(main())

Run it:

Terminal window
python bot.py
# Output:
# Query: What makes Embex fast?
# Answer: Rust core makes it blazingly fast.