NvidiaTextEmbedder
Embed strings, such as user queries, using NVIDIA models.
Key Features
- Embeds strings (typically user queries) using NVIDIA models for semantic search.
- Works with self-hosted models deployed with NVIDIA NIM or models hosted on the NVIDIA API Catalog.
- For models that differentiate between query and document inputs, this component embeds the input as a query.
- Use in query pipelines to transform a query into a vector.
- For embedding documents in indexes, use
NvidiaDocumentEmbedder.
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
- Drag the
NvidiaTextEmbeddercomponent onto the canvas from the Component Library. - Click on the component to open the configuration panel.
- On the General tab:
- Connect Haystack Platform to your NVIDIA account on the Integrations page. For instructions, see Use NVIDIA Models.
- Select the embedding model. Use the same model as in
NvidiaDocumentEmbedderin your indexing pipeline.
- Go to the Advanced tab to configure
prefix,suffix,truncate,timeout, andapi_url.
Connections
NvidiaTextEmbedder accepts a string through its text input. It outputs the embedding as a list of floats through its embedding output, plus usage metadata through its meta output.
Connect the Input component's query output to NvidiaTextEmbedder's text input. Then connect NvidiaTextEmbedder's embedding output to an embedding retriever's query_embedding input.
Source Code
To check this component's source code, open text_embedder.py in the Haystack Core Integrations repository.
Usage Examples
Basic Configuration
NvidiaTextEmbedder:
type: haystack_integrations.components.embedders.nvidia.text_embedder.NvidiaTextEmbedder
init_parameters:
api_key:
type: env_var
env_vars:
- NVIDIA_API_KEY
strict: true
model: nvidia/nv-embedqa-e5-v5
api_url: https://integrate.api.nvidia.com/v1
prefix: ''
suffix: ''
This is an example of a query pipeline with NvidiaTextEmbedder that receives a query, embeds it, and sends it to OpenSearchEmbeddingRetriever to find matching documents.
components:
NvidiaTextEmbedder:
type: haystack_integrations.components.embedders.nvidia.text_embedder.NvidiaTextEmbedder
init_parameters:
api_key:
type: env_var
env_vars:
- NVIDIA_API_KEY
strict: true
model: nvidia/nv-embedqa-e5-v5
api_url: https://integrate.api.nvidia.com/v1
prefix: ''
suffix: ''
truncate:
timeout:
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: nvidia-embeddings-index
max_chunk_bytes: 104857600
embedding_dim: 1024
return_embedding: false
method:
mappings:
settings:
create_index: true
http_auth:
use_ssl:
verify_certs:
timeout:
similarity: cosine
connections:
- sender: NvidiaTextEmbedder.embedding
receiver: OpenSearchEmbeddingRetriever.query_embedding
max_runs_per_component: 100
metadata: {}
inputs:
query:
- NvidiaTextEmbedder.text
outputs:
documents: OpenSearchEmbeddingRetriever.documents
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, including usage statistics. |
Init Parameters
These are the parameters you can configure in Pipeline Builder:
| Parameter | Type | Default | Description |
|---|---|---|---|
| model | Optional[str] | None | Embedding model to use. If no specific model along with locally hosted API URL is provided, the system defaults to the available model found using /models API. |
| api_key | Optional[Secret] | Secret.from_env_var('NVIDIA_API_KEY') | API key for the NVIDIA NIM. |
| api_url | str | os.getenv('NVIDIA_API_URL', DEFAULT_API_URL) | Custom API URL for the NVIDIA NIM. Format for API URL is http://host:port |
| prefix | str | A string to add to the beginning of each text. | |
| suffix | str | A string to add to the end of each text. | |
| truncate | Optional[Union[EmbeddingTruncateMode, str]] | None | Specifies how inputs longer that the maximum token length should be truncated. If None the behavior is model-dependent, see the official documentation for more information. |
| timeout | Optional[float] | None | Timeout for request calls, if not set it is inferred from the NVIDIA_TIMEOUT environment variable or set to 60 by default. |
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. |
Related Information
Was this page helpful?