Embedding Model
An embedding model transforms various data into numerical vectors. Text is the most common type of data that can be embedded. Images, audio files and video files can also be embedded, though this requires a model specifically trained for that data type. There are also some domain-specific text embedding models, including models for code, legal, medical and chemical text.
For text, an embedding is an array of floating-point numbers, typically somewhere between a few hundred and a few thousand elements long. The length of this array is the model's dimensionality. Two pieces of text with similar meaning end up as vectors that are close together in this space, measured by a distance metric such as cosine similarity; two pieces of text with unrelated meaning end up far apart. This is the property Naive RAG relies on: embed the query, embed the stored documents, and find the documents whose vectors sit closest to the query's vector.
Choosing a model
Model choice comes down to a few practical trade-offs.
Dimensionality affects both retrieval quality and cost. A higher-dimensional embedding can capture more nuance, but it also takes more storage in the vector store and more compute to compare at query time. Some models, like OpenAI's text-embedding-3 family, let you request a smaller number of dimensions than the model's maximum, trading some accuracy for a smaller footprint.
Every embedding model has a maximum input length, usually measured in tokens. Text longer than that limit gets truncated or rejected, which is one of the reasons documents get split into chunks before embedding rather than embedded whole.
General-purpose models are trained on broad web text and work reasonably well across domains. Domain-specific models, trained on code, legal text, medical literature, or similar, can outperform general models within that domain, at the cost of doing worse outside it.
Whichever candidates you're comparing, don't guess: the MTEB Embedding Leaderboard tracks benchmark results across retrieval, classification, and clustering tasks for a large set of embedding models, general-purpose and domain-specific alike.
For the Spring AI-specific API used to call an embedding model, see Embedding Model under Spring AI RAG.