Embedding models work by converting text into high-dimensional floating-point arrays where mathematical distance reflects semantic relationship. In other words, ingested text data becomes points in a vector space, which enables similarity searches in vector databases, and the dimension of embeddings plays a critical role for this.
Dimensionality determines how many numerical features represent each piece of content—similar to how a detailed profile might have dimensions for age, interests, location, and preferences. Higher dimensions create more detailed “fingerprints” that capture nuanced relationships, with smaller distances between vectors indicating stronger conceptual similarity and larger distances showing weaker associations.
For example, this request to the OpenAI /embeddings API via Kong AI Gateway:
{
"input": "Tell me, Muse, of the man of many ways, who was driven far journeys, after he had sacked Troy’s sacred citadel.",
"model": "text-embedding-3-large",
"dimensions": 20
}
Creates the following embedding:
{
"object": "list",
"data": [
{
"object": "embedding",
"index": 0,
"embedding": [
0.26458353,
-0.062855035,
-0.14282244,
0.18218088,
-0.41043353,
0.3704169,
0.1712553,
-0.10945333,
-0.00060006406,
0.10076551,
-0.0697658,
0.1779686,
-0.3464596,
0.028745485,
0.3017042,
0.2543161,
-0.20916577,
-0.06255886,
-0.21469438,
0.32934725
]
}
],
"model": "text-embedding-3-large",
"usage": {
"prompt_tokens": 28,
"total_tokens": 28
}
}
The embedding
array contains 20 floating-point numbers—each one representing a dimension in the vector space.
For simplicity, this example uses a reduced dimensionality of 20, though production models typically use 1536
or more.
If you use embedding models that support defining the dimensionality of the embedding output, you should consider how to balance accuracy and performance based on your use case.
However, dimensionality extremes at the far ends of the spectrum present significant drawbacks:
Dimensionality range
|
Benefits
|
Drawbacks
|
Lower dimensionality (2–10 dimensions)
|
- Improves speed and performance
- Works well for simpler tasks like basic keyword matching or simple images, where hundreds of dimensions may suffice.
|
- Can be too simplistic, like calling a movie simply “good” or “bad”
- Might miss important nuance and lead to less accurate matches
|
Higher dimensionality (10,000+ dimensions)
|
- Improves the granularity and nuance of similarity searches
- Useful for complex tasks like semantic text understanding or detailed images, where thousands of dimensions are often required.
|
- Increases storage and computation costs
- Can suffer from the “curse of dimensionality”, where differences become less meaningful.
|
Use moderate dimensionality when possible, and tune it based on both the complexity of your data and the responsiveness required by your application.
Kong AI Gateway supports both cosine similarity and Euclidean distance for vector comparisons, allowing you to choose the method best suited for your use case. You can configure the method using config.vectordb.distance_metric
setting in the respective plugin.
- Use
cosine
for nuanced semantic similarity (for example, document comparison, text clustering), especially when content length varies or dataset diversity is high.
- Use
euclidean
when magnitude matters (for example, images, sensor data) or you’re working with dense, well-aligned feature sets.
Cosine similarity measures the angle between vectors, ignoring their magnitude. It is well-suited for semantic matching, particularly in text-based scenarios. OpenAI recommends cosine similarity for use with the text-embedding-3-large
model.

Figure 2: Visualization of cosine similarity as the angle between vector directions.
Cosine tends to perform well across both low and high dimensional space, especially in high-diversity datasets because it captures vector orientation rather than size. This can be useful, for example, when comparing texts about Microsoft, Apple, and Google.
Euclidean distance measures the straight-line (L2) distance between vectors and is sensitive to magnitude. It works better when comparing objects across broad thematic categories, such as Technology, Fruit, or Musical Instruments, and in domains where absolute distance is important.

Figure 3: Visualization of Euclidean distance between vector points.
The two graphs below illustrate a key difference between cosine similarity and Euclidean distance: two vectors can have the same angle (and thus the same cosine similarity, represented as γ
below) while their Euclidean distances may differ significantly. This happens because cosine similarity measures only the direction of vectors, ignoring their length or magnitude, whereas Euclidean distance reflects the actual straight-line distance between points in space.

Figure 4: Two vectors with equal cosine similarity (γ) but different Euclidean distances.
The following table will help you determine which embedding similarity metric you should use based on your use cases:
Similarity metric
|
Recommended use cases
|
Cosine similarity
|
- Find semantically similar news articles regardless of length
- Recommend products to users with similar taste profiles
- Identify documents with overlapping topics in large corpora
- Compare diverse text embeddings (for example, Microsoft vs. Apple)
|
Euclidean distance
|
- Find images with similar color distributions and intensity
- Detect anomalies in sensor readings where magnitude matters
- Compare aligned image patches using raw pixel embeddings
|