Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Explodinggradients Ragas GoogleEmbeddings Class

From Leeroopedia


Knowledge Sources
Domains Embeddings, Google_Cloud
Last Updated 2026-02-10 00:00 GMT

Overview

Google embeddings provider supporting both Vertex AI and Google AI (Gemini) services with automatic SDK detection.

Description

GoogleEmbeddings extends BaseRagasEmbedding to provide text embeddings via Google's cloud services. It supports both Vertex AI and Google AI (Gemini) backends, automatically detecting the appropriate SDK (new google-genai or legacy google.generativeai). The default model is gemini-embedding-001.

Usage

Use this provider when generating embeddings with Google Cloud's Vertex AI or Google AI (Gemini) embedding models.

Code Reference

Source Location

Signature

class GoogleEmbeddings(BaseRagasEmbedding):
    PROVIDER_NAME = "google"
    DEFAULT_MODEL = "gemini-embedding-001"

    def __init__(
        self,
        client=None,
        model: str = "gemini-embedding-001",
        use_vertex: bool = False,
        project_id: Optional[str] = None,
        location: str = "us-central1",
        cache: Optional[CacheInterface] = None,
        **kwargs,
    ):
        ...
    def embed_text(self, text: str, **kwargs) -> List[float]:
        ...
    async def aembed_text(self, text: str, **kwargs) -> List[float]:
        ...
    def embed_texts(self, texts: List[str], **kwargs) -> List[List[float]]:
        ...
    async def aembed_texts(self, texts: List[str], **kwargs) -> List[List[float]]:
        ...

Import

from ragas.embeddings.google_provider import GoogleEmbeddings

I/O Contract

Inputs

Name Type Required Description
model str No Google embedding model (default "gemini-embedding-001")
use_vertex bool No Use Vertex AI instead of Google AI (default False)
project_id Optional[str] No GCP project ID (required for Vertex AI)
location str No GCP region (default "us-central1")

Outputs

Name Type Description
embed_text returns List[float] Embedding vector
embed_texts returns List[List[float]] Batch embedding vectors

Usage Examples

from ragas.embeddings.google_provider import GoogleEmbeddings

# Google AI (Gemini)
embeddings = GoogleEmbeddings(model="gemini-embedding-001")
vector = embeddings.embed_text("What is machine learning?")

# Vertex AI
embeddings_vertex = GoogleEmbeddings(
    use_vertex=True,
    project_id="my-gcp-project",
    location="us-central1",
)
vector = embeddings_vertex.embed_text("What is ML?")

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment