Retrieval Augmented Generation and Large Language Models
LLMs are remarkable tools.
They can answer questions, summarize and rewrite text, provide feedback on documents, generate code, and more.
These types of tasks seemed out of reach for computers just a few years ago.
RAG is an approach that further improves the performance of large language models by giving them access to information that they don't know from their training.
To help highlight that idea, let's look at a few
examples.
Suppose I asked you the question, why are car rental expensive on the weekend?
You can probably answer that question.
More people travel on weekends, so there's more
competition for cars.
Now suppose I asked you, why are cars in
Argentina more expensive this coming weekend?
You'll need more information to answer this
one.
If you searched online, you might find that holidays will begin.
With that additional information, you again
probably could answer the question.
Finally, suppose I asked you, why doesn't Argentina have more car rentals available?
To answer this question, you'd probably need to do some deep research into the history of Argentina car´s rental development, and so forth.
In other words, you'd need access to specialized information.
You can think of the way you'd respond to these
questions as two phases.
First, you collect any necessary information, and then you reason over that information to develop your response.
As you saw with the first question, sometimes you
don't need to collect any information.
Based on your knowledge of the world, you're ready
to respond right away.
Other times though, you might need to collect a
little bit or even a lot of information.
In RAG, the process of collecting useful information is called retrieval, and the process of reasoning over that information and responding is called generation.
LLMs benefit from the retrieval stage for basically
the same reasons you do.
You can think of LLMs as kind of like a person that has a wide variety of general knowledge from reading huge chunks of the internet.
When you prompt an LLM, it relies on this knowledge
to generate a response.
For many prompts, this works great.
In other cases though, the LLM doesn't know the
information it needs to respond accurately.
The prompt might be about a very recent event or some specialized information it hasn't previously seen.
Just as was true with you, it's unreasonable to expect LLMs to be experts on every topic, and they provide much better responses when they have access to better information.
Recognizing that LLMs also benefit from a retrieval
phase is the core idea of RAG.
LLMs aren't people who spend a lot of time on Wikipedia. Instead, they're mathematical models that have been trained on massive datasets taken from all over the open internet.
During the training process, the model learns any information contained in the training data.
When you send a prompt to an LLM, you're hoping information relevant to your question was included in the training data, ideally many times.
Unfortunately, lots of information won't be
included.
Companies keep private databases, some information is just hidden or hard to access, and with news being published every minute of the day, there will always be information out there that an LLM wasn't trained on.
The question, then, is how do you make sure the LLM
knows this useful information?
The short answer? Just put it in the prompt.
The key idea of a RAG system is that you can modify a prompt before sending it to the large language model. In addition to the user's original question, you can add in information that helps the LLM respond.
.jpeg)
Comments
Post a Comment