Sign in to save

Bookmark this page so you can find it later.

Sign in to save

Bookmark this page so you can find it later.

Retrieval Augmented Generation, often called RAG, is a way to make AI chatbots more accurate by letting them look up information before they answer. Instead of relying only on what the model learned during training, the system searches a knowledge source such as a textbook, website, database, or class notes. This matters because many AI mistakes happen when a model guesses without checking facts.

RAG helps connect language models to reliable, current information.

Key Facts

  • RAG = retrieval + generation: first find relevant information, then write an answer using it.
  • Basic flow: user question -> search query -> retrieved documents -> AI model -> final answer.
  • Similarity search compares meaning, not just exact words, using vectors.
  • A vector embedding turns text into a list of numbers so similar ideas can be found mathematically.
  • Cosine similarity = (A · B) / (|A||B|), often used to compare two text embeddings.
  • RAG can reduce hallucinations, but it does not guarantee that every answer is correct.

Vocabulary

Retrieval Augmented Generation
A method where an AI system searches for relevant information and then uses that information to generate an answer.
Large Language Model
An AI model trained on large amounts of text to predict and generate human-like language.
Embedding
A numerical representation of text that helps computers compare the meanings of words, sentences, or documents.
Vector Database
A database designed to store embeddings and quickly find items with similar meanings.
Hallucination
An incorrect or unsupported answer produced by an AI system that sounds confident but is not based on reliable evidence.

Common Mistakes to Avoid

  • Thinking RAG is the same as normal web search. RAG uses retrieved information as context for a language model, while web search usually returns a list of links or results.
  • Assuming RAG makes AI answers automatically true. The answer can still be wrong if the retrieved sources are outdated, irrelevant, incomplete, or misunderstood by the model.
  • Ignoring the quality of the knowledge database. RAG works best when the database contains accurate, well-organized, and appropriate sources for the question being asked.
  • Using too much retrieved text without filtering it. Extra irrelevant context can confuse the model and make the final answer less focused or less accurate.

Practice Questions

  1. 1 A RAG system retrieves 8 documents, but only 5 are actually relevant to the student's question. What fraction and percentage of the retrieved documents are relevant?
  2. 2 A vector database returns similarity scores of 0.92, 0.81, 0.44, and 0.76 for four documents. If the system uses only documents with scores above 0.75, which documents are included and how many are used?
  3. 3 A student asks an AI chatbot for the latest school science fair rules. Explain why a RAG system connected to the school's current rule database would likely give a better answer than a language model with no retrieval.