VertexAIGeminiGenerator
Generate text using Google Gemini models through Vertex AI.
This integration will be deprecated soon. We recommend using GoogleGenAIChatGenerator instead, which provides unified access to both Gemini Developer API and Vertex AI.
Key Features
- Text generation using Google Gemini models through Vertex AI
- Supports multimodal inputs including text and images
- Streaming support for real-time token-by-token responses
- Designed for text generation, not chat (use
GoogleGenAIChatGeneratorfor chat capabilities) - Authenticates using Google Cloud Application Default Credentials (ADCs)
Configuration
- Drag the
VertexAIGeminiGeneratorcomponent 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. Create a secret with the key
GCP_PROJECT_ID. For detailed instructions, see Create Secrets. - Optionally, enter the location. If not set, uses
us-central1. - Select a model. For available models, see Vertex AI models.
- Enter your GCP project ID. Create a secret with the key
- Go to the Advanced tab to configure generation settings, safety settings, system instruction, and streaming.
Connections
VertexAIGeminiGenerator accepts multimodal inputs through its parts input — a list of strings, ByteStream objects, or Part objects. It outputs generated text as replies (a list of strings).
Connect PromptBuilder's prompt output to this component's parts input. Connect the replies output to AnswerBuilder.
Source Code
To check this component's source code, open gemini.py in the Haystack Core Integrations repository.
Usage Examples
Basic Configuration
VertexAIGeminiGenerator:
type: haystack_integrations.components.generators.google_vertex.gemini.VertexAIGeminiGenerator
init_parameters:
model: gemini-2.0-flash
This query pipeline uses VertexAIGeminiGenerator to generate text responses:
components:
bm25_retriever:
type: haystack_integrations.components.retrievers.opensearch.bm25_retriever.OpenSearchBM25Retriever
init_parameters:
document_store:
type: haystack_integrations.document_stores.opensearch.document_store.OpenSearchDocumentStore
init_parameters:
hosts:
index: 'default'
max_chunk_bytes: 104857600
embedding_dim: 768
return_embedding: false
method:
mappings:
settings:
create_index: true
http_auth:
use_ssl:
verify_certs:
timeout:
top_k: 10
fuzziness: 0
PromptBuilder:
type: haystack.components.builders.prompt_builder.PromptBuilder
init_parameters:
template: |
Given the following information, answer the question.
Context:
{% for document in documents %}
{{ document.content }}
{% endfor %}
Question: {{ query }}
required_variables:
variables:
VertexAIGeminiGenerator:
type: haystack_integrations.components.generators.google_vertex.gemini.VertexAIGeminiGenerator
init_parameters:
project_id:
model: gemini-2.0-flash
location:
generation_config:
safety_settings:
system_instruction:
streaming_callback:
AnswerBuilder:
type: haystack.components.builders.answer_builder.AnswerBuilder
init_parameters:
pattern:
reference_pattern:
connections:
- sender: bm25_retriever.documents
receiver: PromptBuilder.documents
- sender: PromptBuilder.prompt
receiver: VertexAIGeminiGenerator.parts
- sender: VertexAIGeminiGenerator.replies
receiver: AnswerBuilder.replies
- sender: bm25_retriever.documents
receiver: AnswerBuilder.documents
inputs:
query:
- bm25_retriever.query
- PromptBuilder.query
- AnswerBuilder.query
outputs:
answers: AnswerBuilder.answers
max_runs_per_component: 100
metadata: {}
Parameters
Inputs
| Parameter | Type | Default | Description |
|---|---|---|---|
parts | Variadic[Union[str, ByteStream, Part]] | Prompt for the model. | |
streaming_callback | Optional[Callable[[StreamingChunk], None]] | None | A callback function that is called when a new token is received from the stream. |
Outputs
| Parameter | Type | Description |
|---|---|---|
replies | List[str] | A list of generated content. |
Init Parameters
These are the parameters you can configure in Pipeline Builder:
| Parameter | Type | Default | Description |
|---|---|---|---|
project_id | Optional[str] | None | ID of the GCP project to use. By default, it is set during Google Cloud authentication. |
model | str | gemini-2.0-flash | Name of the model to use. For available models, see Vertex AI models. |
location | Optional[str] | None | The default location to use when making API calls. If not set, uses us-central-1. |
generation_config | Optional[Union[GenerationConfig, Dict[str, Any]]] | None | The generation config to use. Accepted fields: temperature, top_p, top_k, candidate_count, max_output_tokens, stop_sequences. |
safety_settings | Optional[Dict[HarmCategory, HarmBlockThreshold]] | None | The safety settings to use. |
system_instruction | Optional[Union[str, ByteStream, Part]] | None | Default system instruction to use for generating content. |
streaming_callback | Optional[Callable[[StreamingChunk], None]] | None | A callback function that is called when a new token is received from the stream. |
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 |
|---|---|---|---|
parts | Variadic[Union[str, ByteStream, Part]] | Prompt for the model. | |
streaming_callback | Optional[Callable[[StreamingChunk], None]] | None | A callback function that is called when a new token is received from the stream. |
Related Information
Was this page helpful?