LlamaIndex Vertex AI Embeddings

raw JSON →
0.5.0 verified Fri May 01 auth: no python

LlamaIndex integration for Google Vertex AI embeddings. Version 0.5.0 supports Gemini models (text-embedding-004, text-embedding-005) and legacy Gecko models. Requires Python >=3.10 and a Google Cloud project with Vertex AI enabled. Release cadence: irregular, tied to llama-index core updates.

pip install llama-index-embeddings-vertex
error google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials.
cause No valid Google Cloud credentials found in environment (missing GOOGLE_APPLICATION_CREDENTIALS or gcloud auth).
fix
Set GOOGLE_APPLICATION_CREDENTIALS to path to service account JSON, or run 'gcloud auth application-default login'.
error ImportError: cannot import name 'VertexEmbedding' from 'llama_index.embeddings.vertex'
cause Outdated library version; import path changed in v0.2.0.
fix
Upgrade: pip install --upgrade llama-index-embeddings-vertex. If version <0.2.0, use old import: from llama_index.embeddings.vertex_ai import VertexEmbedding.
error ValueError: Model 'text-embedding-004' not found or not supported in location 'us-central1'.
cause Specified model is not deployed or not available in the chosen GCP region.
fix
Verify model availability in your region: https://cloud.google.com/vertex-ai/generative-ai/docs/embeddings/get-text-embeddings#supported_models. Use location 'us-central1' for most models.
breaking Version 0.2.0 moved VertexEmbedding from llama_index.embeddings.vertex_ai to llama_index.embeddings.vertex. Old import will break.
fix Change 'from llama_index.embeddings.vertex_ai import VertexEmbedding' to 'from llama_index.embeddings.vertex import VertexEmbedding'.
deprecated Legacy Gecko models (textembedding-gecko@001, @002, @003) are deprecated and may be removed in future versions. Use text-embedding-004 or later.
fix Set model_name='text-embedding-004' or 'text-embedding-005' (if available).
gotcha The 'project' parameter is required; omitting it defaults to the project set in gcloud config, which may be unexpected.
fix Always pass 'project' explicitly to VertexEmbedding().

Initialize VertexEmbedding with model name and project. Authentication via GOOGLE_APPLICATION_CREDENTIALS env var (service account) or default credentials.

import os
from llama_index.embeddings.vertex import VertexEmbedding

# Set credentials (recommended: service account JSON path)
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "path/to/service-account.json"

embed_model = VertexEmbedding(
    model_name="text-embedding-004",  # or "textembedding-gecko@003"
    project="your-gcp-project-id",
    location="us-central1",
)

embeddings = embed_model.get_text_embedding("Hello, world!")
print(len(embeddings))  # 768 for text-embedding-004