SingleStore Vector Database
Use SingleStore as a vector database for your Knowledge Base.
This local setup uses the SingleStore development image. Check its platform requirements before starting Docker. The named volume stores the database at /data.
Setup
uv pip install -U PyMySQL sqlalchemy pypdf openai agnoRun SingleStore with Docker:
docker run -d --name singlestoredb \
--platform linux/amd64 \
-p 3306:3306 \
-p 8080:8080 \
-v agno-singlestore-data:/data \
-e ROOT_PASSWORD=admin \
ghcr.io/singlestore-labs/singlestoredb-dev:latestWait until docker inspect --format '{{.State.Health.Status}}' singlestoredb reports healthy. If it becomes unhealthy or exits, inspect docker logs singlestoredb before continuing. Then create the database:
docker exec singlestoredb singlestore -u root -padmin \
-e "CREATE DATABASE IF NOT EXISTS AGNO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"Then set the environment variables:
export SINGLESTORE_HOST="localhost"
export SINGLESTORE_PORT="3306"
export SINGLESTORE_USERNAME="root"
export SINGLESTORE_PASSWORD="admin"
export SINGLESTORE_DATABASE="AGNO"
export OPENAI_API_KEY="your-api-key"SingleStore supports both cloud-based and local deployments. For cloud setup, see the SingleStore Setup Guide.
Example
from os import getenv
from sqlalchemy.engine import create_engine
from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.vectordb.singlestore import SingleStore
USERNAME = getenv("SINGLESTORE_USERNAME")
PASSWORD = getenv("SINGLESTORE_PASSWORD")
HOST = getenv("SINGLESTORE_HOST")
PORT = getenv("SINGLESTORE_PORT")
DATABASE = getenv("SINGLESTORE_DATABASE")
SSL_CERT = getenv("SINGLESTORE_SSL_CERT", None)
db_url = f"mysql+pymysql://{USERNAME}:{PASSWORD}@{HOST}:{PORT}/{DATABASE}?charset=utf8mb4"
if SSL_CERT:
db_url += f"&ssl_ca={SSL_CERT}&ssl_verify_cert=true"
db_engine = create_engine(db_url)
knowledge = Knowledge(
vector_db=SingleStore(
collection="recipes",
db_engine=db_engine,
schema=DATABASE,
),
)
agent = Agent(
knowledge=knowledge,
search_knowledge=True,
)
if __name__ == "__main__":
knowledge.insert(
url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"
)
agent.print_response("How do I make pad thai?", markdown=True)Async Support ⚡
SingleStore exposes async ingestion and query methods. Embedding calls can be awaited, but schema checks, SQL writes, and the async search fallback use synchronous SQLAlchemy operations.
import asyncio
from os import getenv
from sqlalchemy.engine import create_engine
from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.vectordb.singlestore import SingleStore
USERNAME = getenv("SINGLESTORE_USERNAME")
PASSWORD = getenv("SINGLESTORE_PASSWORD")
HOST = getenv("SINGLESTORE_HOST")
PORT = getenv("SINGLESTORE_PORT")
DATABASE = getenv("SINGLESTORE_DATABASE")
SSL_CERT = getenv("SINGLESTORE_SSL_CERT", None)
db_url = f"mysql+pymysql://{USERNAME}:{PASSWORD}@{HOST}:{PORT}/{DATABASE}?charset=utf8mb4"
if SSL_CERT:
db_url += f"&ssl_ca={SSL_CERT}&ssl_verify_cert=true"
db_engine = create_engine(db_url)
knowledge = Knowledge(
vector_db=SingleStore(
collection="recipes",
db_engine=db_engine,
schema=DATABASE,
),
)
agent = Agent(
knowledge=knowledge,
search_knowledge=True,
)
if __name__ == "__main__":
asyncio.run(
knowledge.ainsert(url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf")
)
asyncio.run(agent.aprint_response("How do I make pad thai?", markdown=True))Use ainsert() and aprint_response() in async application code. These APIs do not make all SQL work nonblocking; move blocking work to workers when your concurrency requirements need it.
SingleStore Params
| Parameter | Type | Default | Description |
|---|---|---|---|
collection | str | - | The name of the collection to use. |
schema | Optional[str] | "ai" | The database schema to use. |
db_url | Optional[str] | None | The database connection URL. |
db_engine | Optional[Engine] | None | SQLAlchemy engine instance. |
embedder | Optional[Embedder] | OpenAIEmbedder() | The embedder to use for creating vector embeddings. |
distance | Distance | Distance.cosine | The distance metric to use for similarity search. |
reranker | Optional[Reranker] | None | Reranker instance to rerank search results. |
name | Optional[str] | None | Name of the vector database. |
description | Optional[str] | None | Description of the vector database. |