Embeddings guide

The embedding service in the Gemini API generates state-of-the-art embeddings for words, phrases, and sentences. The resulting embeddings can then be used for NLP tasks, such as semantic search, text classification and clustering among many others. This page describes what embeddings are and highlights some key use cases for the embedding service to help you get started.

What are embeddings?

Text embeddings are a natural language processing (NLP) technique that converts text into numerical vectors. Embeddings capture semantic meaning and context which results in text with similar meanings having closer embeddings. For example, the sentence "I took my dog to the vet" and "I took my cat to the vet" would have embeddings that are close to each other in the vector space since they both describe similar context.

This is important because it unlocks many algorithms that can operate on vectors but not directly on text.

You can use these embeddings or vectors to compare different texts and understand how they relate. For example, if the embeddings of the text "cat" and "dog" are close together you can infer that these words are similar in meaning or context or both. This ability allows a variety of uses cases described in the next section.

Use cases

Text embeddings power a variety of NLP use cases. For example:

  • Information Retrieval: The goal is to retrieve semantically similar text given a piece of input text. A variety of applications can be supported by an information retrieval system such as semantic search, answering questions, or summarization. Refer to the document search notebook for an example.
  • Classification: You can use embeddings to train a model to classify documents into categories. For example, if you want to classify user comments as negative or positive, you can use the embeddings service to get the vector representation of each comment to train the classifier. Refer to the Gemini classifier example for more details.
  • Clustering: Comparing vectors of text can show how similar or different they are. This feature can be used to train a clustering model that groups similar text or documents together and to detect anomalies in your data.
  • Vector DB: You can store your generated embeddings in a vector DB to improve the accuracy and efficiency of your NLP application. Refer to this page to learn how to use a vector DB to translate text prompts into numerical vectors.

What's next