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

VertexAIGeminiChatGenerator

Complete chats using Google Gemini models through Vertex AI.

Key Features

  • Generates chat responses using Google Gemini models through Vertex AI.
  • Authenticates using Google Cloud Application Default Credentials.
  • Returns responses in the ChatMessage format for chat-based pipelines.
  • Supports tool and function calling with configurable tool behavior.
  • Configurable safety settings and generation parameters.
  • Supports streaming for real-time token delivery.

Configuration

Authentication

This component authenticates using Google Cloud Application Default Credentials (ADCs). You must have a GCP account with a project authorized to use Vertex AI endpoints. For more information, see the Google documentation.

  1. Drag the VertexAIGeminiChatGenerator component onto the canvas from the Component Library.
  2. Click the component to open the configuration panel.
  3. On the General tab:
    1. Enter the model name (for example, gemini-1.5-flash). For available models, see Google documentation.
  4. Go to the Advanced tab to configure the project ID, location, generation config, safety settings, tools, tool config, and streaming callback.

Connections

VertexAIGeminiChatGenerator accepts a list of ChatMessage instances as input (messages). It outputs a list of ChatMessage replies (replies).

Typically, you connect ChatPromptBuilder to the messages input to build the prompt. Connect the replies output to OutputAdapter and then to DeepsetAnswerBuilder to format the final answer.

Usage Example

Using the Component in a Pipeline

This is an example RAG pipeline with VertexAIGeminiChatGenerator and DeepsetAnswerBuilder connected through OutputAdapter:

components:
bm25_retriever: # Selects the most similar documents from the document store
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: 'Standard-Index-English'
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: 20 # The number of results to return
fuzziness: 0

query_embedder:
type: deepset_cloud_custom_nodes.embedders.nvidia.text_embedder.DeepsetNvidiaTextEmbedder
init_parameters:
normalize_embeddings: true
model: intfloat/e5-base-v2

embedding_retriever: # Selects the most similar documents from the document store
type: haystack_integrations.components.retrievers.opensearch.embedding_retriever.OpenSearchEmbeddingRetriever
init_parameters:
document_store:
type: haystack_integrations.document_stores.opensearch.document_store.OpenSearchDocumentStore
init_parameters:
hosts:
index: 'Standard-Index-English'
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: 20 # The number of results to return

document_joiner:
type: haystack.components.joiners.document_joiner.DocumentJoiner
init_parameters:
join_mode: concatenate

ranker:
type: deepset_cloud_custom_nodes.rankers.nvidia.ranker.DeepsetNvidiaRanker
init_parameters:
model: intfloat/simlm-msmarco-reranker
top_k: 8

meta_field_grouping_ranker:
type: haystack.components.rankers.meta_field_grouping_ranker.MetaFieldGroupingRanker
init_parameters:
group_by: file_id
subgroup_by:
sort_docs_by: split_id

answer_builder:
type: deepset_cloud_custom_nodes.augmenters.deepset_answer_builder.DeepsetAnswerBuilder
init_parameters:
reference_pattern: acm

ChatPromptBuilder:
type: haystack.components.builders.chat_prompt_builder.ChatPromptBuilder
init_parameters:
template:
- _content:
- text: "You are a helpful assistant answering the user's questions based on the provided documents.\nIf the answer is not in the documents, rely on the web_search tool to find information.\nDo not use your own knowledge.\n"
_role: system
- _content:
- text: "Provided documents:\n{% for document in documents %}\nDocument [{{ loop.index }}] :\n{{ document.content }}\n{% endfor %}\n\nQuestion: {{ query }}\n"
_role: user
required_variables:
variables:
OutputAdapter:
type: haystack.components.converters.output_adapter.OutputAdapter
init_parameters:
template: '{{ replies[0] }}'
output_type: List[str]
custom_filters:
unsafe: false

VertexAIGeminiChatGenerator:
type: haystack_integrations.components.generators.google_vertex.chat.gemini.VertexAIGeminiChatGenerator
init_parameters:
model: gemini-1.5-flash
project_id:
location:
generation_config:
safety_settings:
tools:
tool_config:
streaming_callback:

connections: # Defines how the components are connected
- sender: bm25_retriever.documents
receiver: document_joiner.documents
- sender: query_embedder.embedding
receiver: embedding_retriever.query_embedding
- sender: embedding_retriever.documents
receiver: document_joiner.documents
- sender: document_joiner.documents
receiver: ranker.documents
- sender: ranker.documents
receiver: meta_field_grouping_ranker.documents
- sender: meta_field_grouping_ranker.documents
receiver: answer_builder.documents
- sender: meta_field_grouping_ranker.documents
receiver: ChatPromptBuilder.documents
- sender: OutputAdapter.output
receiver: answer_builder.replies
- sender: ChatPromptBuilder.prompt
receiver: VertexAIGeminiChatGenerator.messages
- sender: VertexAIGeminiChatGenerator.replies
receiver: OutputAdapter.replies

inputs: # Define the inputs for your pipeline
query: # These components will receive the query as input
- "bm25_retriever.query"
- "query_embedder.text"
- "ranker.query"
- "answer_builder.query"
- "ChatPromptBuilder.query"
filters: # These components will receive a potential query filter as input
- "bm25_retriever.filters"
- "embedding_retriever.filters"

outputs: # Defines the output of your pipeline
documents: "meta_field_grouping_ranker.documents" # The output of the pipeline is the retrieved documents
answers: "answer_builder.answers" # The output of the pipeline is the generated answers

max_runs_per_component: 100

metadata: {}

Parameters

Inputs

ParameterTypeDefaultDescription
messagesList[ChatMessage]A list of ChatMessage instances, representing the input messages.
streaming_callbackOptional[StreamingCallbackT]NoneA callback function that is called when a new token is received from the stream.
toolsOptional[List[Tool]]NoneA list of tools for which the model can prepare calls. If set, it will override the tools parameter set during component initialization.

Outputs

ParameterTypeDefaultDescription
repliesList[ChatMessage]A list containing the generated responses as ChatMessage instances.

Init Parameters

These are the parameters you can configure in Pipeline Builder:

ParameterTypeDefaultDescription
modelstrgemini-1.5-flashName of the model to use. For available models, see https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models.
project_idOptional[str]NoneID of the GCP project to use. By default, it is set during Google Cloud authentication.
locationOptional[str]NoneThe default location to use when making API calls, if not set uses us-central-1. Defaults to None.
generation_configOptional[Union[GenerationConfig, Dict[str, Any]]]NoneConfiguration for the generation process. See the [GenerationConfig documentation](https://cloud.google.com/python/docs/reference/aiplatform/latest/vertexai.generative_models.GenerationConfig for a list of supported arguments.
safety_settingsOptional[Dict[HarmCategory, HarmBlockThreshold]]NoneSafety settings to use when generating content. See the documentation for HarmBlockThreshold and HarmCategory for more details.
toolsOptional[List[Tool]]NoneA list of tools for which the model can prepare calls.
tool_configOptional[ToolConfig]NoneThe tool config to use. See the documentation for [ToolConfig] (https://cloud.google.com/vertex-ai/generative-ai/docs/reference/python/latest/vertexai.generative_models.ToolConfig)
streaming_callbackOptional[StreamingCallbackT]NoneA callback function that is called when a new token is received from the stream. The callback function accepts StreamingChunk as an argument.

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
messagesList[ChatMessage]A list of ChatMessage instances, representing the input messages.
streaming_callbackOptional[StreamingCallbackT]NoneA callback function that is called when a new token is received from the stream.
toolsOptional[List[Tool]]NoneA list of tools for which the model can prepare calls. If set, it will override the tools parameter set during component initialization.