DEEPCHECKS GLOSSARY

RAG Architecture

Deep learning has taken an incredible march, especially in the field of natural language processing (NLP). One of the most exciting developments is Retrieval-Augmented Generation (RAG). It is a combination of retrieval-based and generative-based models, which can be combined to produce more accurate and relevant texts.

RAG is a hybrid neural network architecture that enhances traditional text generation methods by integrating information that could be extracted from external sources. RAG retrieves relevant information from various sources without solely depending on the generative model’s internal information. This makes RAG especially useful for tasks that require accurate, up-to-date, or domain-specific information.

We will explore RAG’s core components, how it works, and why it is transforming the way AI interacts with information.

RAG Architecture

[Source:[https://medium.com/@bijit211987/designing-high-performing-rag-systems-464260b76815\]](https://medium.com/@bijit211987/designing-high-performing-rag-systems-464260b76815%5C%5D)

RAG Architecture

The RAG architecture consists of two primary components: retrieval and generation.

1. Retrieval Component

The retrieval component is the foundation of RAG’s ability to produce accurate responses. It searches through a large body of documents to find the relevant match that can support the generation process. The common model used for this purpose is dense passage retrieval (DPR). This encodes both queries and documents into dense representations that exist in the same vector space, enabling the model to quickly identify which document is most relevant to the user’s input or search criteria by calculating the similarity between the query and the document vectors.

How does this DPR work?

  • Query encoding: When a user inputs a query, such as a question or a prompt, it is transformed into a dense vector representation using an encoder. This captures the semantic meaning of the query in a high-dimensional space.
  • Passage encoding: Every document in the knowledge base is encoded into vectors. This encoding process happens offline and is stored in a way that allows the retrieval to be processed quickly once the user enters the prompt.
  • Retrieval: When the query is input, the system compares the query’s vector to all the passage vectors and retrieves the most similar passages. These are the documents that are most relevant when answering the user’s question.

2. Generative Component

Once the retrieval component identifies the relevant match, it passes it to the generative component. This generative component is based on transformer architectures like BART or GPT. This model uses the retrieved information along with the original input query to create a corrective response. This response will be a combination of the retrieved information along with a newly generated text, which is provided as the meaningful output at the end.

The generative components use two main strategies: fusion-in-decoder (FiD) and fusion-in-encoder (FiE). The generative component creates the final output based on the user’s input. In fusion management, both FiD and FiE combine the retrieved information with the user’s input to generate a coherent response. They process how the retrieved information is integrated into the generative process.

  • FiD: The retrieval and generation are kept separate. The generative model only combines the information from the retrieval documents during the decoding stage, which gives the model more flexibility to focus on the most relevant parts of each document as it generates the final response.
  • FiE: The query and the retrieved passages are fused at the beginning of the process. The encoder processes both at the same time, which can make the model more efficient, but it turns out to be less flexible in how it integrates the retrieved information.
Deepchecks For LLM EVALUATION

RAG Architecture

  • Version Comparison
  • AI-Assisted Annotations
  • CI/CD for LLMs
  • LLM Monitoring
TRY LLM EVALUATION

Technical overview

The RAG architecture operates with several important key steps, including the retrieval and generation components. Let’s look into this in detail:

  1. Query input: A user provides an input query that can be a question or a prompt, such as “What is the difference between machine learning and deep learning?”
  2. Query encoding: The input query is processed by a DPR, which transforms the query into a dense vector. This vector represents the query’s general meaning in a way that can be compared with other text in the knowledge base.
  3. Passage retrieval:
    Passage encoding: all the documents are preprocessed and encoded into dense vectors.
    Similarity search: The encoded query vector is then compared against the pre-encoded passage vectors using the similarity vectors. This comparison helps to find the passage that is more similar to the user’s query.
    Top-K retrieval: The retrieval model selects the top K most relevant passages as defined.
  4. Generative model input: The combined information is later fed into the generative model. These transformer-based models are designed to produce natural language responses based on the provided context.
  5. Generating output: The generative model later produces the response and integrates details from the various documents, providing an accurate answer.

Applications of RAG

  • Question answering systems: RAG ensures they provide accurate and up-to-date answers to user input.
  • Customer support chatbots: RAG can be implemented in chatbots to ensure that the responses are accurate and grounded in a domain base. This allows the bot to extract the latest information from sources like product manuals and customer support logs.
  • Document summarization: RAG can provide a comprehensive summary by extracting relevant information from large and multiple documents.
  • Medical domain: RAG can help generate responses based on the latest research or databases in the field of medicine, where accuracy is highly valued as a key factor.

Benefits of using RAG architecture

RAG architecture offers several benefits over traditional AI models. It ensures that the responses are grounded from external sources. Its adaptability allows the knowledge base to be easily updated with the latest information, enabling quick adaptation without extensive retraining.

RAG reduces the risk of AI hallucination, which is a common issue that models face by fabricating fake content or information. Relying on retrieved documents to provide a basis for its generated responses makes it more reliable for critical applications.

Conclusion

The RAG architecture represents a new stage in the field of NLP by combining retrieval-based and generative-based models. By integrating external information, RAG can produce highly accurate content. It addresses some major limitations of traditional generative models, such as the risk of generating inaccurate information. It has proven valuable applications, including question-answering systems, customer support, and specialized fields like medicine.

As AI continues to evolve, RAG stands out as an approach that bridges the gap between accessing vast external information and the nuanced, natural language understanding of modern artificial intelligence models.

×
Deepchecks is joining forces with Check Point Strengthening AI security – together.