LibraryBasic RAG Architecture

Basic RAG Architecture

Learn about Basic RAG Architecture as part of Vector Databases and RAG Systems Architecture

Understanding Basic RAG System Architectures

Retrieval-Augmented Generation (RAG) is a powerful technique that enhances the capabilities of large language models (LLMs) by grounding their responses in external knowledge. This approach combines the generative power of LLMs with the precision of information retrieval, leading to more accurate, relevant, and context-aware outputs.

Core Components of a Basic RAG System

A fundamental RAG system typically consists of three main components: a retriever, a generator, and a knowledge base. Understanding how these components interact is key to grasping RAG's effectiveness.

The Retriever finds relevant information.

The retriever's job is to search a large corpus of documents (the knowledge base) for information that is most relevant to the user's query. This is often achieved using vector embeddings and similarity search.

The retriever is the first line of defense in a RAG system. It takes a user's query, converts it into a vector representation, and then searches a pre-indexed knowledge base (often a vector database) for document chunks whose vector representations are closest to the query's vector. This process aims to identify the most pertinent pieces of information that can help answer the user's question.

The Generator uses retrieved information to create an answer.

The generator, typically an LLM, receives the user's original query along with the relevant information retrieved by the retriever. It then synthesizes this information to produce a coherent and contextually appropriate response.

Once the retriever has identified relevant document snippets, these snippets are passed to the generator, usually a large language model. The LLM is prompted to use this retrieved context to formulate its answer. This augmentation ensures that the LLM's output is not just based on its pre-trained knowledge but is also informed by specific, up-to-date, or domain-specific information.

The Knowledge Base stores the information.

The knowledge base is the repository of information that the RAG system can access. This can range from a collection of text documents to structured databases, all typically processed into a format suitable for efficient retrieval, such as vector embeddings.

The knowledge base is the foundation upon which the retriever operates. It's crucial that this knowledge base is comprehensive, accurate, and well-organized. Before being used, documents are often chunked into smaller, manageable pieces and then converted into vector embeddings. These embeddings are then stored in a vector database, which allows for fast and efficient similarity searches.

The RAG Workflow: Step-by-Step

Loading diagram...

The process begins with a user submitting a query. This query is then processed by the retriever, which searches the knowledge base for relevant information. The retrieved context is combined with the original query to form an augmented prompt. This augmented prompt is then fed into the generator (LLM), which produces the final answer.

What are the three primary components of a basic RAG system?

Retriever, Generator (LLM), and Knowledge Base.

Key Considerations for RAG Architecture

Designing an effective RAG system involves several critical decisions, including how to chunk documents, how to embed them, and how to select the best retriever and generator models.

The process of converting text into numerical representations (vectors) is called embedding. These embeddings capture the semantic meaning of the text. When a user asks a question, their query is also embedded. The retriever then finds document chunks whose embeddings are 'close' to the query's embedding in a high-dimensional space, indicating semantic similarity. This is often visualized as points in a multi-dimensional space where similar concepts are clustered together.

📚

Text-based content

Library pages focus on text content

The quality of the retrieved documents directly impacts the quality of the generated answer. Therefore, optimizing the retriever and the knowledge base is paramount.

Chunking strategy is vital: too small, and context is lost; too large, and irrelevant information dilutes the signal. Embedding models must be chosen carefully to capture the nuances of the domain. Finally, the prompt engineering for the generator plays a crucial role in how effectively it utilizes the retrieved context.

Learning Resources

Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks(paper)

This is the foundational paper that introduced the RAG concept, explaining its architecture and benefits for NLP tasks.

LangChain: Building LLM Applications(documentation)

LangChain is a popular framework for developing applications powered by language models, including robust RAG implementations.

Vector Databases Explained(blog)

Understand the role and functionality of vector databases, which are essential for efficient retrieval in RAG systems.

What is Retrieval Augmented Generation (RAG)?(documentation)

An overview from AWS explaining RAG, its components, and use cases in building intelligent applications.

Building a RAG System with LlamaIndex(documentation)

LlamaIndex is another powerful framework for building LLM applications, with detailed guides on implementing RAG.

The Illustrated Transformer(blog)

While not directly RAG, understanding the Transformer architecture is crucial as it underpins most modern LLMs used in RAG generators.

OpenAI API Documentation(documentation)

Essential documentation for using OpenAI's models, which are commonly used as generators in RAG systems.

Vector Embeddings Explained(blog)

A clear explanation of what vector embeddings are and how they are used to represent text semantically.

RAG vs. Fine-tuning: When to Use Which(blog)

This article helps differentiate RAG from fine-tuning, providing context on why RAG is often preferred for knowledge grounding.

Introduction to Vector Databases(blog)

An introductory guide to vector databases, covering their purpose, how they work, and their importance in AI applications like RAG.