Knowledge
Code
1from kern.agent import Agent2from kern.knowledge.embedder.ollama import OllamaEmbedder3from kern.knowledge.knowledge import Knowledge4from kern.models.ollama import Ollama5from kern.vectordb.pgvector import PgVector67db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"89knowledge = Knowledge(10 vector_db=PgVector(11 table_name="recipes",12 db_url=db_url,13 embedder=OllamaEmbedder(id="llama3.2", dimensions=3072),14 ),15)16# Add content to the knowledge17knowledge.insert(18 url="https://kern-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"19)2021agent = Agent(model=Ollama(id="llama3.2"), knowledge=knowledge)22agent.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 Ollama
Follow the Ollama installation guide and run:
1ollama pull llama3.2Install dependencies
1uv pip install -U kern-ai sqlalchemy pgvector pypdf openai ollamaRun Agent
1python cookbook/11_models/ollama/knowledge.py