Agent with Knowledge
Code
1from kern.agent import Agent2from kern.knowledge.embedder.ollama import OllamaEmbedder3from kern.knowledge.knowledge import Knowledge4from kern.models.lmstudio import LMStudio5from kern.vectordb.pgvector import PgVector67db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"89knowledge_base = Knowledge(10 vector_db=PgVector(11 table_name="recipes",12 db_url=db_url,13 embedder=OllamaEmbedder(id="llama3.2", dimensions=3072),14 ),15)16knowledge_base.insert(17 url="https://kern-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"18)1920agent = Agent(21 model=LMStudio(id="qwen2.5-7b-instruct-1m"),22 knowledge=knowledge_base,23 )24agent.print_response("How to make Thai curry?", markdown=True)Usage
Set up your virtual environment
1uv venv --python 3.122source .venv/bin/activate1uv venv --python 3.122.venv\Scripts\activateInstall LM Studio
Install LM Studio from here and download the model you want to use.
Install dependencies
1uv pip install -U sqlalchemy pgvector pypdf kern-aiRun PgVector
1docker run -d \2 -e POSTGRES_DB=ai \3 -e POSTGRES_USER=ai \4 -e POSTGRES_PASSWORD=ai \5 -e PGDATA=/var/lib/postgresql/data/pgdata \6 -v pgvolume:/var/lib/postgresql/data \7 -p 5532:5432 \8 --name pgvector \9 agnohq/pgvector:16Run Agent
1python cookbook/11_models/lmstudio/knowledge.py