<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>RAG on Jiang Yi(姜祎)'s Homepage</title><link>https://jiangyigithub.github.io/ai.github.io/categories/rag/</link><description>Recent content in RAG on Jiang Yi(姜祎)'s Homepage</description><generator>Hugo -- gohugo.io</generator><language>en</language><lastBuildDate>Wed, 08 Apr 2026 21:44:44 +0800</lastBuildDate><atom:link href="https://jiangyigithub.github.io/ai.github.io/categories/rag/index.xml" rel="self" type="application/rss+xml"/><item><title>Notes on RAG</title><link>https://jiangyigithub.github.io/ai.github.io/p/notes-on-rag/</link><pubDate>Sun, 14 Apr 2024 12:38:04 +0800</pubDate><guid>https://jiangyigithub.github.io/ai.github.io/p/notes-on-rag/</guid><description>&lt;img src="https://jiangyigithub.github.io/ai.github.io/agent_performance.png" alt="Featured image of post Notes on RAG" /&gt;&lt;h1 id="problems-of-llm"&gt;&lt;a href="#problems-of-llm" class="header-anchor"&gt;&lt;/a&gt;Problems of LLM
&lt;/h1&gt;&lt;ul&gt;
&lt;li&gt;Out of date knowledge: the model cannot gain knowledge after training&lt;/li&gt;
&lt;li&gt;Humiliation: the model may generate nonsense output&lt;/li&gt;
&lt;li&gt;Specific domain: the generalized model is difficult to adapt to specific domain&lt;/li&gt;
&lt;li&gt;Enthetic problems: the model may encounter&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id="fine-tuning"&gt;&lt;a href="#fine-tuning" class="header-anchor"&gt;&lt;/a&gt;Fine-tuning
&lt;/h1&gt;&lt;p&gt;Fine-tuning is used to improve performance of foundation model on specific tasks with the help with some supervised data&lt;/p&gt;
&lt;p&gt;Fine-tuning methods can be classified into:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Based on range of updated parameters:
&lt;ul&gt;
&lt;li&gt;Full Model fine-tuning: update the parameters of the whole model&lt;/li&gt;
&lt;li&gt;Partial fine-tuning: freeze the top layer; freeze the bottom layer&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Based on special technology:
&lt;ul&gt;
&lt;li&gt;Adapter tuning&lt;/li&gt;
&lt;li&gt;LoRA&lt;/li&gt;
&lt;li&gt;Continual Learning fine-tuning&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Based on input:
&lt;ul&gt;
&lt;li&gt;Instruction tuning&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Based on objective
&lt;ul&gt;
&lt;li&gt;Multi-task fine-tuning&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Problems of fine-tuning:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Requires task-specific labeled data, may cause overfitting and catastrophic forgetting。&lt;/li&gt;
&lt;li&gt;The generalization ability is limited, and fine-tuning are required when adapting to new tasks&lt;/li&gt;
&lt;li&gt;The performance may be destroyed after fine-tuning, for example, safety.&lt;/li&gt;
&lt;/ol&gt;
&lt;h1 id="rag"&gt;&lt;a href="#rag" class="header-anchor"&gt;&lt;/a&gt;RAG
&lt;/h1&gt;&lt;p&gt;RAG consists of three major processes of &lt;em&gt;retrieval&lt;/em&gt;, &lt;em&gt;augmentation&lt;/em&gt;, and &lt;em&gt;generation&lt;/em&gt;. The framework of RAG in LLM can be described as follows:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://jiangyigithub.github.io/ai.github.io/RAG-framework.png"
loading="lazy"
alt="RAG-framework"
&gt;&lt;/p&gt;
&lt;h2 id="retrieval"&gt;&lt;a href="#retrieval" class="header-anchor"&gt;&lt;/a&gt;Retrieval
&lt;/h2&gt;&lt;h3 id="retriever-type"&gt;&lt;a href="#retriever-type" class="header-anchor"&gt;&lt;/a&gt;Retriever type
&lt;/h3&gt;&lt;p&gt;Retrieval methods can be generally categorized into two types: sparse and dense, based on the information encoding methods.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;sparse retrieval usually relies on inverted index matching along with the raw data input, for example TF-IDF and BM25. The limitation of sparse retrieval in RAG is
&lt;ol&gt;
&lt;li&gt;its no-training nature, which makes the retrieval performance heavily rely on the quality of database construction and query generation.&lt;/li&gt;
&lt;li&gt;Moreover, such fixed term-based methods only support similarity retrieval, while cannot be adapted for other retrieval considerations demanding in LLM applications, such as the diversity&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;dense retrieval, on the contrary, embeds the query and documents into continuous vector space with certain criteria, for example, semantic similarity. Examples include BERT, Dense Passage Retriever (DPR), etc.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="retrieval-granularity"&gt;&lt;a href="#retrieval-granularity" class="header-anchor"&gt;&lt;/a&gt;Retrieval Granularity
&lt;/h3&gt;&lt;p&gt;Retrieval granularity denotes the retrieval unit in which the corpus is indexed, e.g., document, passage, token, or other levels like entity.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Chunk retrieval.&lt;/li&gt;
&lt;li&gt;Token retrieval.&lt;/li&gt;
&lt;li&gt;Entity retrieval.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="pre-retrieval-and-post-retrieval-enhancement"&gt;&lt;a href="#pre-retrieval-and-post-retrieval-enhancement" class="header-anchor"&gt;&lt;/a&gt;Pre-retrieval and Post-retrieval Enhancement
&lt;/h3&gt;&lt;p&gt;Pre-retrieval and post retrieval strategies can be added to improve the quality of the retriever.&lt;/p&gt;
&lt;p&gt;Pre-retrieval methods include:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Query rewrite. This method aims to close the gaps between the input text and the needed knowledge in retrieval, to reformulate the original question into a more conducive version to retrieve.&lt;/li&gt;
&lt;li&gt;Query augmentation. This method aims to combine the original query and the preliminary generated outputs as a new query, which is further used to retrieve relevant information from the external database&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Post-retrieval enhancement denotes the procedure to process the extracted top-k documents from the retriever before feeding them to the generator for the sake of better alignment between the retrieval and generation stages.&lt;/p&gt;
&lt;h3 id="database"&gt;&lt;a href="#database" class="header-anchor"&gt;&lt;/a&gt;Database
&lt;/h3&gt;&lt;ol&gt;
&lt;li&gt;Wikipedia&lt;/li&gt;
&lt;li&gt;Domain specific database&lt;/li&gt;
&lt;li&gt;search engine&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id="generation"&gt;&lt;a href="#generation" class="header-anchor"&gt;&lt;/a&gt;Generation
&lt;/h2&gt;&lt;ol&gt;
&lt;li&gt;Parameter-Accessible Generators (White-box). Allow parameter optimization.&lt;/li&gt;
&lt;li&gt;Parameter-Inaccessible Generators (Black-box). Focus more on retrieval and augmentation processes, trying to enhance the generator by augmenting the input with better knowledge, guidances or examples for the generation.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id="augmentation"&gt;&lt;a href="#augmentation" class="header-anchor"&gt;&lt;/a&gt;Augmentation
&lt;/h2&gt;&lt;ol&gt;
&lt;li&gt;Input layer integration&lt;/li&gt;
&lt;li&gt;Output layer integration&lt;/li&gt;
&lt;li&gt;Intermediate layer integration&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id="retrieval-frequency"&gt;&lt;a href="#retrieval-frequency" class="header-anchor"&gt;&lt;/a&gt;Retrieval Frequency
&lt;/h2&gt;&lt;p&gt;If it is necessary to retrieve? Self-RAG&lt;/p&gt;
&lt;p&gt;retrieval frequency:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;One-time.&lt;/li&gt;
&lt;li&gt;Every-n-token&lt;/li&gt;
&lt;li&gt;Every token&lt;/li&gt;
&lt;/ol&gt;
&lt;h1 id="rag-training"&gt;&lt;a href="#rag-training" class="header-anchor"&gt;&lt;/a&gt;RAG training
&lt;/h1&gt;&lt;p&gt;&lt;img src="https://jiangyigithub.github.io/ai.github.io/p/notes-on-rag/RAG-training.png"
width="1585"
height="957"
loading="lazy"
alt="RAG-training"
class="gallery-image"
data-flex-grow="165"
data-flex-basis="397px"
&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Training Free&lt;/li&gt;
&lt;li&gt;Independent training&lt;/li&gt;
&lt;li&gt;Sequential training&lt;/li&gt;
&lt;li&gt;Joint training&lt;/li&gt;
&lt;/ol&gt;
&lt;h1 id="advance-rag"&gt;&lt;a href="#advance-rag" class="header-anchor"&gt;&lt;/a&gt;Advance RAG
&lt;/h1&gt;&lt;h1 id="module-rag"&gt;&lt;a href="#module-rag" class="header-anchor"&gt;&lt;/a&gt;Module RAG
&lt;/h1&gt;&lt;h1 id="applications"&gt;&lt;a href="#applications" class="header-anchor"&gt;&lt;/a&gt;Applications
&lt;/h1&gt;&lt;ol&gt;
&lt;li&gt;NLP applications
&lt;ul&gt;
&lt;li&gt;QA systems: REALM&lt;/li&gt;
&lt;li&gt;Chatbot:&lt;/li&gt;
&lt;li&gt;Fact Verification: self-RAG&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Downstream tasks:
&lt;ul&gt;
&lt;li&gt;Recommendations&lt;/li&gt;
&lt;li&gt;Software engineering&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Domain-specific Applications
&lt;ul&gt;
&lt;li&gt;AI for science&lt;/li&gt;
&lt;li&gt;Finance: ChatDOC&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id="limitations-of-rag"&gt;&lt;a href="#limitations-of-rag" class="header-anchor"&gt;&lt;/a&gt;Limitations of RAG
&lt;/h2&gt;&lt;h1 id="long-context-window"&gt;&lt;a href="#long-context-window" class="header-anchor"&gt;&lt;/a&gt;Long Context Window
&lt;/h1&gt;&lt;p&gt;Advantages of Long Context Window:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Improve the understanding and relativity: long context window allows model to refer to more context information when generating answers.&lt;/li&gt;
&lt;li&gt;Handling complex tasks: long context window makes handling complex tasks such as writing a long article, coding&lt;/li&gt;
&lt;li&gt;Improve users&amp;rsquo; experience: the user expects the model remember the chat history and use them to interact with the user.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Disadvantages of long context window:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Only uses context once, Requires refeeding the data to use long context window.&lt;/li&gt;
&lt;li&gt;Cost expensive due to input price.&lt;/li&gt;
&lt;li&gt;Time expensive due to limit of tokens per second.&lt;/li&gt;
&lt;li&gt;Needle in HayStack experiment show that there are problems with long context window.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Advantages of RAG:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Privacy projection.&lt;/li&gt;
&lt;li&gt;Allow chunking the texts and retrieve the related information more accurately&lt;/li&gt;
&lt;li&gt;Adaptive to the size of data.&lt;/li&gt;
&lt;li&gt;Accepts multiple type of data source (multimodality).&lt;/li&gt;
&lt;li&gt;Only uses a small part of the total data, which is cheaper compared with long context window .&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;problems of RAG&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The quality of retrieval
&lt;ul&gt;
&lt;li&gt;The retrieved text cannot be aligned with the queried text.&lt;/li&gt;
&lt;li&gt;The queried text are not retrieved all.&lt;/li&gt;
&lt;li&gt;Redundancy or out-dated data may cause inaccuracy.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;the quality of response generation
&lt;ul&gt;
&lt;li&gt;Model Humiliation&lt;/li&gt;
&lt;li&gt;Irrelevance&lt;/li&gt;
&lt;li&gt;Organize the output to make it reasonable&lt;/li&gt;
&lt;li&gt;Depends on the external information&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Futures:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Trustworthy RA-LLMs&lt;/li&gt;
&lt;li&gt;Multi-lingual RA-LLMs&lt;/li&gt;
&lt;li&gt;Multi-modal RA-LLMs&lt;/li&gt;
&lt;li&gt;Quality of External Knowledge&lt;/li&gt;
&lt;/ol&gt;
&lt;h1 id="other-technologies"&gt;&lt;a href="#other-technologies" class="header-anchor"&gt;&lt;/a&gt;Other technologies
&lt;/h1&gt;&lt;ol&gt;
&lt;li&gt;Query transformations&lt;/li&gt;
&lt;li&gt;Sentence window retrieval&lt;/li&gt;
&lt;li&gt;Fusion retrieval/ hybrid search&lt;/li&gt;
&lt;li&gt;multi-document agents&lt;/li&gt;
&lt;/ol&gt;
&lt;h1 id="reference"&gt;&lt;a href="#reference" class="header-anchor"&gt;&lt;/a&gt;Reference
&lt;/h1&gt;&lt;ul&gt;
&lt;li&gt;&lt;a class="link" href="https://www.semanticscholar.org/paper/A-Survey-on-RAG-Meets-LLMs%3A-Towards-Large-Language-Ding-Fan/0576e9ab604ba4bf20cd5947f3c4a2c609ac2705" target="_blank" rel="noopener"
&gt;A Survey on RAG Meets LLMs: Towards Retrieval-Augmented Large Language Models&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description></item></channel></rss>