> For the complete documentation index, see [llms.txt](https://docs.bitnimbus.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.bitnimbus.io/resources/how-ai-turns-language-into-geometry.md). Agents can also search and read this documentation through its [MCP server](https://docs.bitnimbus.io/~gitbook/mcp).

# How AI Turns Language into Geometry

A plain-language guide to text embeddings: dense, sparse, and how to choose between them

### When Retrieval Gets It Wrong

Most retrieval failures are not bugs. The system did exactly what it was built to do. The catch is that what it was built to do depends on the type of embedding running underneath, and most teams choose one without fully understanding the trade-off.

Part 1 of this series covered prefill and decode, the two phases of LLM inference. This article moves to the layer that decides what a model gets to read in the first place: the embedding. Embeddings represent meaning as numbers, and they sit underneath semantic search, RAG pipelines, recommendation engines, and classification systems.

Before we get to the different kinds of embeddings, we need a quick look at the object they are built from: the vector.

### Start Here: What Is a Vector?

A vector is an ordered list of numbers, like \[3, 7, 2]. The easiest way to picture one is as a location. Two numbers like \[2, 5] mark a point on a flat map: 2 steps right, 5 steps up. Three numbers mark a point in 3-D space. Embeddings use many more numbers, often 768 or more, to mark a point in a space we cannot visualise. The idea is the same.

What makes vectors useful for language is that distance between points carries meaning. Words and sentences that mean similar things land close together. Unrelated concepts land far apart. When you search, your query becomes a point too, and the system returns the documents whose points sit nearest to it.

#### A famous example: king, man, woman, queen

The classic demonstration comes from word2vec, a model that learned a vector for every word by reading huge amounts of text. Because related words end up in consistent positions, you can do arithmetic on meaning. Take the vector for 'king', subtract the vector for 'man', add the vector for 'woman', and the closest word to the result is 'queen'. Nobody taught the model about royalty or gender. The relationship fell out of the geometry.

![Figure 1: The same step that takes 'man' to 'king' also takes 'woman' to 'queen', and the same step that takes 'man' to 'woman' also takes 'king' to 'queen'. Relationships between words show up as consistent directions.](https://2118062877-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRnkuGJRlRYZEKN6mZRsB%2Fuploads%2F70Vv3UuecbLO4vPGWqsg%2Funknown.png?alt=media\&token=31e48a8a-8988-4b4f-b4c9-ab661c36ffd6)

#### An everyday example: burger, pizza, restaurant, keyboard

Now take four words: burger, pizza, restaurant, and keyboard. In a trained embedding space, 'burger' and 'pizza' sit close to each other, and both sit close to 'restaurant', because they show up in the same kinds of sentences. 'Keyboard' lives in a different neighbourhood altogether, near words like 'mouse', 'monitor', and 'laptop'. Search for something related to 'pizza' and 'restaurant' comes back. 'Keyboard' does not.

![Figure 2: 'Burger', 'pizza', and 'restaurant' cluster together because they appear in the same kinds of sentences. 'Keyboard' sits in a different neighbourhood, with the other computer hardware terms.](https://2118062877-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRnkuGJRlRYZEKN6mZRsB%2Fuploads%2FywVFiTEkfghh9BILcRdP%2Funknown.png?alt=media\&token=79deba41-8556-4b05-a4ff-bc8463dda050)

Zoom out and the same idea applies to whole topics, not just a handful of words.

![Figure 3: Semantic vector space (2-D projection). Similar concepts cluster together. 'Inexpensive' and 'cheap' are near each other in dense space but share no words, so a sparse search for one will never find the other.](https://2118062877-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRnkuGJRlRYZEKN6mZRsB%2Fuploads%2FqGH3UlUqzbITKkAZPdP1%2Funknown.png?alt=media\&token=d86cb1ea-23cb-48c9-9eb5-ebee6bb0a480)

| KEY IDEA  Training does not place words at arbitrary coordinates. The model is optimised so that similar meanings cluster together. Geometry becomes a proxy for semantics. |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

### Where Embeddings Are Used

Once text becomes a vector, a lot of useful things become possible. Embeddings sit underneath a wide range of everyday AI features:

* Semantic search: finding documents by meaning rather than exact keywords
* RAG (retrieval-augmented generation): fetching the right context for an LLM to answer from
* Recommendations: finding items similar to what a user has already engaged with
* Classification and clustering: sorting or grouping text by topic or intent
* Deduplication: spotting near-identical content written in different words

The biggest of these, and the one most teams meet first, is semantic search. It is also the retrieval step inside RAG, so understanding it explains a large part of how modern AI products find information.

#### Semantic search

Traditional search matches words. Semantic search matches meaning. The process has four steps:

* Embed every document once, ahead of time, and store the resulting vectors.
* When a user searches, embed the query with the same model.
* Find the stored vectors that sit closest to the query vector.
* Return the documents those vectors came from, ranked by closeness.

This is why a search for 'the car would not start' can return a page titled 'what to do when your vehicle fails to ignite'. The two share almost no words, but their vectors sit close together.

#### Finding the nearest neighbours

Step three is harder than it sounds. A real collection can hold millions of vectors, each with hundreds or thousands of dimensions. Comparing the query against every one of them is exact, but far too slow to run on every search.

Systems solve this with approximate nearest neighbour (ANN) search. Algorithms like HNSW or IVF organise the vectors so that a query only has to examine a small, promising slice of them. They are built into vector databases such as Pinecone, Qdrant, Weaviate, and pgvector, and they return close matches within an acceptable latency.

| NOTE  ANN search is an approximation. It trades a small amount of recall for large gains in speed. For most production use cases that is fine, but it helps to know the trade exists. |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

### Two Ways to Embed Text

Text embeddings come in two main flavours, and nearly every retrieval system you will meet uses one or both.

Dense embeddings are compact vectors, usually 768 to 1,536 numbers long, where almost every number carries information. They capture what a piece of text means. Sparse embeddings are enormous vectors, around 10,000 numbers long, where nearly every number is zero. They capture which exact words appear.

The rest of this article takes each in turn, shows where each one breaks, and then looks at how teams combine them.

### Dense: When Meaning Matters More Than Words

A dense embedding is a fixed-length vector where most, if not all, dimensions hold a non-zero value. Every query and every document gets one: a point in a high-dimensional space, whose position decides what gets retrieved.

#### What lives inside the dimensions

No single dimension maps to a human-readable idea like 'colour' or 'profession'. Each one holds an abstract feature the model learned during training. Meaning emerges from the vector as a whole, not from any one number inside it.

That is what lets dense embeddings match across different wording. 'The car would not start' and 'the vehicle failed to ignite' share no vocabulary, yet their vectors land close together because the model has learned they describe the same situation.

#### The blind spot

Dense embeddings are trained on a corpus. If your domain uses terminology that was rare or absent there, such as specialist legal clauses, unusual scientific notation, or internal product codes, the model may cluster things that should stay distinct. Semantics dominate, so a search for a precise part number can surface related but wrong results. That is not a bug. It is what the model was optimised to do.

### Sparse: When the Exact Word Is the Point

A sparse embedding is a very large vector, typically around 10,000 dimensions, where almost all values are zero. Only the dimensions for terms that actually appear in the text carry a value, and that value reflects how important the term is. It is roughly what TF-IDF has always measured, expressed as a vector.

#### Built for precision

Sparse embeddings are designed for exact term overlap. They find documents that contain the precise words in the query, which is what traditional search engines have always done. BM25, the algorithm behind Elasticsearch and Lucene, is a sparse method at its core.

Because sparse vectors are mostly zeros, you do not need ANN search. An inverted index maps each term to the documents containing it, so lookup is fast and exact. That is why Elasticsearch is still the default for log search, e-commerce catalogues, and legal databases.

#### The vocabulary gap

The weakness is vocabulary mismatch. If a user searches 'inexpensive flights' and your documents say 'cheap', a purely sparse system returns nothing. No shared term means no match, even when the meaning is identical. Synonyms, paraphrases, and cross-lingual queries all hit this wall.

| KEY CONTRAST  Dense finds what things mean, even when the words differ. Sparse finds the exact words, even when the meaning is complicated. Neither is complete on its own. |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

<div data-with-frame="true"><img src="https://2118062877-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRnkuGJRlRYZEKN6mZRsB%2Fuploads%2FFE3Y29Feh2RIqdsHoqJG%2Funknown.png?alt=media&amp;token=def665fe-8322-4522-8351-6feb5ea77362" alt="Figure 4: Dense vs sparse vector. Dense vectors have non-zero values across most dimensions (left). Sparse vectors are nearly all zeros, and only matched terms carry weight (right, amber bars)."></div>

## Side by Side

<table data-header-hidden data-search="false"><thead><tr><th></th><th></th><th></th></tr></thead><tbody><tr><td>Property</td><td>Dense</td><td>Sparse</td></tr><tr><td>Vector size</td><td>Compact (768–4,096 dims)</td><td>Large (~10,000 dims)</td></tr><tr><td>Non-zero values</td><td>Most dimensions carry a value</td><td>Most dimensions are zero</td></tr><tr><td>What it captures</td><td>Semantic meaning</td><td>Exact term overlap</td></tr><tr><td>Search method</td><td>Approximate nearest neighbour</td><td>Inverted index</td></tr><tr><td>Tooling examples</td><td>Pinecone, Qdrant, pgvector</td><td>Elasticsearch, Lucene</td></tr><tr><td>Fails when</td><td>Domain terms are rare or precise</td><td>Query and doc use different words</td></tr><tr><td>Best for</td><td>RAG, semantic search, clustering</td><td>Keyword search, log search, e-commerce</td></tr></tbody></table>

### Combining the Two Text Embedding Methods

Each method covers the other's blind spot, so production systems increasingly run both in parallel and merge the results. This is hybrid search, and it is quickly becoming the default for enterprise RAG and any search where precision matters.

The most common way to merge is reciprocal rank fusion (RRF). Each result is scored by its rank in each list, and the scores are added together. This sidesteps a real problem: dense cosine similarity and BM25 scores live on different scales and cannot be compared directly. Rankings from RRF tend to be more robust than either method alone.

![Figure 5: Hybrid search pipeline. Dense and sparse retrieval run in parallel. Reciprocal Rank Fusion (RRF) merges both ranked lists into a single result set that captures both semantic recall and keyword precision.](https://2118062877-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRnkuGJRlRYZEKN6mZRsB%2Fuploads%2FAsquPX81RkHMK6JVfnk8%2Funknown.png?alt=media\&token=5d33c351-1db3-413d-b42e-cface86ee067)

#### Where you see it in production

* Enterprise knowledge bases where users mix natural-language questions with exact product codes
* RAG pipelines that need both semantic recall and precise keyword anchoring
* Legal and patent search, where both concepts and exact statutory language matter
* E-commerce, where queries combine intent with exact attribute matching

### When to Use Which

#### Dense embeddings: where to reach for them

* Semantic search: finding documents by meaning rather than keywords
* RAG (retrieval-augmented generation): giving an LLM the right context
* Recommendations: finding items similar to what a user has engaged with
* Question answering: matching a question to a passage that answers it
* Clustering and deduplication: grouping similar content
* Cross-lingual and image-text retrieval (for example CLIP)

#### Sparse embeddings: where to reach for them

* Traditional search engines and keyword-driven retrieval
* E-commerce and product catalogues, where exact SKUs and attributes matter
* Legal and patent search, where statutory language must match precisely
* Log and code search, where exact strings matter at scale
* Fast first-stage retrieval before dense re-ranking in large pipelines

### BERT: The Architecture Underneath

Most dense embedding models trace back to one architecture: BERT, short for Bidirectional Encoder Representations from Transformers, introduced by Google in 2018. BERT is an encoder. It takes in the whole input at once, and every token can draw on the context on both sides of it. Generative models like GPT are decoders, which work differently: they read and write strictly left to right, one token at a time, and the latest generation still does. Seeing both sides at once is what makes encoders good at representing meaning that depends on context.

BERT is pre-trained on large text corpora and then fine-tuned for specific tasks. Sentence-BERT (SBERT) adapted the architecture to produce sentence-level vectors efficiently, which is what made large-scale semantic retrieval practical.

#### Why it matters for classification

BERT-style encoders also dominate classification: give the model a piece of text and get back a category with a confidence score. Document routing, compliance checks, intent detection, and risk scoring are all encoder workloads. The architecture suits them because it builds a context-aware representation of the full input instead of predicting the next token.

Major providers continue to invest in encoder models for structured decision tasks. They serve a different purpose from generative LLMs, because they represent rather than generate. For workflows that need consistent, auditable outputs, they are often the better tool.

| NOTE  Encoders produce representations of input. Decoders generate new text. Many production systems combine both: an encoder retrieves relevant context, and a decoder writes an answer from it. |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

### Picking the Right Embedding Model

With the two methods understood, the next question is which model to use. The standard starting point is MTEB, the Massive Text Embedding Benchmark, maintained on Hugging Face. It scores models across classification, clustering, pair scoring, reranking, retrieval, summarisation, and more, using one consistent methodology.

For RAG pipelines, the retrieval score is the one to watch. It measures how well a model finds the right document for a natural-language query, which is exactly what a RAG system does at inference time. At the time of writing, Google's Gemini embedding models sit at or near the top of the overall rankings, and OpenAI's text-embedding-3-large is a strong general-purpose option, with top-five retrieval results that include legal retrieval tasks. Older models such as ada-002 trail well behind.

![Figure 6: Approximate MTEB retrieval scores by model generation. Scores shift as models are updated, so always verify against the live leaderboard.](https://2118062877-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRnkuGJRlRYZEKN6mZRsB%2Fuploads%2FhrFSTSiV2TyWrjCtSVbi%2Funknown.png?alt=media\&token=0348c95e-33e9-422c-bfb1-9a274de82776)

| TIP  MTEB tells you which models are strong in general. It does not tell you which is strongest on your data. Check the per-task breakdown for the domain closest to yours: huggingface.co/spaces/mteb/leaderboard |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |

#### Where a general benchmark stops

A leaderboard ranks models on public datasets. Your data is not public. Your terminology, your document structure, and the way your users phrase questions can all push a top-ranked model below a lower-ranked one that happens to fit your domain better. The only reliable way to know is to test candidates against your own content.

This is where Bitnimbus can help. We work with teams to identify the right embedding model for their needs, evaluating candidates against real queries and real documents. Where an off-the-shelf model falls short, we can fine-tune one tailored to your domain, so retrieval reflects the way your business actually talks.

### The Short Version

We looked at what text embeddings are and the two kinds in common use. In an industry that moves as fast as AI, it is easy to skip past a foundational choice like this one while designing a product. Embeddings are the lifeblood of many of the most common retrieval systems, and getting them right is essential.

* Dense embeddings find what things mean, even when the words are completely different.
* Sparse embeddings find the exact words, even when the concept is complex.
* Hybrid search is becoming the production default: BM25 precision layered over dense semantic recall.
* BERT-style encoders are the architecture behind dense embeddings and most classification systems.
* On MTEB, the overall rank matters less than the retrieval score for your domain. Check that number, then test on your own data.

<br>

Next in the series: BERT itself. How attention works, why bidirectionality changes what the model learns, and what fine-tuning actually modifies inside the weights.

### Sources

#### Vectors and word embeddings

* Mikolov, T., Chen, K., Corrado, G., and Dean, J. (2013). Efficient Estimation of Word Representations in Vector Space. arXiv:1301.3781. arxiv.org/abs/1301.3781
* Emerging Technology from the arXiv (2015). King – Man + Woman = Queen: The Marvelous Mathematics of Computational Linguistics. MIT Technology Review, 17 September 2015. technologyreview\.com/2015/09/17/166211/king-man-woman-queen-the-marvelous-mathematics-of-computational-linguistics/

#### BERT and sentence embeddings

* Devlin, J., Chang, M., Lee, K., and Toutanova, K. (2018). BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding. arXiv:1810.04805. arxiv.org/abs/1810.04805
* Reimers, N. and Gurevych, I. (2019). Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks. arXiv:1908.10084. arxiv.org/abs/1908.10084

#### Search and retrieval

* Malkov, Y. A. and Yashunin, D. A. (2016). Efficient and robust approximate nearest neighbor search using Hierarchical Navigable Small World graphs. arXiv:1603.09320. arxiv.org/abs/1603.09320
* Robertson, S. and Zaragoza, H. (2009). The Probabilistic Relevance Framework: BM25 and Beyond. Foundations and Trends in Information Retrieval, 3(4), 333-389.
* Cormack, G. V., Clarke, C. L. A., and Buettcher, S. (2009). Reciprocal Rank Fusion outperforms Condorcet and individual rank learning methods. Proceedings of SIGIR 2009.

#### Benchmarks and models

* Muennighoff, N., Tazi, N., Magne, L., and Reimers, N. (2022). MTEB: Massive Text Embedding Benchmark. arXiv:2210.07316. arxiv.org/abs/2210.07316
* MTEB leaderboard, Hugging Face. huggingface.co/spaces/mteb/leaderboard
* OpenAI (2024). New embedding models and API updates. openai.com/index/new-embedding-models-and-api-updates/
* Google. Embeddings, Gemini API documentation. ai.google.dev/gemini-api/docs/embeddings
