nemoguardrails.embeddings.providers.google

View as Markdown

Module Contents

Classes

NameDescription
GoogleEmbeddingModelEmbedding model using Gemini API.

API

class nemoguardrails.embeddings.providers.google.GoogleEmbeddingModel(
embedding_model: str,
kwargs = {}
)

Bases: EmbeddingModel

Embedding model using Gemini API.

This class is a wrapper for using embedding models powered by Gemini API.

To use, you must have either:

  1. The GOOGLE_API_KEY environment variable set with your API key, or
  2. Pass your API key using the api_key kwarg to the genai.Client().

Parameters:

embedding_model
str

The name of the embedding model to be used.

**kwargs
Defaults to {}

Additional keyword arguments. Supports:

  • output_dimensionality (int, optional): Desired output dimensions (128-3072 for gemini-embedding-001). Recommended values: 768, 1536, or 3072. If not specified, API defaults to 3072.
  • api_key (str, optional): API key for authentication (or use GOOGLE_API_KEY env var).
  • Other arguments passed to genai.Client() constructor.
_embedding_size
client
= genai.Client(**kwargs)
embedding_size
int
engine_name
= 'google'
output_dimensionality
= kwargs.pop('output_dimensionality', None)
nemoguardrails.embeddings.providers.google.GoogleEmbeddingModel.encode(
documents: typing.List[str]
) -> typing.List[typing.List[float]]

Encode a list of documents into their corresponding sentence embeddings.

Parameters:

documents
List[str]

The list of documents to be encoded.

Returns: List[List[float]]

List[List[float]]: The list of sentence embeddings, where each embedding is a list of floats.

Raises:

  • RuntimeError: If the embedding request fails.
nemoguardrails.embeddings.providers.google.GoogleEmbeddingModel.encode_async(
documents: typing.List[str]
) -> typing.List[typing.List[float]]
async

Encode a list of documents into their corresponding sentence embeddings.

Parameters:

documents
List[str]

The list of documents to be encoded.

Returns: List[List[float]]

List[List[float]]: The list of sentence embeddings, where each embedding is a list of floats.