ClickHouse Async

Load and query a ClickHouse knowledge base asynchronously with ainsert() and aprint_response().

Code

async_clickhouse.py
import asyncio

from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.vectordb.clickhouse import Clickhouse

agent = Agent(
    knowledge=Knowledge(
        vector_db=Clickhouse(
            table_name="recipe_documents",
            host="localhost",
            port=8123,
            username="ai",
            password="ai",
        ),
    ),
    search_knowledge=True,
    read_chat_history=True,
)

async def main():
    await agent.knowledge.ainsert(
        url="https://docs.agno.com/agents/overview.md"
    )
    await agent.aprint_response(
        "What is the purpose of an Agno Agent?",
        markdown=True,
    )

if __name__ == "__main__":
    asyncio.run(main())

Usage

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U "clickhouse-connect[async]<1.0" pypdf openai agno

Run ClickHouse

docker run -d \
-e CLICKHOUSE_DB=ai \
-e CLICKHOUSE_USER=ai \
-e CLICKHOUSE_PASSWORD=ai \
-e CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT=1 \
-v clickhouse_data:/var/lib/clickhouse/ \
-v clickhouse_log:/var/log/clickhouse-server/ \
-p 8123:8123 \
-p 9000:9000 \
--ulimit nofile=262144:262144 \
--name clickhouse-server \
clickhouse/clickhouse-server

Set environment variables

export OPENAI_API_KEY=xxx

Run Agent

python async_clickhouse.py