Skip to content

On the limitations of RAG

Vector search over a single projection is doomed

The Google DeepMind team published an intriguing paper, in which it is shown that vector search has fundamental limitations on retrievability.

A solid write-up of the paper was done in the Data Secrets group:

The gist

It turns out that the embedding-based search everyone loves and takes for granted may not deliver everything and has a serious fundamental limit. With a fixed vector dimensionality, this approach simply cannot retrieve all the relevant documents from the database. In their work, Google proved this both theoretically and experimentally.

An intuitive explanation of why: the larger the knowledge base, the more diverse combinations of queries and relevant documents we need to support. But the search space is always limited by the dimensionality of the embeddings. So, beyond a certain number of documents, arranging the points in a latent space so that for every query we find the right docs is simply impossible.

What are we talking about?

First, let’s recall how the data for RAG is usually prepared:

  1. Documents are torn into chunks the size of a paragraph, fed into one of the embedding models to obtain a set of vectors which are then stored into a vector database.
  2. When relevant documents need to be retrieved, the user’s query is fed into the same embedding model, and turned into a vector.
  3. The database of chunk vectors is searched for all vectors close enough to the query’s.
  4. Matching chunks are augmented by other stuff like results of a full-text search, file metadata, paths, and so on.
  5. The end result is a list of documents (or their fragments) sorted by relevance or whatever metric is thought to be useful.

Overall this works, but there is a fundamental gap between steps 2 and 3. That is, both the data and the query play a game of broken telephone twice and then pass through the keyhole of the embedder, only to be blindly comared by the vector database that knows nothing about the domain.

Even worse, to do so we literally shredded all the documents into pieces that no longer know about each other. This causes long-range semantic connections to be lost, both within the document and between documents.

On top of that mess, we have the fundamental limitations on retrievability pointed out by Google.

An example from real life

Imagine a situation where you have a pile of legal documents with stereotypical headers where couterparties are introduced. Something like “Totally Not Evil Corp.”, hereinafter referred to as the Customer, and “Acme Corp.”, referred to as the Contractor, and so on.

What matters here is that the document body typically mentions only the roles (“Customer”, “Contractor”), not their names. In hundreds of documents there would be hundreds of counterparties; the same company could be the customer in one document, the contractor in another, etc.

Imagine you want to run a query like: “give me all documents where X acted in the role of Y and also Z”. To handle that properly, you need not just first-level semantics, but the ability to work with the attention terms pay to one another.

Classical RAG would fail here, because it tears the document into chunks, and in every chunk except the first there would be only “Customer”, with no semantic link whatsoever to actual company name.

Graph RAG can do this sort of thing, but there it is solved at the symbolic level (“extract all facts from X”). The trouble is that to do that you really need a latent space for such kind of work. At the token level, you can only extract the information that was considered important at the moment it was fixed. Associations that appear later would not bring such facts up.

In practice, one can try to pull every document mentioning a particular entity, cram it all into the context (millions of tokens), and then hope the neural network would swallow it and yield something useful.

Keep in mind, those millions of tokens would be spent on every query. Now imagine how many counterparties a big corporation could have and how often they would need to query those documents.

Sometimes in a more complex query, there could be no direct mention of the counterparty at all. In such case only specialized software or agents combing through the documents for leads could cope with that.

We are trying to offer a third way.

Approaches to a solution

Sure enough, there are ways to stitch the shreds back together after they have been retrieved and augmented with new context. That, for example, is how the CacheClip framework works: precomputed chunks are injected into the context at the appropriate positions, and the self-attention between them is re-established by a smaller model. This is cheaper than a full prefill and provides decent quality.

But even so, you can only stitch togther the information that was recalled from the database. The chunks themselves will tell you nothing about the connections.

We do roughly the same thing as CacheClip, but

  1. We do not tear documents into chunks; instead we store semantically connected memories of them.
  2. When the user’s query comes in, we interpret it and recall elements that are not just conceptually similar, but also semantically matching to what is being asked, with the possibility of post-hoc refinement.
  3. The output is the same familiar list of documents or their fragments with quotes.

All of this integrates into existing RAG pipelines and can then be processed by neural networks as usual.

The main point is that nowhere are we limited to a single embedding; we search the whole memory at once. Our approach will make it possible to retrieve information along associations that did not exist at the time the memory was formed.

For a complete solution, we need discrete semantics across terms and a mechanism for forming complex descriptions. Both are still in the works.

This note is also available in Russian: О проблемах RAG.