The OllamaEmbedder can be used to embed text data into vectors locally using Ollama.

The model used for generating embeddings needs to run locally.

Usage

from phi.agent import Agent, AgentKnowledge
from phi.vectordb.pgvector import PgVector
from phi.embedder.ollama import OllamaEmbedder

# Create knowledge base
knowledge_base=AgentKnowledge(
    vector_db=PgVector(
        db_url=db_url,
        table_name=embeddings_table,
        embedder=OllamaEmbedder(),
    ),
    # 2 references are added to the prompt
    num_documents=2,
),

# Add information to the knowledge base
knowledge_base.load_text("The sky is blue")

# Add the knowledge base to the Agent
agent = Agent(knowledge_base=knowledge_base)

Params

ParameterTypeDefaultDescription
modelstr"openhermes"The name of the model used for generating embeddings.
dimensionsint4096The dimensionality of the embeddings generated by the model.
hoststr-The host address for the API endpoint.
timeoutAny-The timeout duration for API requests.
optionsAny-Additional options for configuring the API request.
client_kwargsOptional[Dict[str, Any]]-Additional keyword arguments for configuring the API client. Optional.
ollama_clientOptional[OllamaClient]-An instance of the OllamaClient to use for making API requests. Optional.