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

OllamaDocumentEmbedder

Compute embeddings for a list of documents using embedding models served with Ollama. Use this component in indexing pipelines to prepare documents for embedding-based retrieval.

Key Features

  • Works with any embedding model available through Ollama.
  • Stores the computed embedding in each document's embedding field.
  • Supports adding a prefix and suffix to document text before embedding.
  • Allows embedding metadata fields alongside document content.
  • Processes documents in configurable batches.
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 OllamaDocumentEmbedder 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 an embedding model available on your Ollama server (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 prefix, suffix, batch_size, meta_fields_to_embed, and embedding_separator.

Connections

OllamaDocumentEmbedder receives a list of documents, typically from a document splitter or converter. It outputs the same documents with embeddings added to their embedding field, ready to be sent to a DocumentWriter.

Source Code

To check this component's source code, open document_embedder.py in the Haystack Core Integrations repository.

Usage Examples

Basic Configuration

  OllamaDocumentEmbedder:
type: haystack_integrations.components.embedders.ollama.document_embedder.OllamaDocumentEmbedder
init_parameters:
model: nomic-embed-text
url: http://localhost:11434
batch_size: 32

Using the Component in a Pipeline

# haystack-pipeline
components:
OllamaDocumentEmbedder:
type: haystack_integrations.components.embedders.ollama.document_embedder.OllamaDocumentEmbedder
init_parameters:
model: nomic-embed-text
url: http://localhost:11434
batch_size: 32
meta_fields_to_embed:
embedding_separator: "\n"

document_writer:
type: haystack.components.writers.document_writer.DocumentWriter
init_parameters:
document_store:
type: haystack_integrations.document_stores.opensearch.document_store.OpenSearchDocumentStore
init_parameters:
hosts:
index: my-index
embedding_dim: 768

connections:
- sender: OllamaDocumentEmbedder.documents
receiver: document_writer.documents

max_runs_per_component: 100

metadata: {}

Parameters

Inputs

ParameterTypeDescription
documentsList[Document]A list of documents to embed.

Outputs

ParameterTypeDescription
documentsList[Document]The documents with their embedding field populated.
metaDict[str, Any]Metadata about the embedding 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.
prefixstr""A string to add at the beginning of each document's text before embedding.
suffixstr""A string to add at the end of each document's text before embedding.
progress_barboolTrueWhether to show a progress bar during embedding.
meta_fields_to_embedOptional[List[str]]NoneA list of document metadata field names to include in the text before embedding.
embedding_separatorstr"\n"The separator used to join the document text and metadata fields.
batch_sizeint32The number of documents to process in each batch.
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
documentsList[Document]A list of documents to embed.
generation_kwargsOptional[Dict[str, Any]]NoneGeneration parameters to override init-time values.