• __all__ = ['GoogleEmbeddingDriver'] module-attribute

Bases: BaseEmbeddingDriver

Attributes

NameTypeDescription
api_keyOptional[str]Google API key.
modelstrGoogle model name.
task_typestrEmbedding model task type (https://ai.google.dev/tutorials/python\_quickstart#use\_embeddings). Defaults to retrieval_document.
titleOptional[str]Optional title for the content. Only works with retrieval_document task type.
Source Code in griptape/drivers/embedding/google_embedding_driver.py
@define
class GoogleEmbeddingDriver(BaseEmbeddingDriver):
    """Google Embedding Driver.

    Attributes:
        api_key: Google API key.
        model: Google model name.
        task_type: Embedding model task type (https://ai.google.dev/tutorials/python_quickstart#use_embeddings). Defaults to `retrieval_document`.
        title: Optional title for the content. Only works with `retrieval_document` task type.
    """

    DEFAULT_MODEL = "models/embedding-001"

    model: str = field(default=DEFAULT_MODEL, kw_only=True, metadata={"serializable": True})
    api_key: Optional[str] = field(default=None, kw_only=True, metadata={"serializable": False})
    task_type: str = field(default="retrieval_document", kw_only=True, metadata={"serializable": True})
    title: Optional[str] = field(default=None, kw_only=True, metadata={"serializable": True})

    def try_embed_chunk(self, chunk: str, **kwargs) -> list[float]:
        genai = import_optional_dependency("google.generativeai")
        genai.configure(api_key=self.api_key)

        result = genai.embed_content(model=self.model, content=chunk, task_type=self.task_type, title=self.title)

        return result["embedding"]

    def _params(self, chunk: str) -> dict:
        return {"input": chunk, "model": self.model}
  • DEFAULT_MODEL = 'models/embedding-001' class-attribute instance-attribute

  • api_key = field(default=None, kw_only=True, metadata={'serializable': False}) class-attribute instance-attribute

  • model = field(default=DEFAULT_MODEL, kw_only=True, metadata={'serializable': True}) class-attribute instance-attribute

  • task_type = field(default='retrieval_document', kw_only=True, metadata={'serializable': True}) class-attribute instance-attribute

  • title = field(default=None, kw_only=True, metadata={'serializable': True}) class-attribute instance-attribute

_params(chunk)

Source Code in griptape/drivers/embedding/google_embedding_driver.py
def _params(self, chunk: str) -> dict:
    return {"input": chunk, "model": self.model}

try_embed_chunk(chunk, **kwargs)

Source Code in griptape/drivers/embedding/google_embedding_driver.py
def try_embed_chunk(self, chunk: str, **kwargs) -> list[float]:
    genai = import_optional_dependency("google.generativeai")
    genai.configure(api_key=self.api_key)

    result = genai.embed_content(model=self.model, content=chunk, task_type=self.task_type, title=self.title)

    return result["embedding"]

Could this page be better? Report a problem or suggest an addition!