Die Vertex AI Text Embeddings API verwendet dichte Vektordarstellungen: gemini-embedding-001 verwendet beispielsweise 3.072-dimensionale Vektoren. Für dichte Vektoreinbettungsmodelle verwenden Deep-Learning-Methoden, die den von Large Language Models verwendeten Methoden ähneln. Im Gegensatz zu späreren Vektoren, bei denen Wörter in der Regel direkt Zahlen zugeordnet werden, sind dichte Vektoren so konzipiert, dass sie die Bedeutung eines Textabschnitts besser darstellen. Der Vorteil der dichten Vektoreinbettungen in der generativen KI besteht darin, dass Sie anstelle der direkten Übereinstimmungen mit Wörtern oder Syntaxen besser nach Passagen suchen können, die der Bedeutung der Abfrage entsprechen, selbst wenn die Abschnitte nicht dieselbe Sprache verwenden.
Die Vektoren werden normalisiert, sodass Sie Kosinus-Ähnlichkeit, Punktprodukt oder euklidische Distanz verwenden können, um dieselben Ähnlichkeitsrankings zu erhalten.
Weitere Informationen zu Texteinbettungsmodellen finden Sie unter Texteinbettungen.
Informationen dazu, welche Sprachen die einzelnen Einbettungsmodelle unterstützen, finden Sie unter Unterstützte Textsprachen.
Hinweise
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.
Sie können Texteinbettungen mit den folgenden Modellen abrufen:
Modellname
Beschreibung
Ausgabeabmessungen
Maximale Sequenzlänge
Unterstützte Textsprachen
gemini-embedding-001
Hervorragende Leistung bei Aufgaben in englischer Sprache, mehrsprachigen Aufgaben und Code-Aufgaben. Es vereint die bisherigen spezialisierten Modelle wie text-embedding-005 und text-multilingual-embedding-002 und erzielt in den jeweiligen Bereichen eine bessere Leistung. Weitere Informationen finden Sie in unserem technischen Bericht.
Für eine hervorragende Einbettungsqualität ist gemini-embedding-001 unser großes Modell, das für höchste Leistung entwickelt wurde. gemini-embedding-001 unterstützt eine Instanz pro Anfrage.
Texteinbettungen für ein Text-Snippet abrufen
Sie können Texteinbettungen für ein Snippet aus Text mithilfe der Vertex AI API oder dem Vertex AI SDK für Python abrufen.
API-Limits
Für jede Anfrage sind Sie auf 250 Eingabetexte beschränkt.
Die API hat ein maximales Eingabetokenlimit von 20.000.
Eingaben, die dieses Limit überschreiten, führen zu einem 400-Fehler. Jeder einzelne Eingabetext ist außerdem auf 2.048 Tokens beschränkt. Überschüssiges wird stillschweigend abgeschnitten. Sie können die automatische Kürzung auch deaktivieren, indem Sie autoTruncate auf false setzen.
Alle Modelle erzeugen standardmäßig einen Embedding-Vektor in voller Länge. Für gemini-embedding-001 hat dieser Vektor 3.072 Dimensionen. Andere Modelle erzeugen 768-dimensionale Vektoren. Mit dem Parameter output_dimensionality können Nutzer jedoch die Größe des Ausgabebettungsvektors steuern.
Durch die Auswahl einer kleineren Ausgabedimensionalität kann Speicherplatz gespart und die Recheneffizienz für Downstream-Anwendungen gesteigert werden, ohne dass die Qualität wesentlich beeinträchtigt wird.
In den folgenden Beispielen wird das gemini-embedding-001-Modell verwendet.
Umgebungsvariablen für die Verwendung des Gen AI SDK mit Vertex AI festlegen:
# 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)
Einbettung zu einer Vektordatenbank hinzufügen
Nachdem Sie die Einbettung generiert haben, können Sie sie einer Vektordatenbank wie der Vektorsuche hinzufügen. Dies ermöglicht einen Abruf mit niedriger Latenz und ist von entscheidender Bedeutung, wenn die Größe Ihrer Daten zunimmt.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-09-04 (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)."]]