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

Use Google AI Models

Use the multimodal Gemini models in your pipelines through Gemini API.


Prerequisites

You need an active Google AI Studio API key to use Gemini models.

Use Gemini Models

First, connect Haystack Enterprise Platform to GoogleAI through the Integrations page. You can set up the connection for a single workspace or for the whole organization:

Add Workspace-Level Integration

  1. Click your profile icon and choose Settings.
  2. Go to Workspace>Integrations.
  3. Find the provider you want to connect and click Connect next to them.
  4. Enter the API key and any other required details.
  5. Click Connect. You can use this integration in pipelines and indexes in the current workspace.

Add Organization-Level Integration

  1. Click your profile icon and choose Settings.
  2. Go to Organization>Integrations.
  3. Find the provider you want to connect and click Connect next to them.
  4. Enter the API key and any other required details.
  5. Click Connect. You can use this integration in pipelines and indexes in all workspaces in the current organization.

Then, add a component that uses a Gemini LLM to your pipeline:

  • LLMs:

    • LLM: Can generate text using a Gemini model, that's the easiest way to use a Gemini model in your pipeline.
    • GoogleGenAIChatGenerator: Can generate text using a Gemini model.
  • Embedding models:

    • GoogleGenAITextEmbedder: Calculates embeddings for text, like query. Often used in query pipelines to embed a query and pass the embedding to an embedding retriever.
    • GoogleGenAIDocumentEmbedder: Calculates embeddings for documents. Often used in indexes to embed documents and pass them to DocumentWriter.

Usage Examples

This is an example of how to use GoogleGenAIChatGenerator in a query pipeline:

# haystack-pipeline
components:
GoogleGenAIChatGenerator:
type: haystack_integrations.components.generators.google_genai.chat.chat_generator.GoogleGenAIChatGenerator
init_parameters:
api_key:
type: env_var
env_vars:
- GOOGLE_API_KEY
- GEMINI_API_KEY
strict: false
api: gemini
vertex_ai_project:
vertex_ai_location:
model: gemini-2.5-flash
generation_kwargs:
safety_settings:
streaming_callback:
tools:

ChatPromptBuilder:
type: haystack.components.builders.chat_prompt_builder.ChatPromptBuilder
init_parameters:
template: >
- _content:
- text: |-
You are a technical expert.
You answer questions truthfully based on provided documents.
For each document check whether it is related to the question.
Only use documents that are related to the question to answer it.
Ignore documents that are not related to the question.
If the answer exists in several documents, summarize them.
Only answer based on the documents provided. Don't make things up.
If the documents can't answer the question or you are unsure say: 'The answer can't be found in the text'.
These are the documents:
{% for document in documents %}
Document[{{ loop.index }}]:
{{ document.content }}
{% endfor %}
Question: {{ query }}
_role: user
required_variables:
variables:

inputs:
query:
- ChatPromptBuilder.query
filters: []
files: []
messages: []

outputs:
answers:
documents:
messages: GoogleGenAIChatGenerator.replies

connections:
- sender: ChatPromptBuilder.prompt
receiver: GoogleGenAIChatGenerator.messages