Is RAG Still Needed? Choosing the Best Approach for LLMs

Are massive context windows replacing RAG? 🤔 Martin Keen breaks down RAG vs. long context in LLM workflows. Explore how vector databases, semantic search, and embedding models impact AI performance to help you choose the right solution for your applications. 🚀

*https://www.youtube.com/watch?v=UabBYexBD4k
**https://300.ya.ru/v_tHSzrKMU

пресказ видео

00:00:00 Проблема контекстного внедрения в LLM

  • LLM «заморожены во времени»: они не знают о текущих событиях и личных данных пользователя.
  • Необходимо решить проблему контекстного внедрения, чтобы модель могла обрабатывать актуальные данные.

00:00:59 Инженерный подход

  • Подготовка документов: PDF-файлы, код, книги разбиваются на фрагменты и передаются в модель встраивания.
  • Векторы фрагментов сохраняются в векторной базе данных.
  • При задавании вопроса программа выполняет семантический поиск и вводит релевантные фрагменты в контекстное окно.

00:02:09 Длинный контекст

  • Метод грубой силы: документы помещаются прямо в контекстное окно модели.
  • Механизм внимания модели выполняет поиск ответа.
  • Современные модели имеют большие контекстные окна, позволяющие хранить миллионы токенов.

00:04:09 Преимущества длинного контекста

  • Упрощение инфраструктуры: удаление базы данных и модели встраивания.
  • Снижение риска «молчаливого сбоя»: модель видит все данные без этапа извлечения.
  • Возможность сравнения документов: модель видит полные документы, что позволяет выявлять недостающие фрагменты.

00:07:47 Недостатки длинного контекста

  • Неэффективность вычислений: необходимость обработки больших объёмов данных при каждом запросе.
  • Проблема «иголки в стоге сена»: модель может ослаблять внимание при большом объёме данных.
  • Ограничения для корпоративных данных: контекстное окно недостаточно для обработки терабайтов данных.

00:10:23 Заключение

  • Длинный контекст подходит для ограниченного набора данных и сложных рассуждений.
  • Векторная база данных остаётся надёжным хранилищем для бесконечных корпоративных знаний.
  • Вопрос к аудитории: какой подход выбрать?

В этом видео

Эпизоды
Расшифровка видео
Поиск в расшифровке
Эпизод 1: The problem with LLMs
0:00
0 секунд
There’s a fundamental truth about LLMs, large language models. They are frozen in time. They
0:09
9 секунд
know everything about our world up until their training cutoff date and absolutely
0:16
16 секунд
nothing about what happened 5 minutes ago. Nor do they know anything about your private data,
0:21
21 секунда
your internal wikis, your proprietary codebase. And if we do want an LLM to know any of that stuff,
0:28
28 секунд
well, we have to solve the problem of context injection. How do we get the right data into the
0:36
36 секунд
model at the right time? And there have been two very different ways to handle this. Now, the first
Эпизод 2: Retrieval augmented generation
0:43
43 секунды
is really what we can think of as the engineering approach. It’s RAG, retrieval augmented generation.
0:52
52 секунды
So here we’ve got an LLM and we’ve also got an input prompt from the user. Now ahead of time
1:01
1 минута 1 секунда
we take some of the documents that we want to give to this LLM. So these are documents that could be
1:09
1 минута 9 секунд
PDFs or code files or entire books and we chunk them. We break them up into smaller chunks and
1:19
1 минута 19 секунд
we pass them through to an embedding model and the embedding model takes those chunks and it
1:27
1 минута 27 секунд
turns them into vectors and those vectors are then stored in a dedicated vector database. Now when a
1:38
1 минута 38 секунд
user asks a question, it performs a semantic search to retrieve the most relevant chunks
1:47
1 минута 47 секунд
and then inject them into the context window. So now the context window has the user prompt,
1:54
1 минута 54 секунды
but it also has all of these chunks that we have taken from the vector database and together this
2:03
2 минуты 3 секунды
forms the context window. Now this works but it does rely on something. It relies on the
2:10
2 минуты 10 секунд
hope that your retrieval logic actually found the right information in the vector database.
Эпизод 3: The long context approach
2:15
2 минуты 15 секунд
Now the the second approach is really a bit more of a brute force approach and that one is called
2:23
2 минуты 23 секунды
long context. Now this is really the model native solution because you skip the database here and
2:31
2 минуты 31 секунда
you skip the embedding model. All you do is you take your documents and you just well you put them
2:38
2 минуты 38 секунд
straight into the context window and then you let the model’s attention mechanism actually do the
2:44
2 минуты 44 секунды
heavy lifting of finding the answer. Now for a long time this kind of brute force method wasn’t
2:50
2 минуты 50 секунд
really much of an option because initially context windows were tiny. Early LLMs had context windows
2:58
2 минуты 58 секунд
that could maybe store what like 4K of tokens. You couldn’t fit a novel in there, let alone a
3:06
3 минуты 6 секунд
corporate knowledge base. You basically had to use RAG. But today’s models have much larger context
3:14
3 минуты 14 секунд
windows. Some of them have, you know, a million tokens plus. And to put that into perspective,
3:21
3 минуты 21 секунда
a million tokens is roughly 700,000 words. and you could fit the entire Lord of the Rings series into
3:29
3 минуты 29 секунд
the prompt and still have room for The Hobbit. So, this massive jump in capacity forces us to ask a
3:36
3 минуты 36 секунд
difficult question about our architecture. Because if we can simply command A, command C, command V,
3:43
3 минуты 43 секунды
all of our documentation into the models context window, do we really need the overhead of
3:49
3 минуты 49 секунд
embedding models and vector data stores? Is RAG becoming an unnecessary complexity layer? Well,
Эпизод 4: Why long context wins
3:56
3 минуты 56 секунд
if we accept that we can fit whatever data we need into the context window, then the argument
4:03
4 минуты 3 секунды
for doing so basically boils down to one word, simplicity. And let me give you three reasons why
4:11
4 минуты 11 секунд
stuffing the context window directly may indeed be the way to go. And reason number one is collapsing
4:20
4 минуты 20 секунд
the infrastructure. A production RAG system. Well, it is quite heavy. You need a a chunking strategy
4:27
4 минуты 27 секунд
which is like fixed size maybe or sliding window or recursive. You decide. You’re going to need
4:33
4 минуты 33 секунды
a embedding model to encode the data. You need a a vector database to store it. You’re going
4:39
4 минуты 39 секунд
to need a reranker to sort the results. you need to keep all the vectors in sync with your source
4:45
4 минуты 45 секунд
data. It’s basically a lot of moving parts, a lot of places for things to break. And long context
4:52
4 минуты 52 секунды
offers what we might call well just simply the uh the no stack stack. You remove the database, you
5:01
5 минут 1 секунда
remove the embeddings, you remove the retrieval logic. The architecture simplifies down to getting
5:06
5 минут 6 секунд
the data and just well sending it to the model. So that’s reason number one. Reason number two is the
5:15
5 минут 15 секунд
retrieval lottery. Now, RAG introduces a critical point of failure here, the retrieval step itself,
Эпизод 5: The retrieval lottery
5:23
5 минут 23 секунды
because when a user asks a question, RAG looks at mathematical representations of the data, which are
5:30
5 минут 30 секунд
stored in vectors. And vectors are basically just like a really long series of numbers in
5:37
5 минут 37 секунд
an array. And it tries to find the closest match. That’s semantic search. But semantic
5:43
5 минут 43 секунды
search is probabilistic and for all manner of reasons, the retrieval might fail to find the
5:49
5 минут 49 секунд
relevant document. And we actually have a name for this. It’s called silent failure. The answer,
5:55
5 минут 55 секунд
well, it existed in the data, but the LLM never saw it because the retrieval step didn’t return
6:01
6 минут 1 секунда
the right results. With long context, there is no retrieval step. The model gets to see everything.
Эпизод 6: Global reasoning limitations
6:08
6 минут 8 секунд
Now, reason number three that is well, I think we’re going to call this the whole book problem.
6:15
6 минут 15 секунд
A RAG is fundamentally designed to retrieve what exists. It relies on finding a semantic
6:21
6 минут 21 секунда
match between your query and a specific snippet of text in your database. But what if the answer
6:27
6 минут 27 секунд
lies in what’s not in the database? So, so let’s say you have a set of product requirements stored
6:35
6 минут 35 секунд
as a document and you’ve also got a set of release notes stored as a document and then we ask which
6:42
6 минут 42 секунды
security requirements were omitted from the final release. Now using RAG when you query for omitted
6:50
6 минут 50 секунд
security requirements the vector search looks for chunks discussing well security and requirements.
6:57
6 минут 57 секунд
It retrieves snippets from the requirements doc. It retrieves snippets from the release notes,
7:02
7 минут 2 секунды
but it cannot retrieve the gap between them. And because RAG only shows the model a few isolated
7:09
7 минут 9 секунд
snapshots, the model never sees the full picture required to spot the missing pieces. The model
7:15
7 минут 15 секунд
really needs both of these documents in full to perform the comparison, which is exactly what
7:22
7 минут 22 секунды
long context does by dumping the whole book, the full requirements doc and the full release notes
7:28
7 минут 28 секунд
into the context window. So, is RAG dead? Is the vector database destined for the museum of things
Эпизод 7: Rethinking RAG benefits
7:35
7 минут 35 секунд
we needed in 2024? Well, not quite because while long context wins on simplicity, RAG still has a
7:43
7 минут 43 секунды
place. And I got another three reasons to support that. So, reason number one is the rereading text.
7:53
7 минут 53 секунды
Now, long context creates a massive compute inefficiency. So, if we take a manual, let’s say
7:59
7 минут 59 секунд
this is like a a 500 page manual, and we’ve got to turn this into tokens. Well, that’s something like
8:08
8 минут 8 секунд
250k of tokens. And we need to do that every time we make a user query and we put this document in
8:17
8 минут 17 секунд
the prompt. You’re basically requiring the model to process that manual every time. Now, RAG also
8:23
8 минут 23 секунды
has to process that manual, but it only pays that processing cost once at indexing time. Now, prompt
8:30
8 минут 30 секунд
caching that can partially offset some of this for static data, but for dynamic data streams where
8:36
8 минут 36 секунд
content changes frequently, you are stuck paying the full tax on every request. Reason number two
Эпизод 8: The noise and data problem
8:45
8 минут 45 секунд
is the needle in the haystack problem. Now, there’s a an intuitive assumption that if data
8:52
8 минут 52 секунды
is in the context window, the model’s probably going to use it, but research suggests otherwise.
9:00
9 минут
Because as we start with a context window and then it grows and it continues to grow and now we’re at
9:06
9 минут 6 секунд
like 500,000 tokens, well, the model’s attention mechanism can get a bit diluted. If you ask a
9:14
9 минут 14 секунд
specific question about a single paragraph that’s buried in, let’s say, the middle of a 2,000 page
9:19
9 минут 19 секунд
document, well, the model often fails to retrieve it or it hallucinates details from the surrounding
9:26
9 минут 26 секунд
text. But with RAG, we’re giving the model less noise. So by retrieving, say only the top five
9:35
9 минут 35 секунд
relevant chunks, RAG has removed the haystack and presents the model with just the needles.
9:42
9 минут 42 секунды
It forces the model to focus on the signal and not the noise. And then reason number three,
9:49
9 минут 49 секунд
well that is the infinite data set. Now a context window of millions of tokens sounds great but in
9:57
9 минут 57 секунд
the scheme of enterprise data that’s really just a drop in the bucket. I mean an enterprise data lake
10:05
10 минут 5 секунд
that’s probably measured in terabytes or or maybe even petabytes. So if you want an infinite data
10:13
10 минут 13 секунд
set that stores everything, you really do need to have a retrieval layer to filter information down
10:19
10 минут 19 секунд
to something that fits into the LLM context window. So where does this leave us? Well,
Эпизод 9: Choosing the right strategy
10:25
10 минут 25 секунд
if your problem involves a bounded data set and requires complex global reasoning like analyzing
10:30
10 минут 30 секунд
a specific legal contract or summarizing a book, I think long context is the way to go. It simplifies
10:38
10 минут 38 секунд
the stack and it improves the reasoning. But if you’re navigating the infinite data set of
10:44
10 минут 44 секунды
enterprise knowledge, the vector database remains the only viable warehouse for your data. But how
10:51
10 минут 51 секунда
about you? Are you team long context, team RAG, maybe a bit of both? Let me know in the comments.

Поделиться: