Embeddings
Ollama Embedder
The OllamaEmbedder
can be used to embed text data into vectors locally using Ollama. Note: The model used for generating embeddings needs to runn 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
Parameter | Type | Default | Description |
---|---|---|---|
model | str | "openhermes" | The name of the model used for generating embeddings. |
dimensions | int | 4096 | The dimensionality of the embeddings generated by the model. |
host | str | - | The host address for the API endpoint. |
timeout | Any | - | The timeout duration for API requests. |
options | Any | - | Additional options for configuring the API request. |
client_kwargs | Optional[Dict[str, Any]] | - | Additional keyword arguments for configuring the API client. Optional. |
ollama_client | Optional[OllamaClient] | - | An instance of the OllamaClient to use for making API requests. Optional. |