Skip to main content
For the complete documentation index for agents and LLMs, see llms.txt.

OllamaTextEmbedder

Embed strings using embedding models served with Ollama. Use this component in query pipelines to transform user queries into vectors for embedding-based retrieval.

Key Features

  • Works with any embedding model available through Ollama.
  • Outputs a float vector embedding suitable for use with embedding retrievers.
  • The embedding model must match the one used by OllamaDocumentEmbedder in the indexing pipeline.
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.

Configuration

  1. Drag the OllamaTextEmbedder component onto the canvas from the Component Library.
  2. Click on the component to open the configuration panel.
  3. On the General tab:
    1. Set the model to the same embedding model used in your indexing pipeline (for example, nomic-embed-text).
    2. Set the url to your Ollama server address. The default is http://localhost:11434.
  4. Go to the Advanced tab to configure timeout, keep_alive, and dimensions.

Connections

OllamaTextEmbedder receives the user query as a text string, typically from the Input component. It outputs a float vector through its embedding output, which you connect to an embedding retriever such as OpenSearchEmbeddingRetriever.

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

Using the Component in a Pipeline

# haystack-pipeline
components:
OllamaTextEmbedder:
type: haystack_integrations.components.embedders.ollama.text_embedder.OllamaTextEmbedder
init_parameters:
model: nomic-embed-text
url: http://localhost:11434
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
document_store:
type: haystack_integrations.document_stores.opensearch.document_store.OpenSearchDocumentStore
init_parameters:
hosts:
index: my-index
embedding_dim: 768

connections:
- sender: OllamaTextEmbedder.embedding
receiver: OpenSearchEmbeddingRetriever.query_embedding

max_runs_per_component: 100

metadata: {}

inputs:
query:
- OllamaTextEmbedder.text

Parameters

Inputs

ParameterTypeDescription
textstrThe text to embed.

Outputs

ParameterTypeDescription
embeddingList[float]The embedding of the text.
metaDict[str, Any]Metadata about the request.

Init Parameters

These are the parameters you can configure in Pipeline Builder:

ParameterTypeDefaultDescription
modelstrnomic-embed-textThe name of the Ollama embedding model to use.
urlstrhttp://localhost:11434The URL of the Ollama API server.
generation_kwargsOptional[Dict[str, Any]]NoneAdditional parameters for the embedding request.
timeoutint120Request timeout in seconds.
keep_aliveOptional[Union[float, str]]NoneControls how long the model stays loaded in memory.
dimensionsOptional[int]NoneThe number of dimensions in the output embedding, if supported by the model.

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.

ParameterTypeDefaultDescription
textstrThe text to embed.
generation_kwargsOptional[Dict[str, Any]]NoneGeneration parameters to override init-time values.