Starting April 29, 2025, Gemini 1.5 Pro and Gemini 1.5 Flash models are not available in projects that have no prior usage of these models, including new projects. For details, see Model versions and lifecycle.
Stay organized with collections
Save and categorize content based on your preferences.
This document describes how to create a text embedding using the
Vertex AI
Text embeddings API.
Vertex AI text embeddings API uses dense vector representations: gemini-embedding-001,
for example, uses 3072-dimensional vectors. Dense vector embedding models use deep-learning methods similar to the ones used by large language models. Unlike sparse vectors, which tend to directly map words to numbers, dense vectors are designed to better represent the meaning of a piece of text. The benefit of using dense vector
embeddings in generative AI is that instead of searching for direct word or
syntax matches, you can better search for passages that align to the meaning of
the query, even if the passages don't use the same language.
The vectors are normalized, so you can use cosine similarity, dot product, or
Euclidean distance to provide the same similarity rankings.
For information about which languages each embeddings model supports, see
Supported text languages.
Before you begin
Sign in to your Google Cloud account. If you're new to
Google Cloud,
create an account to evaluate how our products perform in
real-world scenarios. New customers also get $300 in free credits to
run, test, and deploy workloads.
In the Google Cloud console, on the project selector page,
select or create a Google Cloud project.
You can get text embeddings by using the following models:
Model name
Description
Output Dimensions
Max sequence length
Supported text languages
gemini-embedding-001
State-of-the-art performance across English, multilingual and code tasks. It unifies the previously specialized models like text-embedding-005 and text-multilingual-embedding-002 and achieves better performance in their respective domains. Read our Tech Report for more detail.
For superior embedding quality, gemini-embedding-001 is our large
model designed to provide the highest performance. Note that
gemini-embedding-001 supports one instance per request.
Get text embeddings for a snippet of text
You can get text embeddings for a snippet of text by using the Vertex AI API or
the Vertex AI SDK for Python.
API limits
For each request, you're limited to 250 input texts.
The API has a maximum input token limit of 20,000.
Inputs exceeding this limit result in a 400 error. Each individual input text
is further limited to 2048 tokens; any excess is silently truncated. You can
also disable silent truncation by setting autoTruncate to false.
All models produce a full-length embedding vector by default. For gemini-embedding-001,
this vector has 3072 dimensions, and other models produce 768-dimensional vectors. However, by
using the output_dimensionality parameter, users can control the size of the output embedding vector.
Selecting a smaller output dimensionality can save storage space and
increase computational efficiency for downstream applications, while sacrificing
little in terms of quality.
The following examples use the gemini-embedding-001 model.
Set environment variables to use the Gen AI SDK with Vertex AI:
# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values# with appropriate values for your project.exportGOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECTexportGOOGLE_CLOUD_LOCATION=globalexportGOOGLE_GENAI_USE_VERTEXAI=True
fromgoogleimportgenaifromgoogle.genai.typesimportEmbedContentConfigclient=genai.Client()response=client.models.embed_content(model="gemini-embedding-001",contents=["How do I get a driver's license/learner's permit?","How long is my driver's license valid for?","Driver's knowledge test study guide",],config=EmbedContentConfig(task_type="RETRIEVAL_DOCUMENT",# Optionaloutput_dimensionality=3072,# Optionaltitle="Driver's License",# Optional),)print(response)# Example response:# embeddings=[ContentEmbedding(values=[-0.06302902102470398, 0.00928034819662571, 0.014716853387653828, -0.028747491538524628, ... ],# statistics=ContentEmbeddingStatistics(truncated=False, token_count=13.0))]# metadata=EmbedContentMetadata(billable_character_count=112)
Add an embedding to a vector database
After you've generated your embedding you can add embeddings to a vector
database, like Vector Search. This enables low-latency retrieval,
and is critical as the size of your data increases.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-03 UTC."],[],[],null,["# Get text embeddings\n\nThis document describes how to create a text embedding using the\nVertex AI\n[Text embeddings API](/vertex-ai/generative-ai/docs/model-reference/text-embeddings-api).\n\nVertex AI text embeddings API uses dense vector representations: [gemini-embedding-001](#supported-models),\nfor example, uses 3072-dimensional vectors. Dense vector embedding models use deep-learning methods similar to the ones used by large language models. Unlike sparse vectors, which tend to directly map words to numbers, dense vectors are designed to better represent the meaning of a piece of text. The benefit of using dense vector\nembeddings in generative AI is that instead of searching for direct word or\nsyntax matches, you can better search for passages that align to the meaning of\nthe query, even if the passages don't use the same language.\n\nThe vectors are normalized, so you can use cosine similarity, dot product, or\nEuclidean distance to provide the same similarity rankings.\n\n- To learn more about embeddings, see the [embeddings APIs overview](/vertex-ai/generative-ai/docs/embeddings).\n- To learn about text embedding models, see [Text embeddings](/vertex-ai/generative-ai/docs/model-reference/text-embeddings).\n- For information about which languages each embeddings model supports, see [Supported text languages](/vertex-ai/generative-ai/docs/model-reference/text-embeddings-api#supported_text_languages).\n\n| To see an example of getting text embeddings,\n| run the \"Getting Started with Text Embeddings + Vertex AI Vector Search\" notebook in one of the following\n| environments:\n|\n| [Open in Colab](https://colab.research.google.com/github/GoogleCloudPlatform/generative-ai/blob/main/embeddings/intro-textemb-vectorsearch.ipynb)\n|\n|\n| \\|\n|\n| [Open in Colab Enterprise](https://console.cloud.google.com/vertex-ai/colab/import/https%3A%2F%2Fraw.githubusercontent.com%2FGoogleCloudPlatform%2Fgenerative-ai%2Fmain%2Fembeddings%2Fintro-textemb-vectorsearch.ipynb)\n|\n|\n| \\|\n|\n| [Open\n| in Vertex AI Workbench](https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https%3A%2F%2Fraw.githubusercontent.com%2FGoogleCloudPlatform%2Fgenerative-ai%2Fmain%2Fembeddings%2Fintro-textemb-vectorsearch.ipynb)\n|\n|\n| \\|\n|\n| [View on GitHub](https://github.com/GoogleCloudPlatform/generative-ai/blob/main/embeddings/intro-textemb-vectorsearch.ipynb)\n\nBefore you begin\n----------------\n\n- Sign in to your Google Cloud account. If you're new to Google Cloud, [create an account](https://console.cloud.google.com/freetrial) to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n\n\n Enable the Vertex AI API.\n\n\n [Enable the API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com)\n\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n\n\n Enable the Vertex AI API.\n\n\n [Enable the API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com)\n\n1. [Choose a task type](/vertex-ai/generative-ai/docs/embeddings/task-types) for your embeddings job.\n\n\u003cbr /\u003e\n\nSupported models\n----------------\n\nYou can get text embeddings by using the following models:\n\nFor superior embedding quality, `gemini-embedding-001` is our large\nmodel designed to provide the highest performance. Note that\n`gemini-embedding-001` supports one instance per request.\n| **Note:** Only use the models as listed in the supported models table. Don't specify a model without the `@version` suffix or `@latest`. These model names are not considered valid.\n\nGet text embeddings for a snippet of text\n-----------------------------------------\n\nYou can get text embeddings for a snippet of text by using the Vertex AI API or\nthe Vertex AI SDK for Python.\n\n### API limits\n\nFor each request, you're limited to 250 input texts.\nThe API has a maximum input token limit of 20,000.\nInputs exceeding this limit result in a 400 error. Each individual input text\nis further limited to 2048 tokens; any excess is silently truncated. You can\nalso disable silent truncation by setting `autoTruncate` to `false`.\n\nFor more information, see [Text embedding limits](/vertex-ai/docs/quotas#text-embedding-limits).\n\n### Choose an embedding dimension\n\nAll models produce a full-length embedding vector by default. For `gemini-embedding-001`,\nthis vector has 3072 dimensions, and other models produce 768-dimensional vectors. However, by\nusing the `output_dimensionality` parameter, users can control the size of the output embedding vector.\nSelecting a smaller output dimensionality can save storage space and\nincrease computational efficiency for downstream applications, while sacrificing\nlittle in terms of quality.\n\nThe following examples use the `gemini-embedding-001` model. \n\n### Python\n\n#### Install\n\n```\npip install --upgrade google-genai\n```\n\n\nTo learn more, see the\n[SDK reference documentation](https://googleapis.github.io/python-genai/).\n\n\nSet environment variables to use the Gen AI SDK with Vertex AI:\n\n```bash\n# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values\n# with appropriate values for your project.\nexport GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT\nexport GOOGLE_CLOUD_LOCATION=global\nexport GOOGLE_GENAI_USE_VERTEXAI=True\n```\n\n\u003cbr /\u003e\n\n from google import genai\n from google.genai.types import EmbedContentConfig\n\n client = genai.Client()\n response = client.models.embed_content(\n model=\"gemini-embedding-001\",\n contents=[\n \"How do I get a driver's license/learner's permit?\",\n \"How long is my driver's license valid for?\",\n \"Driver's knowledge test study guide\",\n ],\n config=EmbedContentConfig(\n task_type=\"RETRIEVAL_DOCUMENT\", # Optional\n output_dimensionality=3072, # Optional\n title=\"Driver's License\", # Optional\n ),\n )\n print(response)\n # Example response:\n # embeddings=[ContentEmbedding(values=[-0.06302902102470398, 0.00928034819662571, 0.014716853387653828, -0.028747491538524628, ... ],\n # statistics=ContentEmbeddingStatistics(truncated=False, token_count=13.0))]\n # metadata=EmbedContentMetadata(billable_character_count=112)\n\n\u003cbr /\u003e\n\nAdd an embedding to a vector database\n-------------------------------------\n\nAfter you've generated your embedding you can add embeddings to a vector\ndatabase, like Vector Search. This enables low-latency retrieval,\nand is critical as the size of your data increases.\n\nTo learn more about Vector Search,\nsee [Overview of Vector Search](/vertex-ai/docs/vector-search/overview).\n\nWhat's next\n-----------\n\n- To learn more about rate limits, see [Generative AI on Vertex AI rate limits](/vertex-ai/generative-ai/docs/quotas).\n- To get batch predictions for embeddings, see [Get batch text embeddings predictions](/vertex-ai/generative-ai/docs/embeddings/batch-prediction-genai-embeddings)\n- To learn more about multimodal embeddings, see [Get multimodal embeddings](/vertex-ai/generative-ai/docs/embeddings/get-multimodal-embeddings)\n- To tune an embedding, see [Tune text embeddings](/vertex-ai/generative-ai/docs/models/tune-embeddings)\n- To learn more about the research behind `text-embedding-005` and `text-multilingual-embedding-002`, see the research paper [Gecko: Versatile Text Embeddings Distilled from Large Language Models](https://arxiv.org/abs/2403.20327)."]]