OllamaTextEmbedder
Embed strings, such as user queries, using Ollama models.
Key Features
- Uses Ollama to run embedding models locally, without external API services.
- Outputs a dense embedding vector for the input text.
- Must use the same embedding model as
OllamaDocumentEmbedderused in the index. - Default model is
nomic-embed-text. - Compatible with embedding models available in Ollama's library.
Configuration
Before using this component, make sure you have a running Ollama instance with the embedding model pulled.
- Drag the
OllamaTextEmbeddercomponent onto the canvas from the Component Library. - Click on the component to open the configuration panel.
- On the General tab:
- Set the model name. The model must already be available in your running Ollama instance. See other pre-built models in Ollama's library.
- Set the
urlto point to your Ollama server (default:http://localhost:11434).
- Go to the Advanced tab to configure
timeoutandgeneration_kwargs.
Embedding Models in Query Pipelines and Indexes
The embedding model you use to embed documents in your indexing pipeline must be the same as the embedding model you use to embed the query in your query pipeline.
This means the embedders for your indexing and query pipelines must match. For example, if you use CohereDocumentEmbedder to embed your documents, you should use CohereTextEmbedder with the same model to embed your queries.
Connections
OllamaTextEmbedder accepts a text string as input. In a query pipeline, connect its text input to the query output of the Input component.
It outputs a dense embedding vector as List[float]. Connect its embedding output to the query_embedding input of an embedding retriever.
To embed documents in an index instead, use OllamaDocumentEmbedder.
Source Code
To check this component's source code, open text_embedder.py in the Haystack Core Integrations repository.
Usage Examples
Basic Configuration
OllamaTextEmbedder:
type: haystack_integrations.components.embedders.ollama.text_embedder.OllamaTextEmbedder
init_parameters:
model: nomic-embed-text
url: http://localhost:11434
timeout: 120
This is an example query pipeline with OllamaTextEmbedder that embeds a query and sends it to OpenSearchEmbeddingRetriever to find matching documents.
components:
OllamaTextEmbedder:
type: haystack_integrations.components.embedders.ollama.text_embedder.OllamaTextEmbedder
init_parameters:
model: nomic-embed-text
url: http://localhost:11434
generation_kwargs:
timeout: 120
OpenSearchEmbeddingRetriever:
type: haystack_integrations.components.retrievers.opensearch.embedding_retriever.OpenSearchEmbeddingRetriever
init_parameters:
filters:
top_k: 10
filter_policy: replace
custom_query:
raise_on_failure: true
efficient_filtering: true
document_store:
type: haystack_integrations.document_stores.opensearch.document_store.OpenSearchDocumentStore
init_parameters:
hosts:
index: ollama-embeddings-index
max_chunk_bytes: 104857600
embedding_dim: 768
return_embedding: false
method:
mappings:
settings:
create_index: true
http_auth:
use_ssl:
verify_certs:
timeout:
similarity: cosine
connections:
- sender: OllamaTextEmbedder.embedding
receiver: OpenSearchEmbeddingRetriever.query_embedding
max_runs_per_component: 100
metadata: {}
inputs:
query:
- OllamaTextEmbedder.text
outputs:
documents: OpenSearchEmbeddingRetriever.documents
Parameters
Inputs
| Parameter | Type | Default | Description |
|---|---|---|---|
text | str | Text to be converted to an embedding. | |
generation_kwargs | Optional[Dict[str, Any]] | None | Optional arguments to pass to the Ollama generation endpoint, such as temperature, top_p, etc. See the Ollama docs. |
Outputs
| Parameter | Type | Default | Description |
|---|---|---|---|
embedding | List[float] | The embedding of the text. | |
meta | Dict[str, Any] | Metadata about the request, including the model name. |
Init Parameters
These are the parameters you can configure in Pipeline Builder:
| Parameter | Type | Default | Description |
|---|---|---|---|
model | str | nomic-embed-text | The name of the model to use. The model should be available in the running Ollama instance. |
url | str | http://localhost:11434 | The URL of a running Ollama instance. |
generation_kwargs | Optional[Dict[str, Any]] | None | Optional arguments to pass to the Ollama generation endpoint, such as temperature, top_p, and others. See the available arguments in Ollama docs. |
timeout | int | 120 | The number of seconds before throwing a timeout error from the Ollama API. |
Run Method Parameters
These are the parameters you can configure for the component's run() method. This means you can pass these parameters at query time through the API, in Playground, or when running a job. For details, see Modify Pipeline Parameters at Query Time.
| Parameter | Type | Default | Description |
|---|---|---|---|
text | str | Text to be converted to an embedding. | |
generation_kwargs | Optional[Dict[str, Any]] | None | Optional arguments to pass to the Ollama generation endpoint, such as temperature, top_p, etc. See the Ollama docs. |
Was this page helpful?