ClickHouse Async
Code
1import asyncio23from kern.agent import Agent4from kern.knowledge.knowledge import Knowledge5from kern.vectordb.clickhouse import Clickhouse67agent = Agent(8 knowledge=Knowledge(9 vector_db=Clickhouse(10 table_name="recipe_documents",11 host="localhost",12 port=8123,13 username="ai",14 password="ai",15 ),16 ),17 search_knowledge=True,18 read_chat_history=True,19)2021if __name__ == "__main__":22 asyncio.run(23 agent.knowledge.ainsert(url="https://kern.ndx.rocks/introduction/agents.md")24 )2526 asyncio.run(27 agent.aprint_response("What is the purpose of an Kern Agent?", markdown=True)28 )Usage
Set up your virtual environment
1uv venv --python 3.122source .venv/bin/activate1uv venv --python 3.122.venv\Scripts\activateInstall dependencies
1uv pip install -U clickhouse-connect pypdf openai kern-aiRun ClickHouse
1docker run -d \2-e CLICKHOUSE_DB=ai \3-e CLICKHOUSE_USER=ai \4-e CLICKHOUSE_PASSWORD=ai \5-e CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT=1 \6-v clickhouse_data:/var/lib/clickhouse/ \7-v clickhouse_log:/var/log/clickhouse-server/ \8-p 8123:8123 \9-p 9000:9000 \10--ulimit nofile=262144:262144 \11--name clickhouse-server \12clickhouse/clickhouse-serverSet environment variables
1export CLICKHOUSE_HOST="localhost"2export CLICKHOUSE_PORT="8123"3export CLICKHOUSE_USER="ai"4export CLICKHOUSE_PASSWORD="ai"5export CLICKHOUSE_DB="ai"6export OPENAI_API_KEY=xxxRun Agent
1python cookbook/08_knowledge/vector_db/clickhouse_db/async_clickhouse.py