Intro RAG Reflection#
During the course, I was introduced to Retrieval-Augmented Generation, usually called RAG. RAG is a method that can make AI systems more useful and reliable, because the language model gets access to relevant information before it generates an answer.
What is RAG?#
RAG stands for Retrieval-Augmented Generation. It can be understood in three parts:
- Retrieval means finding relevant information from a knowledge source.
- Augmented means that the found information is added as extra context.
- Generation means that the language model uses the context to generate an answer.
In simple words, RAG is a way to make an AI answer based on specific information instead of only using what the model already knows.
Why RAG is useful#
Large Language Models can answer many questions, but they also have some weaknesses. They may give outdated answers, misunderstand the question, or invent information if they do not know the correct answer. This is often called hallucination.
RAG can help reduce this problem. Instead of asking the model to answer directly, the system first searches in a collection of documents, pages or data. The most relevant information is then sent to the model together with the user’s question.
This means the model has something concrete to base its answer on. The answer becomes more connected to the source material and less dependent on the model’s memory.
How a RAG system works#
A simple RAG system usually works like this:
- A user asks a question.
- The system searches in a knowledge base.
- The system finds the most relevant text passages.
- The language model receives both the question and the retrieved text.
- The model generates an answer based on that context.
For example, if I have a chatbot connected to my portfolio, the chatbot should not guess what I have written. Instead, it should search in my portfolio posts and use the relevant parts to answer questions.
Important parts of RAG#
There are a few important concepts in RAG:
- Knowledge base: The collection of information the chatbot can search in.
- Chunking: Splitting long texts into smaller parts, so they are easier to search.
- Embeddings: A way to represent text as numbers, so similar meanings can be found.
- Retrieval: Finding the most relevant chunks for the user’s question.
- Prompt/context: The retrieved information is added to the prompt before the model answers.
These parts work together. If the knowledge base is unclear or badly structured, the chatbot may retrieve weak information and give a weak answer. If the knowledge base is clear, the answer is usually better.
Example#
If a user asks: “What is my project about?”
A normal chatbot might answer generally or guess. A RAG chatbot can search in my project posts and find information about my E.G. chatbot project. It can then answer that the project is about building a website and chatbot to help with Christmas market stall booking and repeated customer questions.
This makes the answer more accurate because it is based on my actual portfolio content.
Benefits and challenges#
The main benefit of RAG is that the chatbot can use updated and specific information. If the knowledge base is changed, the chatbot can also be updated without retraining the whole language model.
RAG can also make answers easier to trust, because they are based on a source. This is useful in systems where the information changes over time, such as websites, documentation, portfolios or customer support pages.
However, RAG is not perfect. If the system retrieves the wrong text, the answer can still be wrong. The quality of the answer depends on the quality of the data, the way the text is split into chunks, and how well the system finds the right information.
Reflection#
I think RAG is important because it shows that AI is not only about the model itself. The data around the model is just as important. A chatbot becomes more useful when it has access to the right information and can use that information in a structured way.
For me, RAG is especially useful to understand because many practical AI systems need to answer based on specific content. A chatbot for a portfolio, a company website or a project does not need to know everything in the world. It needs to know the right information for that specific situation.
The easiest way for me to remember RAG is:
Search first, answer after.
The system first retrieves relevant information, and then the language model uses that information to generate a better answer.