GeminiEmbedder class is used to embed text data into vectors using Google’s Gemini API. You can use it through Google AI Studio or Google Cloud Vertex AI.
Usage
For Google AI Studio:from agno.agent import AgentKnowledge
from agno.vectordb.pgvector import PgVector
from agno.embedder.google import GeminiEmbedder
# Embed sentence in database
embeddings = GeminiEmbedder().get_embedding(
"The quick brown fox jumps over the lazy dog."
)
# Print the embeddings and their dimensions
print(f"Embeddings: {embeddings[:5]}")
print(f"Dimensions: {len(embeddings)}")
# Use an embedder in a knowledge base
knowledge_base = AgentKnowledge(
vector_db=PgVector(
db_url="postgresql+psycopg://ai:ai@localhost:5532/ai",
table_name="gemini_embeddings",
embedder=GeminiEmbedder(),
),
num_documents=2,
)
from agno.agent import AgentKnowledge
from agno.vectordb.pgvector import PgVector
from agno.embedder.google import GeminiEmbedder
embedder = GeminiEmbedder(
vertexai=True,
project_id="your-gcloud-project-id", # Optional
location="us-central1", # Optional
)
# Use in a knowledge base
knowledge_base = AgentKnowledge(
vector_db=PgVector(
db_url="postgresql+psycopg://ai:ai@localhost:5532/ai",
table_name="gemini_embeddings_vertex",
embedder=embedder,
),
num_documents=2,
)
Params
| Parameter | Type | Default | Description |
|---|---|---|---|
id | str | gemini-embedding-exp-03-07 | The Gemini embedding model ID to use |
task_type | str | RETRIEVAL_QUERY | The type of task for which embeddings are being generated |
title | Optional[str] | None | Optional title for the embedding task |
dimensions | Optional[int] | 1536 | The dimensionality of the generated embeddings |
api_key | Optional[str] | None | The API key used for authenticating requests |
request_params | Optional[Dict[str, Any]] | None | Optional dictionary of parameters for the embedding request |
client_params | Optional[Dict[str, Any]] | None | Optional dictionary of parameters for the Gemini client |
gemini_client | Optional[GeminiClient] | None | Optional pre-configured Gemini client instance |
vertexai | bool | False | Whether to use Vertex AI instead of Google AI Studio |
project_id | Optional[str] | None | Google Cloud project ID for Vertex AI |
location | Optional[str] | None | Google Cloud region for Vertex AI |
Developer Resources
- View Cookbook