VertexAIDocumentEmbedder
Embed documents using Vertex AI Embeddings API.
Key Features
- Embeds documents using the Vertex AI Embeddings API
- Configurable task type (RETRIEVAL_DOCUMENT, RETRIEVAL_QUERY, and others)
- Batch processing support for efficient embedding of large document sets
- Built-in retry logic for reliability
- Stores embeddings in each document's
embeddingfield
Configuration
- Drag the
VertexAIDocumentEmbeddercomponent onto the canvas from the Component Library. - Click on the component to open the configuration panel.
- On the General tab:
- Enter your GCP project ID and region. Create secrets with the keys
GCP_PROJECT_IDandGCP_DEFAULT_REGION. For detailed instructions, see Create Secrets. - Select a model. For supported models, see the official Google documentation.
- Select a task type. Use
RETRIEVAL_DOCUMENTwhen embedding documents for storage.
- Enter your GCP project ID and region. Create secrets with the keys
- Go to the Advanced tab to configure batch size, retries, truncation, and metadata field settings.
Connections
VertexAIDocumentEmbedder accepts a list of Document objects through its documents input. It outputs a list of Document objects with embeddings stored in the embedding field.
Use this component in an indexing pipeline. Connect preprocessors like DocumentSplitter to its documents input, and connect its documents output to DocumentWriter.
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.
Source Code
To check this component's source code, open document_embedder.py in the Haystack Core Integrations repository.
Usage Examples
Basic Configuration
VertexAIDocumentEmbedder:
type: haystack_integrations.components.embedders.google_vertex.document_embedder.VertexAIDocumentEmbedder
init_parameters:
model: text-embedding-005
task_type: RETRIEVAL_DOCUMENT
gcp_region_name:
type: env_var
env_vars:
- GCP_DEFAULT_REGION
strict: false
gcp_project_id:
type: env_var
env_vars:
- GCP_PROJECT_ID
strict: false
batch_size: 32
max_tokens_total: 20000
time_sleep: 30
retries: 3
progress_bar: true
embedding_separator: "\n"
This index uses VertexAIDocumentEmbedder to embed documents before storing them:
components:
TextFileToDocument:
type: haystack.components.converters.txt.TextFileToDocument
init_parameters:
encoding: utf-8
store_full_path: false
DocumentSplitter:
type: haystack.components.preprocessors.document_splitter.DocumentSplitter
init_parameters:
split_by: sentence
split_length: 5
split_overlap: 1
VertexAIDocumentEmbedder:
type: haystack_integrations.components.embedders.google_vertex.document_embedder.VertexAIDocumentEmbedder
init_parameters:
model: text-embedding-005
task_type: RETRIEVAL_DOCUMENT
gcp_region_name:
type: env_var
env_vars:
- GCP_DEFAULT_REGION
strict: false
gcp_project_id:
type: env_var
env_vars:
- GCP_PROJECT_ID
strict: false
batch_size: 32
max_tokens_total: 20000
time_sleep: 30
retries: 3
progress_bar: true
truncate_dim:
meta_fields_to_embed:
embedding_separator: "\n"
DocumentWriter:
type: haystack.components.writers.document_writer.DocumentWriter
init_parameters:
document_store:
type: haystack_integrations.document_stores.opensearch.document_store.OpenSearchDocumentStore
init_parameters:
hosts:
index: 'vertex-embeddings'
max_chunk_bytes: 104857600
embedding_dim: 768
return_embedding: false
method:
mappings:
settings:
create_index: true
http_auth:
use_ssl:
verify_certs:
timeout:
policy: OVERWRITE
connections:
- sender: TextFileToDocument.documents
receiver: DocumentSplitter.documents
- sender: DocumentSplitter.documents
receiver: VertexAIDocumentEmbedder.documents
- sender: VertexAIDocumentEmbedder.documents
receiver: DocumentWriter.documents
inputs:
files:
- TextFileToDocument.sources
max_runs_per_component: 100
metadata: {}
Parameters
Inputs
| Parameter | Type | Description |
|---|---|---|
documents | List[Document] | A list of documents to embed. |
Outputs
| Parameter | Type | Description |
|---|---|---|
documents | List[Document] | A list of documents with embeddings. |
Init Parameters
These are the parameters you can configure in Pipeline Builder:
| Parameter | Type | Default | Description |
|---|---|---|---|
model | Literal['text-embedding-004', 'text-embedding-005', ...] | Name of the model to use. | |
task_type | Literal['RETRIEVAL_DOCUMENT', 'RETRIEVAL_QUERY', ...] | RETRIEVAL_DOCUMENT | The type of task for which the embeddings are being generated. See Google documentation. |
gcp_region_name | Optional[Secret] | Secret.from_env_var('GCP_DEFAULT_REGION', strict=False) | The default location to use when making API calls. If not set, uses us-central-1. |
gcp_project_id | Optional[Secret] | Secret.from_env_var('GCP_PROJECT_ID', strict=False) | ID of the GCP project to use. |
batch_size | int | 32 | The number of documents to process in a single batch. |
max_tokens_total | int | 20000 | The maximum number of tokens to process in total. |
time_sleep | int | 30 | The time to sleep between retries in seconds. |
retries | int | 3 | The number of retries in case of failure. |
progress_bar | bool | True | Whether to display a progress bar during processing. |
truncate_dim | Optional[int] | None | The dimension to truncate the embeddings to, if specified. |
meta_fields_to_embed | Optional[List[str]] | None | A list of metadata fields to include in the embeddings. |
embedding_separator | str | \n | The separator to use between different embeddings. |
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 | Description |
|---|---|---|
documents | List[Document] | A list of documents to embed. |
Related Information
Was this page helpful?