Basic Usage
You can turn a string into a embedding using one of theembedXxx methods. The embedQuery method works on a single string and is generally meant for lookups (which we’ll see later). The embedDocuments method works on a batch of strings.
Similarity
There are several ways to do searches with embeddings, many of the advanced ones beyond the scope of this documentation, but one simple, built-in way is via cosine similarity. Cosine similarity is a metric that measures the angle between two non-zero vectors to determine their similarity, with a score of 1 meaning they point in the same direction, 0 meaning they are unrelated, and -1 meaning they point in opposite directions. What this means for embeddings is cosine similarity useful for doing searches: the higher the number, the closer the match.Search Example
It’s pretty typical to useembedDocuments to calculate embeddings for documents to be searched against via embedQuery like so:
Configuration
Different embedding models from different providers have different options, e.g. it’s common to be able to chance the default size of the calculated embeddings vector.Vectors are Provider-Specific
Even though the concept of embeddings and how to use them is the same across providers and many providers calculate embeddings that are the same size, an embedding calculated with one providers, e.g. Google, is NOT compatible with an embedding calcuated with another providers, e.g. OpenAI. You’ll need to track the source and maintain integrity yourself per the requirements of your applications.Examples
Next Steps
- Providers - Embeddings support by provider

