Skip to main content

GoogleGenAITextEmbedder

Embeds strings using Google AI models.

Basic Information

  • Type: haystack_integrations.components.embedders.google_genai.text_embedder.GoogleGenAITextEmbedder

Inputs

ParameterTypeDefaultDescription
textstrText to embed.

Outputs

ParameterTypeDefaultDescription
embeddingList[float]A dictionary with the following keys: - embedding: The embedding of the input text. - meta: Information about the usage of the model.
metaDict[str, Any]A dictionary with the following keys: - embedding: The embedding of the input text. - meta: Information about the usage of the model.

Overview

Work in Progress

Bear with us while we're working on adding pipeline examples and most common components connections.

Embeds strings using Google AI models.

You can use it to embed user query and send it to an embedding Retriever.

Authentication examples

1. Gemini Developer API (API Key Authentication)

from haystack_integrations.components.embedders.google_genai import GoogleGenAITextEmbedder

# export the environment variable (GOOGLE_API_KEY or GEMINI_API_KEY)
text_embedder = GoogleGenAITextEmbedder(model="text-embedding-004")

**2. Vertex AI (Application Default Credentials)**
```python
from haystack_integrations.components.embedders.google_genai import GoogleGenAITextEmbedder

# Using Application Default Credentials (requires gcloud auth setup)
text_embedder = GoogleGenAITextEmbedder(
api="vertex",
vertex_ai_project="my-project",
vertex_ai_location="us-central1",
model="text-embedding-004"
)

3. Vertex AI (API Key Authentication)

from haystack_integrations.components.embedders.google_genai import GoogleGenAITextEmbedder

# export the environment variable (GOOGLE_API_KEY or GEMINI_API_KEY)
text_embedder = GoogleGenAITextEmbedder(
api="vertex",
model="text-embedding-004"
)

Usage Example

components:
GoogleGenAITextEmbedder:
type: integrations.google_genai.src.haystack_integrations.components.embedders.google_genai.text_embedder.GoogleGenAITextEmbedder
init_parameters:

Parameters

Init Parameters

These are the parameters you can configure in Pipeline Builder:

ParameterTypeDefaultDescription
api_keySecretSecret.from_env_var(['GOOGLE_API_KEY', 'GEMINI_API_KEY'], strict=False)Google API key, defaults to the GOOGLE_API_KEY and GEMINI_API_KEY environment variables. Not needed if using Vertex AI with Application Default Credentials. Go to https://aistudio.google.com/app/apikey for a Gemini API key. Go to https://cloud.google.com/vertex-ai/generative-ai/docs/start/api-keys for a Vertex AI API key.
apiLiteral['gemini', 'vertex']geminiWhich API to use. Either "gemini" for the Gemini Developer API or "vertex" for Vertex AI.
vertex_ai_projectOptional[str]NoneGoogle Cloud project ID for Vertex AI. Required when using Vertex AI with Application Default Credentials.
vertex_ai_locationOptional[str]NoneGoogle Cloud location for Vertex AI (e.g., "us-central1", "europe-west1"). Required when using Vertex AI with Application Default Credentials.
modelstrtext-embedding-004The name of the model to use for calculating embeddings. The default model is text-embedding-004.
prefixstrA string to add at the beginning of each text to embed.
suffixstrA string to add at the end of each text to embed.
configOptional[Dict[str, Any]]NoneA dictionary of keyword arguments to configure embedding content configuration types.EmbedContentConfig. If not specified, it defaults to {"task_type": "SEMANTIC_SIMILARITY"}. For more information, see the Google AI Task types.

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
textstrText to embed.