Embeddings for Text
Converts text data into vector representations for semantic search, classification, clustering, and similar tasks.Embeddings for Text is a natural language processing technique that converts textual data into numerical vectors that can be processed by machine learning algorithms, especially large models. These vector representations are designed to capture the semantic meaning and context of the words they represent.
This model card features two models:
You can get text embeddings for a snippet of text by using the Vertex AI API or the Vertex AI SDK for Python.
To get text embeddings, send a POST request by specifying the model ID of the publisher model.
Before using any of the request data, make the following replacements:
PROJECT_ID
: Your project ID.TEXT
: The text that you want to generate embeddings for.HTTP method and URL
Request JSON body
When using model versions released on or after August 2023, including text-embedding-005
, text-multilingual-embedding-002
, textembedding-gecko@003
and textembedding-gecko-multilingual@001
, there is a new task type parameter and the optional title (only valid with task_type=RETRIEVAL_DOCUMENT
).
Task type parameter
The task_type
parameter is defined as the intended downstream application to help the model produce better quality embeddings. Not all model versions support all task types.
task_type | Description |
---|---|
RETRIEVAL_QUERY | Specifies the given text is a query in a search/retrieval setting |
RETRIEVAL_DOCUMENT | Specifies the given text is a document in a search/retrieval setting |
SEMANTIC_SIMILARITY | Specifies the given text will be used for semantic textual similarity (STS) |
CLASSIFICATION | Specifies that the embeddings will be used for classification |
CLUSTERING | Specifies that the embeddings will be used for clustering |
QUESTION_ANSWERING | Specifies that the query embedding is used for answering questions. Use RETRIEVAL_DOCUMENT for the document side. |
FACT_VERIFICATION | Specifies that the query embedding is used for fact verification |
CODE_RETRIEVAL_QUERY | Specifies that the query embedding is used for code retrieval for Java and Python(preview-0815 model only). |
Output dimensionality parameter
A new parameter outputDimensionality
is supported for model version 005
. You can use this parameter to reduce the embedding size, for example, for storage optimization.
curl command
Save the request body in a file called request.json
, and execute the following command:
You should receive a JSON response similar to the following:
If you're not running this code in a > Google Cloud VM or notebook, before using the SDK run gcloud auth application-default login
to authenticate.
Install the Vertex AI LLM Python SDK:
Note: The runtime must be restarted so that the correct package is installed.
To learn how to install and use the Vertex AI client library, see Vertex AI client libraries. See the Vertex AI Python API reference for details. To authenticate to Vertex AI, set up Application Default Credentials. See Set up authentication for a local development environment for details.
Call the Vertex AI LLM Embedding API:
Replace YOUR_PROJECT_ID
in the following curl command:
Semantic search is a type of search that uses the meaning of words and phrases to find relevant results. The following colab examples demonstrate how to do semantic search with embeddings generated from the news text and using Google ScaNN: Efficient Vector Similarity Search and Vertex AI Matching Engine to retrieve the most relevant text semantically.
Colab samples
Resource ID | Release date | Release stage | Description |
---|---|---|---|
text-embedding-preview-0815 | 2024-08-15 | Preview | Additional feature for retrieving relevant code blocks using plain text queries on top of previous versions. |
text-embedding-005 | 2024-05-14 | General Availability | Improvements in established benchmarks covering various downstream tasks, such as retrieval and classification |
text-multilingual-embedding-002 | 2024-05-14 | General Availability | Improvements in established benchmarks covering various downstream tasks, such as retrieval and classification |
text-embedding-preview-0409 | 2024-04-09 | Preview | Improvements in established benchmarks covering various downstream tasks, such as retrieval and classification |
text-multilingual-embedding-preview-0409 | 2024-04-09 | Preview | Improvements in established benchmarks covering various downstream tasks, such as retrieval and classification |
textembedding-gecko@003 | 2023-12-05 | General Availability | Updated version with enhanced AI quality |
textembedding-gecko@002 | 2023-11-02 | General Availability | Updated version with enhanced AI quality |
textembedding-gecko-multilingua@001 | 2023-11-02 | General Availability | Optimized for a wide range of non-English languages. |
textembedding-gecko@001 | 2023-05-07 | General Availability |
Google Cloud Console has failed to load JavaScript sources from www.gstatic.com.
Possible reasons are: