Use Google Gemini Models

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

You can use the gemini-pro models in your pipelines.

Prerequisites

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

Use Gemini Models

First, connect deepset AI Platform to GoogleAI through the Integrations page. You can do so 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.

For details, see Add Integrations.

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

Usage Examples

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

components:
...
  prompt_builder:
      type: haystack.components.builders.prompt_builder.PromptBuilder
      init_parameters:
        template: |-
          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: {{question}}
          Answer:

    generator:
      type: haystack_integrations.components.generators.google_ai.gemini.GoogleAIGeminiGenerator
      init_parameters:
          model: gemini-ultra
                 
    answer_builder:
      init_parameters: {}
      type: haystack.components.builders.answer_builder.AnswerBuilder
      ...

connections:
...
 - sender: prompt_builder.prompt
   receiver: generator.prompt
 - sender: generator.replies
   receiver: answer_builder.replies
   ...