from raghilda.embedding import EmbeddingOllama, EmbedInputType
provider = EmbeddingOllama(
model="embeddinggemma-2:270m-q8_0-text",
prompts={
EmbedInputType.QUERY: "task: search result | query: ",
EmbedInputType.DOCUMENT: "title: none | text: ",
},
)
document_embeddings = provider.embed(
["Authentication requires an API key."],
input_type=EmbedInputType.DOCUMENT,
)
query_embeddings = provider.embed(
["How do I configure authentication?"],
input_type=EmbedInputType.QUERY,
)embedding.EmbeddingOllama
Creates an embedding function provider backed by a local Ollama server.
Usage
embedding.EmbeddingOllama(
model="embeddinggemma-2:270m-q8_0-text",
base_url="http://localhost:11434/v1",
api_key=None,
batch_size=20,
prompts=None,
)Implements the EmbeddingProvider interface.
This provider uses Ollama’s OpenAI-compatible API with defaults for a local server. Stores created with it can be reconnected without setting OPENAI_API_KEY.
Pull an embedding model before using it (e.g., ollama pull embeddinggemma-2:270m-q8_0-text). Browse available embedding models at ollama.com/search.
Set prompts= when creating the provider to configure the model’s query and document prefixes. On each embed() call, input_type= selects which prefix to use for the supplied texts. It defaults to EmbedInputType.DOCUMENT. Stores select the input type automatically during ingestion and retrieval.
Parameters
model: str = "embeddinggemma-2:270m-q8_0-text"-
The Ollama embedding model to use. Default is “embeddinggemma-2:270m-q8_0-text”, a text-only build. The default is a pinned tag rather than
:latestbecause the store saves only the model name, and:latestcan resolve to different builds over time or across platforms, which would silently degrade retrieval. base_url: str = "http://localhost:11434/v1"-
The base URL for the Ollama server’s OpenAI-compatible API. Default is “http://localhost:11434/v1”. Change this when Ollama runs on another machine or port.
api_key: str | None = None-
The API key sent with each request. Ollama does not check it, so this is only needed when the server sits behind a proxy that requires one. If None, uses
OLLAMA_API_KEYfrom the environment, or a placeholder if unset. Keys are not saved with the store. SetOLLAMA_API_KEYbefore reconnecting to a store that uses an authenticated proxy. batch_size: int = 20-
The number of texts to process in each batch when calling the API.
prompts: dict[EmbedInputType, str] | None = None-
Optional prefix strings keyed by EmbedInputType. The
input_typeargument to embed() selects the prefix to add to each text in that call. Use the query and document prefixes recommended by your model. If no prefix is configured for the selected type, text is sent unchanged. These settings are saved with the store.