Skip to content

Commit

Permalink
Merge pull request #1463 from vodkar/fix-knowledge-example-1459
Browse files Browse the repository at this point in the history
Fixed ollama knowledge example
  • Loading branch information
ysolanky authored Nov 28, 2024
2 parents 2e340f2 + 42820ae commit c7baaf1
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions cookbook/providers/ollama_tools/knowledge.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
"""Run `pip install duckduckgo-search sqlalchemy pgvector pypdf openai ollama "psycopg[binary]"` 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 nomic-embed-text`
`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(model="nomic-embed-text", dimensions=768),
),
)
knowledge_base.load(recreate=False) # Comment out after first run

Expand Down

0 comments on commit c7baaf1

Please sign in to comment.