google#

  • __all__ = ['GoogleEmbeddingDriver'] module-attribute

Bases: BaseEmbeddingDriver “)

Attributes#

Name

Type

Description

<a href="google.mdx#griptape.drivers.embedding.google.GoogleEmbeddingDriver.api_key" title="api_key = field(default=None, kw_only=True, metadata={'serializable': False}) class-attribute instance-attribute (griptape.drivers.embedding.google.GoogleEmbeddingDriver.api_key)"><code class="language-python">api_key</code></a>

Optional[str]

Google API key.<br/>

<a href="google.mdx#griptape.drivers.embedding.google.GoogleEmbeddingDriver.model" title="model = field(default=DEFAULT_MODEL, kw_only=True, metadata={'serializable': True}) class-attribute instance-attribute (griptape.drivers.embedding.google.GoogleEmbeddingDriver.model)"><code class="language-python">model</code></a>

str

Google model name.<br/>

<a href="google.mdx#griptape.drivers.embedding.google.GoogleEmbeddingDriver.task_type" title="task_type = field(default='retrieval_document', kw_only=True, metadata={'serializable': True}) class-attribute instance-attribute (griptape.drivers.embedding.google.GoogleEmbeddingDriver.task_type)"><code class="language-python">task_type</code></a>

str

Embedding model task type (<https://ai.google.dev/tutorials/python_quickstart#use_embeddings>). Defaults to retrieval_document.<br/>

<a href="google.mdx#griptape.drivers.embedding.google.GoogleEmbeddingDriver.title" title="title = field(default=None, kw_only=True, metadata={'serializable': True}) class-attribute instance-attribute (griptape.drivers.embedding.google.GoogleEmbeddingDriver.title)"><code class="language-python">title</code></a>

Optional[str]

Optional title for the content. Only works with retrieval_document task type.<br/>

Source Code in griptape/drivers/embedding/google_embedding_driver.py

Optional title for the content. Only works with retrieval_document task type.#

  • 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"]