Skip to content

Commit 78335ce

Browse files
authored
Update the model information (#416)
1 parent 370d469 commit 78335ce

1 file changed

Lines changed: 81 additions & 20 deletions

File tree

integrations/google-genai.md

Lines changed: 81 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,25 @@ toc: true
2828
- [Overview](#overview)
2929
- [Installation](#installation)
3030
- [Usage](#usage)
31-
- [Chat Generation with `gemini-2.0-flash`](#chat-generation-with-gemini-20-flash)
31+
- [Chat Generation with `gemini-3.1-flash-lite-preview`](#chat-generation-with-gemini-31-flash-lite-preview)
3232
- [Streaming Chat Generation](#streaming-chat-generation)
3333
- [Function calling](#function-calling)
34-
- [Document Embedding](#document-embedding)
35-
- [Text Embedding](#text-embedding)
34+
- [Embeddings](#embeddings)
35+
- [Multimodal Embeddings with `gemini-embedding-2-preview`](#multimodal-embeddings-with-gemini-embedding-2-preview)
36+
- [License](#license)
3637

3738
## Overview
3839

3940
[Google Gen AI](https://ai.google.dev/) provides access to Google's Gemini models through the new Google Gen AI SDK. This integration enables the usage of Google's latest generative models via the updated API interface.
4041
Google Gen AI is compatible with both the Gemini Developer API and the Vertex AI API.
4142

42-
Haystack supports the latest [Gemini models](https://ai.google.dev/models/gemini) like `gemini-2.0-flash` and `text-embedding-004` for tasks such as **chat completion**, **function calling**, **streaming responses** and **embedding generation**.
43+
Haystack supports the latest [Gemini models](https://ai.google.dev/models/gemini) for tasks such as **chat completion**, **function calling**, **streaming responses** and **embedding generation**.
44+
45+
**Generative models:** `gemini-3.1-flash-lite-preview`, `gemini-3.1-pro-preview`, `gemini-3-flash-preview`, `gemini-2.5-flash`, `gemini-2.5-pro`, `gemini-2.5-flash-lite`, and the Gemini 2.0 series (e.g. `gemini-2.0-flash`).
46+
47+
**Embedding models:** `gemini-embedding-2-preview` (multimodal, multilingual) and `gemini-embedding-001` (multilingual).
48+
49+
> 🖼️ Learn how to build multimodal search systems using Gemini Embedding 2 to embed text, images, video, audio, and PDFs in [Multimodal Search with Gemini Embedding 2 in Haystack](https://haystack.deepset.ai/blog/multimodal-embeddings-gemini-haystack).
4350
4451
## Installation
4552

@@ -53,9 +60,10 @@ pip install google-genai-haystack
5360

5461
Once installed, you will have access to the Haystack Chat components:
5562

56-
- [`GoogleGenAIChatGenerator`](https://docs.haystack.deepset.ai/docs/googlegenaichatgenerator): Use this component with [Gemini models](https://ai.google.dev/gemini-api/docs/models/gemini#model-variations), such as '**gemini-2.0-flash**' for chat completion and function calling.
57-
- `GoogleGenAIDocumentEmbedder`: Use this component with [Google GenAI models](https://ai.google.dev/gemini-api/docs/embeddings#embeddings-models), such as '**text-embedding-004**' for generating embeddings for documents.
58-
- `GoogleGenAITextEmbedder`: Use this component with [Google GenAI models](https://ai.google.dev/gemini-api/docs/embeddings#embeddings-models), such as '**text-embedding-004**' for generating embeddings for text.
63+
- [`GoogleGenAIChatGenerator`](https://docs.haystack.deepset.ai/docs/googlegenaichatgenerator): Use this component with [Gemini models](https://ai.google.dev/gemini-api/docs/models/gemini#model-variations), such as **gemini-3.1-flash-lite-preview** or **gemini-2.5-pro** for chat completion and function calling.
64+
- [`GoogleGenAIDocumentEmbedder`](https://docs.haystack.deepset.ai/docs/googlegenaidocumentembedder): Use this component with [Google GenAI embedding models](https://ai.google.dev/gemini-api/docs/embeddings#embeddings-models), such as **gemini-embedding-001** for generating embeddings for documents.
65+
- [`GoogleGenAITextEmbedder`](https://docs.haystack.deepset.ai/docs/googlegenaitextembedder): Use this component with [Google GenAI embedding models](https://ai.google.dev/gemini-api/docs/embeddings#embeddings-models), such as **gemini-embedding-001** for generating embeddings for text.
66+
- [`GoogleGenAIMultimodalDocumentEmbedder`](https://docs.haystack.deepset.ai/docs/googlegenaimultimodaldocumentembedder): Use this component with [Google GenAI multimodal embedding models](https://ai.google.dev/gemini-api/docs/embeddings#embeddings-models), such as **gemini-embedding-2-preview** for generating embeddings for text, image, PDF, video and audio.
5967

6068
To use this component with the Gemini Developer API and get an API key, visit [Google AI Studio](https://aistudio.google.com/).
6169
To use this component with the Vertex AI API, visit [Google Cloud > Vertex AI](https://cloud.google.com/vertex-ai).
@@ -93,9 +101,9 @@ from haystack_integrations.components.generators.google_genai import GoogleGenAI
93101
chat_generator = GoogleGenAIChatGenerator(api="vertex")
94102
```
95103

96-
### Chat Generation with `gemini-2.0-flash`
104+
### Chat Generation with `gemini-3.1-flash-lite-preview`
97105

98-
To use Gemini model for chat generation, set the `GOOGLE_API_KEY` or `GEMINI_API_KEY` environment variable and then initialize a `GoogleGenAIChatGenerator` with `"gemini-2.0-flash"`:
106+
To use Gemini model for chat generation, set the `GOOGLE_API_KEY` or `GEMINI_API_KEY` environment variable and then initialize a `GoogleGenAIChatGenerator` with `"gemini-3.1-flash-lite-preview"`:
99107

100108
```python
101109
import os
@@ -105,7 +113,7 @@ from haystack_integrations.components.generators.google_genai import GoogleGenAI
105113
os.environ["GOOGLE_API_KEY"] = "YOUR-GOOGLE-API-KEY"
106114

107115
# Initialize the chat generator
108-
chat_generator = GoogleGenAIChatGenerator(model="gemini-2.0-flash")
116+
chat_generator = GoogleGenAIChatGenerator(model="gemini-3.1-flash-lite-preview")
109117

110118
# Generate a response
111119
messages = [ChatMessage.from_user("Tell me about the future of AI")]
@@ -136,7 +144,7 @@ def streaming_callback(chunk: StreamingChunk):
136144

137145
# Initialize with streaming callback
138146
chat_generator = GoogleGenAIChatGenerator(
139-
model="gemini-2.0-flash",
147+
model="gemini-3.1-flash-lite-preview",
140148
streaming_callback=streaming_callback
141149
)
142150

@@ -177,7 +185,7 @@ weather_tool = Tool(
177185

178186
# Initialize chat generator with tools
179187
chat_generator = GoogleGenAIChatGenerator(
180-
model="gemini-2.0-flash",
188+
model="gemini-3.1-flash-lite-preview",
181189
tools=[weather_tool]
182190
)
183191

@@ -195,7 +203,21 @@ Output:
195203
The weather in Paris is sunny and 25°C.
196204
```
197205

198-
### Document Embedding
206+
### Embeddings
207+
208+
Embeddings are vector representations of text that capture semantic meaning. They power use cases like **semantic search**, **retrieval-augmented generation (RAG)**, and **similarity comparison** e.g. finding documents or passages that are closest in meaning to a query.
209+
210+
This integration provides three embedder components:
211+
212+
- **`GoogleGenAIDocumentEmbedder`** — Embeds Haystack `Document` objects (text content). Use it when indexing documents into a vector store or when you need to embed multiple documents in one call. The resulting embeddings are stored on the documents and can be used for document retrieval.
213+
- **`GoogleGenAITextEmbedder`** — Embeds a single string. Use it when you need to embed a search query or any standalone text to compare against document embeddings (e.g. in a RAG pipeline for the query side).
214+
- **`GoogleGenAIMultimodalDocumentEmbedder`** — Embeds documents that can contain **images**, **videos**, or **PDFs** (via `meta["file_path"]`). Use the `gemini-embedding-2-preview` model for multimodal retrieval, e.g. searching over mixed media with text or image queries.
215+
216+
For text-only pipelines, use the same model (e.g. `gemini-embedding-001`) for documents and queries so that their embeddings live in the same vector space. For multimodal content, use `gemini-embedding-2-preview` with the appropriate `task_type` in the config.
217+
218+
#### Document Embedding
219+
220+
Use `GoogleGenAIDocumentEmbedder` to create embeddings for documents before storing them in a document store or using them in retrieval:
199221

200222
```python
201223
import os
@@ -204,15 +226,17 @@ from haystack_integrations.components.embedders.google_genai import GoogleGenAID
204226

205227
os.environ["GOOGLE_API_KEY"] = "YOUR-GOOGLE-API-KEY"
206228

207-
# Initialize the embedder
208-
embedder = GoogleGenAIDocumentEmbedder()
229+
# Initialize the embedder (uses gemini-embedding-001 by default)
230+
embedder = GoogleGenAIDocumentEmbedder(model="gemini-embedding-001")
209231

210232
# Generate a response
211233
doc = Document(content="some text")
212234
docs_w_embeddings = embedder.run(documents=[doc])["documents"]
213235
```
214236

215-
### Text Embedding
237+
#### Text Embedding
238+
239+
Use `GoogleGenAITextEmbedder` to embed a single string (e.g. a user query) so you can compare it to document embeddings:
216240

217241
```python
218242
import os
@@ -221,9 +245,8 @@ from haystack_integrations.components.embedders.google_genai import GoogleGenAIT
221245
os.environ["GOOGLE_API_KEY"] = "YOUR-GOOGLE-API-KEY"
222246

223247
text_to_embed = "I love pizza!"
224-
225-
# Initialize the text embedder
226-
text_embedder = GoogleGenAITextEmbedder()
248+
# Initialize the text embedder (uses gemini-embedding-001 by default)
249+
text_embedder = GoogleGenAITextEmbedder(model="gemini-embedding-001")
227250

228251
# Generate a response
229252
print(text_embedder.run(text_to_embed))
@@ -233,5 +256,43 @@ Output:
233256

234257
```shell
235258
{'embedding': [-0.052871075, -0.035282962, ...., -0.04802792],
236-
'meta': {'model': 'text-embedding-004'}}
259+
'meta': {'model': 'gemini-embedding-001'}}
260+
```
261+
262+
The returned embedding is a list of floats (e.g. 3072 dimensions for `gemini-embedding-001`). In a typical RAG pipeline you would pass this query embedding to a retriever to find the most similar document embeddings from your index.
263+
264+
#### Multimodal Embeddings with `gemini-embedding-2-preview`
265+
266+
`GoogleGenAIMultimodalDocumentEmbedder` embeds documents that reference **text**, **images**, **audios**, **videos**, or **PDFs** via `meta["file_path"]`. It uses the `gemini-embedding-2-preview` model, which produces a unified embedding space for text, images, and other modalities—so you can index mixed media and retrieve with text or image queries.
267+
268+
Set `config={"task_type": "RETRIEVAL_DOCUMENT"}` when embedding documents for indexing, and use `RETRIEVAL_QUERY` when embedding queries. Use the same model and task type pairing so document and query embeddings are comparable.
269+
270+
Example: embedding multiple files (text, audio, video, images, PDF) and writing them to a document store:
271+
272+
```python
273+
import os
274+
from haystack.document_stores.in_memory import InMemoryDocumentStore
275+
from haystack import Document
276+
from haystack_integrations.components.embedders.google_genai import GoogleGenAIMultimodalDocumentEmbedder
277+
278+
os.environ["GOOGLE_API_KEY"] = "YOUR-GOOGLE-API-KEY"
279+
280+
document_store = InMemoryDocumentStore()
281+
docs = [
282+
Document(meta={"file_path": "kangaroo.mp4"}),
283+
Document(meta={"file_path": "tiger.jpg"}),
284+
Document(meta={"file_path": "sample.pdf"}),
285+
Document(meta={"file_path": "dog.jpg"}),
286+
Document(meta={"file_path": "cat.jpg"}),
287+
]
288+
289+
doc_multimodal_embedder = GoogleGenAIMultimodalDocumentEmbedder(
290+
model="gemini-embedding-2-preview",
291+
config={"task_type": "RETRIEVAL_DOCUMENT"},
292+
)
293+
docs_with_embeddings = doc_multimodal_embedder.run(documents=docs)
294+
document_store.write_documents(docs_with_embeddings["documents"])
237295
```
296+
297+
## License
298+
`google-genai-haystack` is distributed under the terms of the [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html) license.

0 commit comments

Comments
 (0)