> ## Documentation Index
> Fetch the complete documentation index at: https://phidatainc-studio-tools-doc.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# SingleStore Async

## Code

```python cookbook/08_knowledge/vector_db/singlestore_db/singlestore_db.py theme={null}
import asyncio
from os import getenv

from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.vectordb.singlestore import SingleStore
from sqlalchemy.engine import create_engine

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)

vector_db = SingleStore(
    collection="recipes",
    db_engine=db_engine,
    schema=DATABASE,
)

knowledge = Knowledge(name="My SingleStore Knowledge Base", vector_db=vector_db)

agent = Agent(
    knowledge=knowledge,
    search_knowledge=True,
    read_chat_history=True,
)

if __name__ == "__main__":
    asyncio.run(
        knowledge.ainsert(
            name="Recipes",
            url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf",
            metadata={"doc_type": "recipe_book"},
        )
    )

    asyncio.run(
        agent.aprint_response("How do I make pad thai?", markdown=True)
    )
```

## Usage

<Steps>
  <Snippet file="create-venv-step.mdx" />

  <Step title="Install dependencies">
    ```bash theme={null}
    uv pip install -U PyMySQL sqlalchemy pypdf openai agno
    ```
  </Step>

  <Step title="Run SingleStore">
    ```bash theme={null}
    docker run -d --name singlestoredb \
    --platform linux/amd64 \
    -p 3306:3306 \
    -p 8080:8080 \
    -v /tmp:/var/lib/memsql \
    -e ROOT_PASSWORD=admin \
    -e SINGLESTORE_DB=AGNO \
    -e SINGLESTORE_USER=root \
    -e SINGLESTORE_PASSWORD=admin \
    -e LICENSE_KEY=accept \
    ghcr.io/singlestore-labs/singlestoredb-dev:latest

    docker start singlestoredb

    docker exec singlestoredb memsql -u root -padmin -e "CREATE DATABASE IF NOT EXISTS AGNO;"
    ```
  </Step>

  <Step title="Set environment variables">
    ```bash theme={null}
    export SINGLESTORE_HOST="localhost"
    export SINGLESTORE_PORT="3306"
    export SINGLESTORE_USERNAME="root"
    export SINGLESTORE_PASSWORD="admin"
    export SINGLESTORE_DATABASE="AGNO"
    export SINGLESTORE_SSL_CA=".certs/singlestore_bundle.pem"
    export OPENAI_API_KEY=xxx
    ```
  </Step>

  <Step title="Run Agent">
    ```bash theme={null}
    python cookbook/08_knowledge/vector_db/singlestore_db/singlestore_db.py
    ```
  </Step>
</Steps>
