Implementation:Explodinggradients Ragas GoogleEmbeddings Class
Appearance
| 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
- Repository: Explodinggradients_Ragas
- File: src/ragas/embeddings/google_provider.py
- Lines: 12-349
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