From db7ba85e1040eb33eb66178ba480d892f2486192 Mon Sep 17 00:00:00 2001 From: vodkar Date: Mon, 18 Nov 2024 13:39:08 +0500 Subject: [PATCH] Added ollama embedder Added some documentation --- cookbook/providers/ollama_tools/knowledge.py | 23 +++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/cookbook/providers/ollama_tools/knowledge.py b/cookbook/providers/ollama_tools/knowledge.py index 964983e6e6..158f8c2717 100644 --- a/cookbook/providers/ollama_tools/knowledge.py +++ b/cookbook/providers/ollama_tools/knowledge.py @@ -1,15 +1,32 @@ -"""Run `pip install duckduckgo-search sqlalchemy pgvector pypdf openai ollama` to install dependencies.""" +""" +Run `pip install duckduckgo-search sqlalchemy pgvector pypdf openai ollama` to install dependencies. + +Run Ollama Server: `ollama serve` +Pull required models: +`ollama pull openhermes` +`ollama pull llama3.1:8b` + +If you haven't deployed database yet, run: +`docker run --rm -it -e POSTGRES_PASSWORD=ai -e POSTGRES_USER=ai -e POSTGRES_DB=ai -p 5532:5432 --name postgres pgvector/pgvector:pg17` +to deploy a PostgreSQL database. + +""" from phi.agent import Agent -from phi.model.ollama import OllamaTools +from phi.embedder.ollama import OllamaEmbedder from phi.knowledge.pdf import PDFUrlKnowledgeBase +from phi.model.ollama import OllamaTools from phi.vectordb.pgvector import PgVector db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai" knowledge_base = PDFUrlKnowledgeBase( urls=["https://phi-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"], - vector_db=PgVector(table_name="recipes", db_url=db_url), + vector_db=PgVector( + table_name="recipes", + db_url=db_url, + embedder=OllamaEmbedder(host="http://localhost:11434"), + ), ) knowledge_base.load(recreate=False) # Comment out after first run