Method Signature
Description
Calculates embeddings (vector representations) for the given contents. Supports both text-only and multimodal embeddings depending on the model. Embeddings are useful for:- Semantic search and similarity matching
- Content classification and clustering
- Recommendation systems
- Anomaly detection
Parameters
str
required
The embedding model to use.Text embedding models:
'text-embedding-004'- Latest text embedding model'text-embedding-005'- Newer text embedding model'text-multilingual-embedding-002'- Multilingual support
'multimodalembedding@001''gemini-embedding-2-exp-11-2025'
ContentListUnion
required
The contents to embed.Can be:
- A string:
'What is your name?' - A list of strings:
['text1', 'text2'] - A list of Content objects for multimodal input
- A list of Part objects
EmbedContentConfig
Configuration for embedding generation.
Response
list[ContentEmbedding]
List of embeddings for each input content.
dict
Additional metadata about the embedding response
Code Examples
Basic Text Embedding
Multiple Text Embeddings
With Task Type and Reduced Dimensions
Semantic Similarity Search
Multimodal Embeddings (Vertex AI)
With Document Title
Batch Processing for Large Datasets
Async Usage
Notes
- Text embedding models support batch embedding of multiple texts
- Some Vertex AI multimodal models only support one content at a time
- Use
output_dimensionalityto reduce vector size for faster similarity search - Different
task_typevalues optimize embeddings for specific use cases - Embeddings are normalized vectors suitable for cosine similarity
- The
auto_truncateoption (Vertex AI) handles inputs exceeding token limits - For production RAG systems, consider using vector databases like Pinecone or Weaviate
Related Methods
- generate_content - Generate text responses
- count_tokens - Count tokens before embedding