Setup
docker run -d --name singlestoredb \
-p 3306:3306 \
-p 8080:8080 \
-e ROOT_PASSWORD=admin \
-e SINGLESTORE_DB=AGNO \
-e SINGLESTORE_USER=root \
-e SINGLESTORE_PASSWORD=password \
singlestore/cluster-in-a-box
docker start singlestoredb
After running the container, set the environment variables:
export SINGLESTORE_HOST="localhost"
export SINGLESTORE_PORT="3306"
export SINGLESTORE_USERNAME="root"
export SINGLESTORE_PASSWORD="admin"
export SINGLESTORE_DATABASE="AGNO"
SingleStore supports both cloud-based and local deployments. For step-by-step guidance on setting up your cloud deployment, please refer to the SingleStore Setup Guide.
Example
import typer
from typing import Optional
from os import getenv
from sqlalchemy.engine import create_engine
from agno.agent import Agent
from agno.knowledge.pdf_url import PDFUrlKnowledgeBase
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_base = PDFUrlKnowledgeBase(
urls=["https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
vector_db=SingleStore(
collection="recipes",
db_engine=db_engine,
schema=DATABASE,
),
)
def pdf_assistant(user: str = "user"):
run_id: Optional[str] = None
agent = Agent(
run_id=run_id,
user_id=user,
knowledge_base=knowledge_base,
use_tools=True,
show_tool_calls=True,
# Uncomment the following line to use traditional RAG
# add_references_to_prompt=True,
)
if run_id is None:
run_id = agent.run_id
print(f"Started Run: {run_id}\n")
else:
print(f"Continuing Run: {run_id}\n")
while True:
agent.cli_app(markdown=True)
if __name__ == "__main__":
# Comment out after first run
knowledge_base.load(recreate=False)
typer.run(pdf_assistant)
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 | Embedder | OpenAIEmbedder() | The embedder to use for creating vector embeddings. |
distance | Distance | Distance.cosine | The distance metric to use for similarity search. |
Developer Resources