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
OllamaDocumentEmbedderin the indexing pipeline.
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
- 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
modelto the same embedding model used in your indexing pipeline (for example,nomic-embed-text). - Set the
urlto your Ollama server address. The default ishttp://localhost:11434.
- Set the
- Go to the Advanced tab to configure
timeout,keep_alive, anddimensions.
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
| Parameter | Type | Description |
|---|---|---|
text | str | The text to embed. |
Outputs
| Parameter | Type | Description |
|---|---|---|
embedding | List[float] | The embedding of the text. |
meta | Dict[str, Any] | Metadata about the request. |
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 Ollama embedding model to use. |
url | str | http://localhost:11434 | The URL of the Ollama API server. |
generation_kwargs | Optional[Dict[str, Any]] | None | Additional parameters for the embedding request. |
timeout | int | 120 | Request timeout in seconds. |
keep_alive | Optional[Union[float, str]] | None | Controls how long the model stays loaded in memory. |
dimensions | Optional[int] | None | The 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.
| Parameter | Type | Default | Description |
|---|---|---|---|
text | str | The text to embed. | |
generation_kwargs | Optional[Dict[str, Any]] | None | Generation parameters to override init-time values. |
Related Information
Was this page helpful?