<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by OpenRAG on Medium]]></title>
        <description><![CDATA[Stories by OpenRAG on Medium]]></description>
        <link>https://medium.com/@OpenRAG?source=rss-52d08ad306b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*6QSsg78aOE_8mmeKSqsbrA.png</url>
            <title>Stories by OpenRAG on Medium</title>
            <link>https://medium.com/@OpenRAG?source=rss-52d08ad306b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 24 May 2026 02:29:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@OpenRAG/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[Beyond Retrieval: Ushering in a New Era of Synergy Between RAG and Reasoning]]></title>
            <link>https://medium.com/@OpenRAG/beyond-retrieval-ushering-in-a-new-era-of-synergy-between-rag-and-reasoning-a1edb499b09f?source=rss-52d08ad306b------2</link>
            <guid isPermaLink="false">https://medium.com/p/a1edb499b09f</guid>
            <category><![CDATA[rags]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[reasoning]]></category>
            <dc:creator><![CDATA[OpenRAG]]></dc:creator>
            <pubDate>Fri, 02 May 2025 18:00:42 GMT</pubDate>
            <atom:updated>2025-05-02T18:03:12.421Z</atom:updated>
            <content:encoded><![CDATA[<p>Breakthroughs in the reasoning abilities of large language models are redefining the boundaries of Retrieval-Augmented Generation (RAG) technology. How can we enable models not only to “retrieve knowledge” but also to “think like humans”? This question has sparked research into the deep integration of RAG and reasoning capabilities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w6PTZUMPpa5hhXuzQkN6Lw.png" /><figcaption>Timeline of studies on RAG-reasoning synergy</figcaption></figure><p>Recently, our team (led by Haofen Wang at Tongji University, Yun Xiong at Fudan University) released “<a href="https://arxiv.org/pdf/2504.15909">Synergizing RAG and Reasoning: A Systematic Review</a>”. It is the first work to systematically examine how to integrate RAG with reasoning, offering new insights into applying RAG to knowledge-intensive and complex tasks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FPFamcTKD_10DZB6xJKKFQ.png" /></figure><p>In the article, we focus on recent advances in deeply integrating retrieval and reasoning capabilities. Specifically, we aim to address the following key questions:</p><p>1. Why combine RAG with reasoning, and what new potential emerges from this synergy?</p><p>2. What are the collaborative patterns between RAG and reasoning? Are they pre-defined workflows or dynamic strategies, and how is the reasoning process initiated?</p><p>3. How can we realize a deep synergy between RAG and reasoning? What are the key techniques and optimization strategies involved?</p><p>4. What are the evaluation challenges and costs of such systems, and how can we balance performance with resource consumption?</p><p>5. In practical applications, how should “RAG+Reasoning” solutions be tailored to specific scenarios, and what are our recommendations and considerations?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7C7R2L7-XFiDQg338XGqRA.png" /><figcaption>Taxonomy synthesizing RAG and Reasoning</figcaption></figure><h4><strong>First, What is Reasoning?</strong></h4><p>Before diving into the synergy, it is important to clarify what we mean by “reasoning” in an AI system, especially as distinct from simple one-step “inference”. In the review, we define reasoning as “a structured, multi-step process that dynamically breaks down complex problems, generates intermediate hypotheses, and iteratively refines solutions using logic and evidence”. In other words, a reasoning-capable AI does not jump straight from a question to an answer. Instead, it breaks the problem into sub-problems, draws interim conclusions for each, and uses those to eventually reach a final answer — much like how a human would tackle a difficult question step by step. This is in contrast to a single-step inference where an AI simply produces an answer from the input in one go without that stepwise thought process.</p><p>To visualize this, imagine trying to solve a puzzle or a math problem. Rather than guessing the final answer outright, you would solve smaller parts of the puzzle and piece those solutions together. Similarly, a reasoning-enabled AI addresses parts of the question one by one and builds up the answer. This approach tends to be much more reliable for complex tasks than jumping directly to a conclusion.</p><h4><strong>What’s New in RAG+Reasoning?</strong></h4><p>Integrating reasoning into RAG yields several improvements over using retrieval alone. We identified five key upgrades:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O78SFGrEU9lbmFfPO_A0vg.png" /><figcaption>Advantages of Combining RAG with Reasoning</figcaption></figure><p><strong>1. Ambiguous Semantic Matching → Logic-Driven Targeted Retrieval</strong></p><p>Traditional RAG uses superficial semantic matching and can misinterpret queries. With reasoning, the system understands the query’s intent more deeply and retrieves exactly the information it needs, rather than just related chunks. For example, if asked “How can we reduce post-operative infection risk in diabetic patients?”, a reasoning-enhanced system might deduce it should look for evidence on “blood glucose control thresholds” and “antibiotic guidelines”, rather than naively matching keywords like “diabetes post-op care”.</p><p><strong>2. Simple Information Aggregation → Coherent Context Construction</strong></p><p>Basic RAG might dump all retrieved chunks into the prompt, risking confusion or contradiction. A reasoning-enhanced system filters and connects evidence, checks for gaps or inconsistencies, and builds a coherent context for the model. This ensures the LLM works with information that’s logically consistent.</p><p><strong>3. Simple and Single-Turn QA → Systemic Decision Support</strong></p><p>Traditional RAG performs well in factual QA but struggles with multi-step problems or decisions. Adding reasoning allows the system to break down complex tasks, perform intermediate calculations, and handle multiple constraints systematically, rather than trying to answer in one go. For example, imagine an engineering query that asks for a construction plan meeting several safety and cost requirement. A reasoning-augmented RAG can iterate through these requirements, perhaps retrieve different pieces of domain knowledge for each, and then assemble a plan that accounts for all of them.</p><p><strong>4. Indiscriminate Retrieval → Intelligent Resource Allocation</strong></p><p>A vanilla RAG often retrieves a fixed number of documents regardless of query complexity. A reasoning-aware system can adjust: it might use minimal or no retrieval for a simple question, and do multiple rounds for a complex one. This adaptive strategy means less wasted time and computational cost on easy queries, and more focus on hard ones.</p><p><strong>5. Passive knowledge Tool → Proactive Cognitive Assistant</strong></p><p>Regular RAG is reactive, as it only responds, but never asks. With reasoning integrated, the system becomes proactive. It can ask the user clarifying questions when the query is ambiguous and anticipate follow-ups. For example, if you are researching a topic, it might suggest related information or warn of potential pitfalls (like contradictory evidence) before you even ask. In effect, it turns the system into a more interactive assistant that engages in dialogue to reach a goal.</p><p>These potential enhancements show how combining retrieval with reasoning makes the system more intelligent and user-centric, going beyond just fetching facts to actually understanding and addressing the user’s needs.</p><h4><strong>Why is RAG+Reasoning Needed?</strong></h4><p>Given the enhancements above, it’s clear why combining RAG with reasoning is a good idea: each component compensates for the other’s weaknesses. Let’s spell this out more explicitly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gzxovhwCvUG074Tx_HpSSg.png" /><figcaption>The purpose of the synergy between RAG and reasoning</figcaption></figure><p><strong>• Limits of RAG alone: </strong>Lacking deep understanding of complex intents, retrieval strategies are static and struggle to adapt to multi-step reasoning, making it difficult to efficiently balance accuracy and speed, and they are inadequate in integrating multimodal and dynamic knowledge.</p><p><strong>• Challenges of reasoning alone: </strong>The reasoning space is vast, making it easy to fall into local optima; there is a lack of effective external knowledge verification mechanisms and intermediate state supervision, resulting in poor transparency and high computational resource consumption.</p><p>The idea of combining RAG with reasoning is to let each cover the other’s blind spots. We emphasize two <strong>synergy purposes</strong>:</p><p><strong>• Reasoning-Augmented Retrieval (RAR):</strong> Use reasoning to make retrieval smarter and more iterative. The system can clarify the query and fetch information step by step. For instance, it might break a query into parts, search for each part separately, or reformulate the question if the first try wasn’t clear. Reasoning helps the system decide what to search for next. The result is that it finds the right facts more reliably and uses fewer unnecessary steps.</p><p>• <strong>Retrieval-Augmented Reasoning (ReAR):</strong> Use retrieval to make reasoning more grounded and accurate. Here, even when the model is reasoning through a problem, it continually pulls in real-world evidence to support each step. This keeps the model from hallucinating or missing knowledge. With the relevant facts at hand during its chain-of-thought, the AI’s reasoning stays on track and the final answers are much more trustworthy, which is crucial for tackling really hard problems where pure reasoning might falter.</p><h4><strong>What are the Patterns of Synergy?</strong></h4><p>If we agree that RAG and reasoning belong together, the next question is how to combine them. There are two common ways to organize the interplay between retrieval and reasoning: pre-defined workflow and dynamic workflow. Each approach has advantages in different situations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3DCuOR1XACmaUPOnjiFwjg.png" /><figcaption>Patterns of Synergy between RAG and Reasoning</figcaption></figure><p><strong>Pre-defined workflow:</strong> This is a structured, deterministic integration. In a pre-defined workflow, the system follows a fixed sequence of steps, interleaving retrieval and reasoning in a predetermined order. You can think of it like a pipeline with a clear architecture: for example, “Step 1: break query into sub-queries → Step 2: retrieve documents for each sub-query → Step 3: reason over the collected info → Step 4: generate answer.” All the stages and their order are set ahead of time. This kind of workflow emphasizes controllability and transparency. This works well if you know the task structure in advance and can split the problem into sub-tasks.</p><p>Specifically, the pre- defined workflow pattern can be further divided into the following three types:</p><ul><li><strong>Pre-retrieval reasoning</strong>: Decompose complex problems before retrieval (e.g., business rule extraction in PlanRAG).</li><li>P<strong>ost-retrieval reasoning</strong>: Perform logical verification and knowledge integration on retrieved results (e.g., conflict resolution mechanism in ActiveRAG).</li><li><strong>Hybrid mode</strong>: Iterative “retrieve–reason–retrieve again” cycles (e.g., generation feedback optimization in ITER-RETGEN).</li></ul><p><strong>Dynamic workflow:</strong> This is a flexible, adaptive integration. In a dynamic workflow, the sequence of retrieval and reasoning steps is not fixed in advance; instead, the system decides on the fly what to do next based on the current context. Think of this like an agent that observes its own intermediate reasoning state and can say, “I need to fetch another piece of data now,” or “I should perform a verification at this point,” or even “I’ve done enough, time to finalize the answer.” There is a kind of real-time decision engine in the loop. This approach relies heavily on the LLM’s ability to self-monitor and control its actions, often implemented via special trigger tokens or internal policies. This is powerful for tackling very complex or unpredictable queries, but it is also more complex to design and can be harder to predict or debug.</p><p>Specifically, the dynamic workflow pattern can be further divided into the following three types:</p><ul><li><strong>Proactive-driven</strong>: The LLM actively triggers retrieval (e.g., real-time API calls in Agentic Reasoning).</li><li><strong>Reflective-driven</strong>: The system adjusts strategies based on self-assessment of intermediate results (e.g., confidence threshold control in Self-RAG).</li><li><strong>Feedback-driven</strong>: External reward models guide optimization (e.g., multi-dimensional process supervision in RAG-Gym).</li></ul><p>In practice, both patterns have their place. Pre-defined workflows excel when the problem type is well understood and consistency is key. Dynamic workflows shine in open-ended scenarios where the system needs maximum flexibility. Often, a solution might combine elements of both. For instance, mostly following a dynamic approach but with a bit of structured guidance for critical steps, or vice versa. The right choice depends on the use case and the desired balance between reliability and adaptability.</p><h4><strong>How to Implement and Optimize “RAG+Reasoning”?</strong></h4><p>Building a well-oiled “RAG+Reasoning” system involves two parts: embedding reasoning capabilities into the pipeline and optimizing the combined process for performance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GYbdu6BVKDnDuPFb91x5Eg.png" /><figcaption>Implementation and optimization of the synergy between RAG and Reasoning</figcaption></figure><p>For reasoning process, researchers have explored methods such as:</p><p>• <strong>Chain-of-Thought (CoT):</strong> This refers to prompting or training the LLM to generate explicit step-by-step reasoning before giving a final answer. By structuring the model’s internal thought process into a logical sequence, it enables multi-step problem solving in a transparent way.</p><p>• <strong>Special Token Prediction:</strong> Another clever technique is training the model to output special “signal” tokens that act as commands, telling the system to perform some action (like retrieval). This method allows fine-grained, interpretable control within a single unified model output. It’s like giving the model a remote control over the retrieval mechanism through its own text output. Many recent systems (like Self-RAG, SmartRAG, etc.) use this approach, effectively turning the LLM into an agent that writes its own toolkit instructions mid-generation.</p><p><strong>Search-Driven Reasoning:</strong> This set of techniques explicitly marries search algorithms with the reasoning process. The idea is to use structured search strategies (like tree search or even Monte Carlo Tree Search) to explore different reasoning paths or hypotheses in a systematic way. This approach can be especially powerful for tasks like complex question answering or planning, where one might need to consider many possible routes.</p><p><strong>Reasoning on Graph:</strong> In many situations, knowledge is better represented as a graph (nodes and relationships) than as unstructured text. Graph-based reasoning methods leverage this by explicitly constructing or utilizing knowledge graphs during the reasoning process. For example, if trying to answer a question that requires understanding relationships between several entities, the system can traverse a knowledge graph to find the links. This approach enables multi-hop reasoning with clear semantics, as the graph structure ensures that each hop is a well-defined relation (like “X is a subtype of Y” or “A causes B”).</p><p><strong>External Solver:</strong> Sometimes the “reasoning” needed isn’t purely logical deduction but rather a precise computational problem, such as solving an equation, running an optimization, or executing code. In these cases, an effective strategy is to integrate specialized external solvers into the workflow. For example, the model might delegate a math calculation to a calculator, then use the result in its reasoning. This extends the system’s capabilities beyond what the LLM alone can do.</p><p>On the optimization side, key strategies include:</p><p><strong>Prompt-Based</strong> <strong>Optimization:</strong> Prompt-based optimization boosts RAG and reasoning performance by using well-crafted language prompts to structure tasks, standardize results, and enable interactive adaptability — without changing model parameters. By decomposing reasoning into clear steps and leveraging role assignments, explicit output formats, and interactive tokens or instructions, prompts improve interpretability, reduce hallucinations, and allow dynamic adjustments during execution. This strategy enhances consistency, coherence, and external knowledge integration, outperforming traditional methods in complex scenarios. Its general, lightweight, and non-intrusive nature makes prompt-based optimization an effective foundation and mainstream approach for LLM reasoning, enabling robust task control and laying the groundwork for future hybrid methods.</p><p><strong>Tuning-Based</strong> <strong>Optimization:</strong> This approach updates the model’s parameters through training (fine-tuning) so that it better handles the intertwined retrieval-reasoning task. Methods like CoRAG and DeepRAG fine-tune models for better retrieval paths and reasoning steps, while systems such as MCTS-KBQA and Self-RAG target structured outputs by training for precise control tokens and executable tool instructions. Other frameworks like O1-Embedder and Open-RAG use mixed fine-tuning and specialized modules for enhanced semantics and multi-hop capabilities. Collaborative strategies, typified by AdaptiveRAG and CR-Planner, use lightweight classifiers and critics to dynamically adjust retrieval strategies and assess reasoning quality. Overall, these approaches optimize models for efficient, accurate retrieval-reasoning, boosting performance across various complex tasks.</p><p><strong>Reinforcement Learning (RL)-Based Optimization:</strong> RL has become crucial for enhancingRAG and reasoning tasks, providing flexible reward mechanisms that help language models balance knowledge retrieval and logical reasoning. RL optimization typically follows either outcome-based reward modeling (ORM), which focuses on final answer quality (e.g., R1-Searcher and KBQA-O1), or process-based reward modeling (PRM), which supervises intermediate reasoning steps (e.g., LeReT and ReARTeR). Recently, methods like GRPO — an efficient Proximal Policy Optimization (PPO) variant — have improved retrieval quality and enabled retry mechanisms, simulating persistent search behavior in LLMs.</p><p>Hybrid approaches combine ORM and PRM via composite rewards, as seen in SmartRAG and RAG-Gym, optimizing both overall output and stepwise reasoning, thereby reducing retrieval costs while maintaining performance. Academic research often explores such RL-based methods using small-scale LLMs like Qwen and Llama. Overall, RL frameworks in RAG promote both global strategy optimization and local robustness, paving the way for future advances in multi-agent, offline RL, and more granular reward structures in open-domain reasoning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ERvPmTkuIno2h-hRSv4p3A.png" /></figure><p>By mixing the right techniques with smart optimization, we can build systems that not only reason and retrieve, but do so efficiently and coherently. The next question is: how do we know it is working well? That’s where evaluation comes in.</p><h4><strong>Downstream Evaluation Tasks</strong></h4><p>So far, the progress in RAG+Reasoning is often measured on tasks like multi-hop question answering, where the AI must gather and connect information from multiple sources to answer a question. Systems that combine retrieval and reasoning have been pushing the state-of-the-art on benchmarks such as HotpotQA and 2WikiMultihopQA, which test exactly those multi-step reasoning capabilities.</p><p>However, standard benchmarks only scratch the surface of what we want these systems to do. They usually check if the final answer is correct, but they do not evaluate how the AI arrived there. Did it reason properly through each step? Did it use evidence correctly? There is a growing sense that we need new ways to evaluate reasoning chains and ensure an AI’s process is sound, not just the end result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a-bL30TYuBPM20MXWTwSfA.png" /><figcaption>The current downstream tasks and datasets re-<br>lated to the combination of RAG and Reasoning</figcaption></figure><p>On the horizon are more ambitious tasks that really showcase why RAG+Reasoning is valuable. We categorize some of the representative evaluation scenarios as follows:</p><p><strong>Deep Research Tasks:</strong> These are extremely complex, open-ended information seeking tasks. It is the kind you might associate with doing research rather than answering a single question. For example, the system might be asked to investigate a scientific hypothesis, analyze a historical event with multiple sources, or compile a report on a broad topic. RAG+Reasoning systems have shown significant improvements on these tasks, as they can manage the breadth and depth required better than either alone.</p><p>• <strong>PhD(Expert)-Level Complex Reasoning Tasks:</strong> These tasks are designed to mimic what a human expert (like a PhD-level person) might do, often within a specialized domain. They require advanced domain knowledge plus complex reasoning. For instance, a medical diagnosis task where the AI must reason through symptoms and tests, or a legal analysis task where it must interpret laws and precedents. These tasks demand not only retrieving the relevant domain knowledge (e.g. clinical guidelines, legal clauses) but also applying it with rigorous logical consistency and depth of reasoning.</p><p>To support the evaluation of the above, researchers have also developed benchmarks and datasets that capture these challenges. For example, WildSeek is a dataset mentioned in our review which is built from multi-domain “deep research” queries requiring multi-hop reasoning and tool use. Another work introduced a PhD-level exam dataset covering finance, medicine, and law, to test expert-level reasoning under time constraints . These new benchmarks go far beyond trivia QA; they are explicitly constructed to require the kind of retrieval+reasoning synergy we’ve been discussing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9eB-eHFkqIxGl37WhrF1Yg.png" /></figure><p>Looking forward, several challenges remain. One is managing dynamic, real-time information, making sure the AI can reason with fresh data that changes frequently (like news or live sensor data). Another is incorporating deep domain expertise safely and effectively, so the AI can handle specialized fields like medicine or law with the necessary rigor. As our reasoning chains get longer and more complex, issues of traceability and debugging become critical; we need better ways to watch the AI’s thought process and intervene if it goes astray. Finally, as these systems become more autonomous, ensuring safety and alignment with human values will be an ongoing concern. Solving these will be key to the next generation of robust RAG+Reasoning systems.</p><h4><strong>Hidden Costs: The “Invisible Tax” of Reasoning</strong></h4><p>We find that integrating reasoning into RAG systems comes with an overlooked cost — an “invisible tax” on resources and speed. A basic LLM is quick and efficient but limited to its training data; adding RAG expands its knowledge but introduces extra processing, storage, and token overhead. Adding multi-step reasoning further increases latency, token use, and complexity, while introducing new security and reliability risks. In fact, each extra reasoning step can make computational load and token usage skyrocket , while repeated retrievals yield diminishing returns . Because these hidden costs are easy to underestimate, we advocate for fine-grained <strong>Cost Models</strong> to quantify trade-offs and guide design choices.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F_CDFd-OfsqYVi5ap2zDpw.png" /><figcaption>From LLM to RAG and then to RAG+Reasoning, performance improvement comes with additional cost.</figcaption></figure><p><strong>Non-Linear Growth of Computational Resources. </strong>RAG+Reasoning splits retrieval and reasoning into stages, causing superlinear growth in computational demand. Each extra reasoning or retrieval step greatly increases complexity. Methods like MCTS or multi-step planning drive up GPU runtime and memory compared to linear approaches. Though they improve accuracy, resource needs escalate sharply with model size and task complexity, presenting scalability challenges.</p><p><strong>Implicit Token Inflation. </strong>Multi-step reasoning inflates token usage through intermediate thoughts, documents, and feedback. Active learning and chain-based methods produce more tokens by combining various results and exploring paths. These demands grow quickly with complex tasks, deep or broad reasoning, and long outputs, raising both API costs and memory use.</p><p><strong>Marginal Decline in Retrieval Efficiency</strong>. Dynamic retrieval aids precision but loses efficiency as tasks become complex. While adaptive retrieval helps on simple tasks, complex ones require repeated iterations, increasing overhead. Advanced retrievals improve quality but cost more, and optimizations can’t eliminate extra training and runtime overhead, challenging the balance between accuracy and efficiency.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ODlEWCPoKueU24PWwhKoqA.png" /><figcaption>Cost quadrant diagram of retrieval and reasoning requirements</figcaption></figure><p><strong>Toward a Cost Model Framework. </strong>Fine-grained cost models are needed to balance accuracy and efficiency, since current single-task metrics miss the joint impact of computation, tokens, and retrieval. Without such models, true tradeoffs in reasoning frameworks go unmeasured, as accuracy gains may be offset by rapid cost and latency increases. Detailed cost modeling is key to realistically assessing reasoning-based approaches.</p><h4><strong>Practical Guide on RAG+Reasoning</strong></h4><p>Finally, to help practitioners and researchers apply the findings of our review, we compiled a Practical Guide with recommendations on tailoring “RAG + Reasoning” solutions to different scenarios.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fTQ6eI_mNNAC467dD-ujlA.png" /><figcaption>Practical guide to synergizing RAG and Reasoning</figcaption></figure><ol><li><strong>Industry Scenario Considerations</strong></li></ol><p>We recommend first understanding the nature of the tasks in your domain along the three core stages of an information-seeking pipeline: Query, Retrieval, and Generation. Different industries place different demands on each stage.</p><p><strong>Query Stage:</strong> How complex or implicit are user queries? In some domains like law or finance, questions can be layered and require a lot of interpretation. For example, in finance, a query might implicitly ask for reasoning about market conditions, so the system needs to parse that and possibly reformulate specific sub-queries. That is, preserving the original intent and nuances through the reasoning process (without misinterpreting) is essential for good results.</p><p><strong>Retrieval Stage:</strong> Look at the nature of knowledge sources in your domain. Are they static or rapidly changing? Are they homogeneous (all similar type of documents) or heterogeneous (mix of text, databases, etc.)? Domains with frequently updating information (like news or real-time data) demand a RAG system that is adaptable and can incorporate updates seamlessly. This might involve special indexing strategies (e.g., cold-hot tiered indexing where frequently needed info is quickly accessible) and reasoning methods that can decide when to fetch new data.</p><p><strong>Generation Stage:</strong> What does a “good” answer look like? In casual settings, it can be concise and just correct enough. In critical fields (medical, legal), it needs to be comprehensive, correct, and come with explanations or citations. Also consider latency: do users need answers instantly, or is a short wait acceptable for a better answer? Ensuring the output is trustworthy and clear is especially important in professional settings.</p><p><strong>2. Design Principles and Pitfalls</strong></p><p>Task-specific design guidelines should be established to define clear operational boundaries. For example:</p><p>In predictive tasks, decomposition into sub-tasks and constraint-based generation using structured knowledge (e.g., knowledge graphs) is recommended to avoid unverifiable reasoning jumps.</p><p>In dynamic environments, prioritize lightweight retrieval caching and prompt-based adaptation over prolonged fine-tuning to reduce system latency and maintain agility.</p><p>In high-risk domains, implement multi-layer verification pipelines and rule-based filters to safeguard decision quality, and strictly prohibit autonomous execution of critical decisions without human oversight.</p><p><strong>3. Opportunity Points:</strong></p><p>Our review also highlights some exciting opportunities for pushing “RAG+Reasoning” further. Here are two examples:</p><p><strong>• Cold-hot Tiered Indexing and Dynamic Context Management:</strong> Developing smarter retrieval indexing that separates “hot” frequently-used information from “cold” long-tail info, and dynamically managing what context the model sees. This can speed up retrieval and help the reasoning module focus on relevant knowledge by prioritizing likely useful info while still allowing access to the long tail when needed.</p><p><strong>• Fine-Grained Layering and Confidence Grading:</strong> Creating multi-layer models or workflows where easier subtasks are handled by a simpler (faster) layer and more complex reasoning kicks in only when needed. Also, having the system self-grade its confidence at each reasoning step. If confidence is low, perhaps branch out or retrieve more information. This could optimize the effort spent on each query and ensure that uncertain reasoning is caught and addressed.</p><p><strong>Conclusion</strong></p><p>The synergy of RAG and reasoning is ushering in a new generation of AI assistants that are both knowledgeable and thoughtful. Our team’s review provides a foundation and a roadmap for developing these next-gen systems, and we are excited about what’s on the horizon. The synergy between RAG and reasoning is advancing rapidly, showing huge potential in academia and industry alike, that is, from more insightful financial analytics and smarter healthcare support, to more reliable intelligent personal assistants.</p><p>Looking ahead, there are plenty of research avenues to explore. Promising directions include graph-based knowledge integration (to connect and reason over structured information), coordinated reasoning across modalities (so AIs can seamlessly combine text, images, and more in their thinking), and applying advanced methods like reinforcement learning to further refine how retrieval and reasoning work together. With careful research and engineering, we expect future systems will not only be more powerful in tackling complex tasks, but also more transparent and trustworthy in how they do it. In short, the future looks bright for “RAG+Reasoning”, and we are looking forward to seeing (and contributing to) the innovations to come.</p><h4><strong>Resource</strong></h4><p><strong>Full Paper</strong>: <a href="https://arxiv.org/abs/2504.15909">Synergizing RAG and Reasoning: A Systematic Review</a> (arxiv:2504.15909).</p><p><strong>Figure : </strong>All of our Figures (Except for that Sankey charts) are created using Figma. Many thanks to @Yuxi BI for the excellent work.</p><p>You are welcome to use the figures from our paper as long as you provide appropriate attribution and citation.</p><p><strong>Paper List</strong>: As before, for more related resources and a collection of relevant papers, please visit the OpenRAG platform: <a href="https://openrag.notion.site/open-rag-base?pvs=4">OpenRAG.</a><br>It is a paper knowledge base built on Notion. Our original intention in creating this was to help everyone quickly find and compare relevant papers of interest through multi-dimensional attributes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R10medLwI-iOlwJ2QgjSfw.png" /><figcaption>Paper List in OpenRAG</figcaption></figure><p><strong>Citation</strong></p><p>If you found our work useful, a citation would be greatly appreciated. Thanks so much!</p><pre>@article{gao2025synergizing,<br>  title={Synergizing RAG and Reasoning: A Systematic Review},<br>  author={Gao, Yunfan and Xiong, Yun and Zhong, Yijie and Bi, Yuxi and Xue, Ming and Wang, Haofen},<br>  journal={arXiv preprint arXiv:2504.15909},<br>  year={2025}<br>}</pre><p><strong>Contact Us</strong></p><ul><li>Yunfan Gao (First author &amp; blog author) : <a href="http://gaoyunfan1602@gmail.com">gaoyunfan1602@gmail.com</a></li><li>Hofen Wang (PI of the lab, Tongji University): <a href="http://carter.whfcarter@gmail.com">carter.whfcarter@gmail.com</a></li><li>Yun Xiong (PI of the lab, Fudan University): <a href="mailto:yunx@fudan.edu.cn">yunx@fudan.edu.cn</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a1edb499b09f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[KaLM-Embedding: Reshaping Multilingual Text Embedding Models]]></title>
            <link>https://medium.com/@OpenRAG/kalm-embedding-reshaping-multilingual-text-embedding-models-cc4cee591e64?source=rss-52d08ad306b------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc4cee591e64</guid>
            <dc:creator><![CDATA[OpenRAG]]></dc:creator>
            <pubDate>Mon, 20 Jan 2025 10:22:11 GMT</pubDate>
            <atom:updated>2025-01-20T10:22:11.876Z</atom:updated>
            <content:encoded><![CDATA[<h3>1. Introduction</h3><p>In the era of rapid development of large language models (LLMs), retrieval-augmented generation (RAG) has become a key approach for enhancing model performance. However, with the widespread adoption of the RAG framework, text embedding models have increasingly become a bottleneck hindering further progress. Traditional embedding models often perform inadequately in multilingual and multi-domain tasks due to the poor quality of training data. To address this challenge, we introduce the KaLM-Embedding (Knowledge in large Language Models into Embedding) model, which outperforms other models of similar scale in multilingual capabilities, as demonstrated in the MTEB (Massive Text Embedding Benchmark) evaluation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*96TctKj51ahad91vhJhUCA.jpeg" /></figure><h3>2. KaLM-Embedding: Innovative Training Methods for Superior Multilingual Models</h3><h3>(1) Data Collection: The Foundation of Model Success</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lYhXn5U0pBL-vW2PFxCxLA.png" /></figure><p>During the development of the KaLM-Embedding model, we meticulously designed a data collection strategy to ensure the model excels in multilingual and multi-domain tasks.</p><h3>Large-Scale Open Source Datasets: A Combination of Diversity and Quality</h3><ul><li><strong>Pre-training Data</strong>: During the contrastive pre-training phase, large-scale weakly-supervised pairs data is introduced to transform the original language model into an embedding model, enabling it to acquire preliminary text embedding capabilities, which lays the foundation for subsequent fine-tuning. We utilized title-body pairs from various documents as well as symmetric translation sentence pairs, supplemented with a portion of large-scale supervised question-answer datasets to ensure the diversity and coverage of the data.</li><li><strong>Fine-tuning Data</strong>: During the fine-tuning phase, we introduced over 70 high-quality datasets from different sources. These datasets are diverse and of high quality, providing ideal conditions for the model’s fine-tuning despite their smaller size. We also incorporated multiple classification and clustering datasets, treating each (sentence, category label) pair as a training instance. Additionally, we sampled hard negative examples from all classification datasets to mitigate the issue of insufficient label categories in some datasets. For each specific dataset, we conducted meticulous processing, such as filtering out overly short documents or excluding low-quality parts based on metadata.</li><li><strong>Data Purity</strong>: To ensure data purity, we only used the training sets of all datasets, explicitly excluding any test sets. For datasets without separate training and test sets, we first filtered out test set samples included in MTEB and then processed the remaining data. This strategy ensures that all examples appearing in MTEB evaluations were not seen by the model during training.</li></ul><p>Despite the fine-tuning data being primarily in Chinese and English, with only a small amount of multilingual data, the model’s performance in other languages remains satisfactory, indicating that the multilingual advantages of pre-trained LLMs can be successfully transferred to embedding models.</p><h3>Persona-Based Synthetic Data: Enhancing Data Diversity and Domain Coverage</h3><p>We generated 550,000 high-quality synthetic data entries using Qwen2–72B-Instruct, covering six task types and 40,000 unique instructions. To enhance data diversity, we introduced random persona from Persona Hub as system prompts, effectively increasing the domain diversity of the generated data. Since four retrieval tasks require instruction generation before data generation, we only introduced persona during the instruction generation phase to avoid persona conflicts between the two stages.</p><h3>(2) Training Strategies: Key to Optimizing Model Performance</h3><h3>Ranking Consistency Filtering: Precise Sample Selection</h3><p>In addition to using in-batch negative samples, we also retrieved hard negative samples from the dataset’s corpus. However, some queries may correspond to multiple correct documents or answers, or be too broad, leading to associations with multiple documents despite low relevance. These situations can introduce false negative samples, adversely affecting model optimization.</p><p>To address this issue, we adopted the <strong>ranking consistency filtering</strong> method (top-k filtering), ranking the similarity of queries with their original positive sample data across the entire document corpus and filtering out samples not ranked in the top k. This process is conducted simultaneously with hard negative sample mining to avoid redundant calculations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0LSStsQMPPUt-5SJ3sPPcA.jpeg" /></figure><h3>Semi-Homogeneous Task Batching: Balancing Difficulty and Risk</h3><p>Previous research adopted the <strong>homogeneous task batching</strong> method, where each batch contains samples from a single task to increase the difficulty of in-batch negative samples. However, this also introduces the risk of containing too many false negative samples.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3NEj8SW5sNVf4FgfW8qqvw.jpeg" /></figure><p>We introduced the concept of <strong>semi-homogeneous task batching</strong>, first constructing a complete homogeneous task batch, then sampling, mixing, and randomly reassigning a specified proportion of samples back to the original batch to balance the difficulty of negative samples and the risk of false negatives. However, this method was not used in our latest model but provided a controllable means of analysis.</p><h3>Matryoshka Representation Learning: Achieving Flexible Dimensional Embeddings</h3><p>We employ <strong>Matryoshka Representation Learning (MRL)</strong> for training, setting different vector dimensions such as 896, 512, 256, 128, and 64 to enable flexible selection of encoding dimensions. In scenarios where richer semantic representation is required and high performance is pursued, larger-dimensional vectors can be chosen; whereas in cases where retrieval efficiency is prioritized or the text semantics are simpler, smaller-dimensional vectors are more practical.</p><h3>Task Instructions: Enhancing Model Understanding and Generalization</h3><p>Task instructions can significantly improve the performance of embedding models by reducing ambiguities between different tasks in the embedding space. During training, we prepend instruction prefixes to queries from open-source data and adopt a similar setup during testing. For synthetic data, we retained the originally generated instructions, covering various retrieval tasks. In practical applications, it is recommended to customize task instructions based on specific scenarios and requirements. Given that our model has been trained on a large number of synthetic instructions, it demonstrates strong capabilities in understanding and generalizing instructions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hpe6FCNTPm40YzefAMecBw.png" /></figure><h3>3. Experimental Results: Robust Multilingual Performance</h3><p>We selected MTEB (Massive Text Embedding Benchmark) as the primary evaluation and analysis dataset due to its coverage of diverse task types and a wide range of datasets. Although our main optimization targets are Chinese (zh) and English (en), we also evaluated the model on French (fr) and Polish (pl). Our KaLM-embedding-mini-instruct model demonstrated significantly superior overall performance across multiple languages compared to other models. However, its performance on Polish was relatively weaker, which may be attributed to the lower proportion of Polish data in the training set, particularly the language distribution bias in synthetic data. The specific results are as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8iWFoW13BpRZxYAw2RfnuA.png" /></figure><p>We conducted ablation experiments on training strategies and data selection. Due to the small weight assigned to low-dimensional Matryoshka embeddings during training, the impact of Matryoshka representation learning on the final results was minimal. The influence of task instructions was particularly significant, especially considering the mix of various types of training data we used. Data selection had a more pronounced improvement effect on English than on Chinese, which may be due to the fact that the English evaluation included more out-of-domain data, making the enhancement of generalization ability through data selection more noticeable in English. Additionally, in contrast to other models, our pretraining had a smaller impact on the final results, which may be attributed to the broader and cleaner nature of our fine-tuning data. The specific results are as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7NUv1qVVFryC9rPJxN9cKw.png" /></figure><h3>4. Conclusion and Future Directions</h3><p>The success of the KaLM-Embedding model demonstrates the crucial role of <strong>high-quality data</strong> in enhancing model performance. The research team has open-sourced the model for use by researchers and developers, aiming to promote the development of multilingual embedding technologies.</p><p>Future research directions:</p><ol><li><strong>Long-text Embedding Representation</strong>: Due to the complexity and diversity of long-text information, a single vector representation may lead to information loss and perform worse than sparse representation methods. Effective representation of long texts may require the use of multiple vectors or dynamic-dimensional vectors. As the context length in language models continues to increase, how to train an effective long-text embedding model remains a challenge to address.</li><li><strong>Model Merging</strong>: Model merging, as an application of multi-task learning, faces conflicts and differences between tasks. In our experimental experience, the performance of merged models may significantly decline, and task-type differences are the primary reason for poor merging results. How to effectively integrate embeddings in a multi-task model is an area worth exploring.</li><li><strong>Model Architecture Innovation</strong>: The impact of different base models and pooling methods on model performance requires further in-depth research. While different methods show consistency in performance, the practical differences are not significant. High-quality data and training strategies remain key to pushing the performance limits of models, and innovative model architecture design will be an important research direction in the future.</li><li><strong>Adaptive Instructions</strong>: Current task instructions still require manual design and selection based on specific tasks. Whether it is possible to generate instructions adaptively and automatically select task-relevant instructions during inference to optimize performance is a direction worth further investigation. Additionally, in embedding models, it may be valuable to explore the use of continuous, non-discrete vectors as instructions for different tasks, which could further enhance task adaptability and performance.</li></ol><p>Open Source Links:</p><ul><li>Model: <a href="https://huggingface.co/collections/HIT-TMG/kalm-embedding-67316afa4c56f4fc1f58764b">https://huggingface.co/collections/HIT-TMG/kalm-embedding-67316afa4c56f4fc1f58764b</a></li><li>Code: <a href="https://github.com/HITsz-TMG/KaLM-Embedding">https://github.com/HITsz-TMG/KaLM-Embedding</a></li><li>Report: <a href="https://arxiv.org/abs/2501.01028">https://arxiv.org/abs/2501.01028</a></li></ul><p>Follow us to learn more about the latest developments and application cases of the KaLM-Embedding model!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc4cee591e64" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OpenRAG Base: Your individual RAG Knowledge Base]]></title>
            <link>https://medium.com/@OpenRAG/openrag-base-your-individual-rag-knowledge-base-7b4f34208d09?source=rss-52d08ad306b------2</link>
            <guid isPermaLink="false">https://medium.com/p/7b4f34208d09</guid>
            <category><![CDATA[retrieval-generation]]></category>
            <category><![CDATA[retrieval-augmented]]></category>
            <category><![CDATA[large-language-models]]></category>
            <category><![CDATA[retrieval-augmented-gen]]></category>
            <category><![CDATA[rags]]></category>
            <dc:creator><![CDATA[OpenRAG]]></dc:creator>
            <pubDate>Wed, 03 Apr 2024 10:06:18 GMT</pubDate>
            <atom:updated>2024-04-03T10:06:18.313Z</atom:updated>
            <content:encoded><![CDATA[<p>We’re officially launching the RAG Knowledge Base: OpenRAG Base 🎉✨</p><p><a href="https://openrag.notion.site/Open-RAG-c41b2a4dcdea4527a7c1cd998e763595"><strong>Check the Website </strong></a><strong>!</strong></p><h3>What is ?</h3><p>Open RAG Knowledge Base is a <strong>Notion</strong> repository of RAG knowledge that is built upon the collection, organization, and aggregation of publicly available resource. <strong>Maybe the most comprehensive source for RAG information at present🧐</strong>. Including:</p><ul><li>Academic Paper</li><li>Cutting Edge Readings</li><li>Benchmark and Evaluation</li><li>RAG Scholar and Institution</li><li>Downstream tasks and Dataset</li><li>Toolkit</li><li>…. More content coming soon.(e.g. seminar, baseline, cookbook)</li></ul><p>Although more focused on academic research, whether you are just getting started with RAG, are a RAG-related researcher, or are a practitioner, I believe you can benefit from it.</p><p>Based on this repository, you have a highly flexible and dynamically updated survey, and it can support <strong>highly customizable analysis and summarization .</strong> For example, if you want to see which papers have open-sourced code, which conferences these papers were published in, which papers used the same dataset, in order to quickly compare them.</p><blockquote>💡 <strong>With OpenRAG Base, you will have a RAG knowledge base tailored exclusively for you.</strong></blockquote><p><em>We will continue to update this project</em></p><h3>Why do this ?</h3><p>The current conventional practice for organizing survey papers is to list relevant papers through Readme on Github (we used to do this before as well ).</p><p>However, we find this to be a relatively inefficient and non-intuitive method, including the following points:</p><ul><li>The content is fixed, and users cannot quickly find the corresponding content according to their own needs.</li><li>The waterfall display makes the page too long and looks very redundant.</li><li>It is relatively difficult to update.</li><li>User comments and other interactive methods are more cumbersome.</li><li>Only data collection, lacking analysis and summary.</li><li>Each user sees the same content, unable to provide personalized services.</li></ul><blockquote>💡 <strong>We hope to have a more flexible and intuitive platform that helps users analyze and grasp technological developments, rather than simply stacking up materials.</strong></blockquote><p>So… ultimately…. we chose Notion.</p><h3>How to Use ?</h3><p>If you haven’t used Notion before, that’s okay, it’s very easy to operate (See <a href="https://www.notion.so/">Official Tutorial</a>).</p><p>The entire knowledge base consists of multiple Notion Databases, with linked relation between the Databases</p><p>Click on a specific Database in the Database List on the homepage to view detailed content.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RYb1HX4QC-9u35Pc1iV2Gg.png" /></figure><p>Below, we will introduce each Database individually:</p><blockquote><strong>💡 Note: When browsing online, you can only view static pages and cannot make modifications. You need to copy to your local in order to make changes.</strong></blockquote><blockquote><strong>1.</strong>Click “Duplicate” in the top right corner of the homepage (you need to be logged in to Notion).</blockquote><blockquote>2.You can duplicate the entire project or a single page (when duplicating a single page, data associated with other databases will not be displayed).</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*njW1IKerVcV_sajxHxNR8Q.png" /><figcaption>Copy the entire project into your Notion, where you can make any modifications to it. Copying a single page again will synchronize that page with ours.</figcaption></figure><h4>Academic_Paper</h4><p>This is the main page, which contains academic papers on RAG under the context of large models. We will use this Database as a case study to detail several common methods of using OpenRAG Base.</p><ol><li><strong>Overview</strong></li></ol><p>Each row represents a paper on RAG, and we have designed over ten properties to help with analysis and summarization, with the paper’s abbreviation serving as the primary key. (<a href="https://www.notion.so/help/database-properties"><em>See the concept of Notion DatabaseProperty</em></a><em>)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dyenvd12WdOTyj-sSKG_Qw.png" /><figcaption>The main page of Academic Papers.</figcaption></figure><p><strong>2. Common operations</strong></p><ul><li>The control area is located in the upper right corner, where you can filter, sort, and search fields.</li><li>Clicking on ‘···’ opens more controls, where you can select the displayed fields (properties) or group them. The “All” view will display all fields by default, which may contain a lot of redundancy. We will also provide targeted displays in other views, and you can create your own views as well.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KFvedWLt-1MmAHE2MTBSVw.png" /><figcaption>The control area is located in the upper right corner and common operations include: querying, filtering, sorting, displaying fields, and grouping.</figcaption></figure><p><strong>3. Pages</strong></p><p>This is one of Notion’s unique features where each piece of data can be a Page. The paper’s abbreviation serves as the primary key, and hovering the mouse next to it will display “Open”. Clicking on it will expand the detailed page of the paper on the right. In the upper right corner, you can switch the sidebar to full screen mode for quick scrolling through data.</p><ul><li>The detailed page includes all the attributes of that data.</li><li>It functions as a standalone page where you can record content, images etc.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LwduHKJisTDCny7LZUQrtw.png" /><figcaption>Click on “Open” next to the paper abbreviation on the right to open the detailed page.</figcaption></figure><p>In addition to displaying the attributes, for the convenience of readers to quickly understand the paper’s content, we have three additional sections on the detailed page:</p><ul><li>Abstract and author information from the original paper</li><li>Important figures and charts from the paper, typically process or model architecture diagrams</li><li>Quick reading (In Chinese)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zyu7KTfCcJvk4RdEYPQq8g.png" /><figcaption>The paper detail page presents a quick interpretation of the original paper.</figcaption></figure><p>The quick reading guide utilizes <a href="https://papers.cool/"><strong>Papers.cool</strong></a> and <a href="https://kimi.moonshot.cn/"><strong>Kimi Chat</strong></a> (an excellent LLMs tool for assisting in reading papers 💪).</p><p>The address for Papers.cool is right below the paper title, for example: <a href="https://papers.cool/arxiv/2402.07630">https://papers.cool/arxiv/2402.07630</a></p><p>The usage of Papers.cool is also very simple, for example, you just need to enter the Arxiv id on the website：<a href="https://papers.cool/arxiv/">https://papers.cool/arxiv/</a>&lt;arxiv_id&gt;.</p><p>You can further engage with Kimi Chat by accessing it from the bottom of the webpage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EKX6Hu3kYBEiywuhK-6ctQ.png" /><figcaption>On the Papers.cool page, click on [PDF] to open the original paper and click on [KIMI] to generate a quick reading interpretation.</figcaption></figure><p>If you want Kimi to generate an English interpretation, you can use Ctrl/command + F, then select settings, set the Kimi Language to English, don’t forget to save, and after refreshing, it will output in English.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JN-TUFvGI2Hew3VnnWgDjA.png" /><figcaption>Set the language of the quick reading guide to English,</figcaption></figure><p><strong>4. Views</strong></p><p>Below the title in the top left corner is the view area, displaying the current list of views.</p><p>You can save your custom settings as a view to make the table more targeted and easier to access later.</p><p>In addition to tables, views also support formats like boards, timelines, galleries, and more.</p><p>For example, if you want to specifically view tasks and datasets in the RAG paper, you can filter out these fields and set corresponding filters. These settings will be displayed below the view.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-IFwIwAtiuVqM5FbjW4Ljw.png" /><figcaption>An example of a view for RAG Tasks and Datasets:</figcaption></figure><p>Another commonly used view is the Board view, often used in conjunction with grouping.</p><p>For example, if you want to see which papers are related to pre-training, fine-tuning, and inference, you can create a Board view and use “Aug_Stage” as the grouping criteria. You can also select the fields to display, apply filters, and set sorting preferences.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*169zW9Nydhf_otUuyJXEZw.png" /><figcaption>An example of a Board view grouped by the Augmentation Stage</figcaption></figure><p><strong>5. Relation</strong></p><p>“Relation” is another important concept in Notion. It is represented by an arrow in the properties and can be understood as an attribute that links two databases together. This attribute acts as a regular property in one database and as a primary key in another database.</p><p>See <a href="https://www.notion.so/help/relations-and-rollups#what-is-a-database-relation%EF%BC%89"><em>Detailed Information for Notion “Relation”.</em></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yxTVuLlAZtyLLh9LMOT0MA.png" /><figcaption>Official Example for Notion “Relation”</figcaption></figure><p>In the OpenRAG Base, we have set up multiple Relation properties such as Scholar, Institution, Dataset, etc. This allows us to conduct more targeted analysis based on these properties. Each property corresponds to a database where it serves as the primary key for linking related information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*itMPp2Kku6Sna2O_KiJDlg.png" /><figcaption>“Relation” examples in OpenRAG Base</figcaption></figure><p>In the example above, there are three Relations. By clicking on the table header and entering “Edit Property”, you can see the right sidebar where the “Preview” section displays which two databases are linked by this Relation.</p><p>In the specific example, the Relation is bidirectional, meaning the “Dataset property” appears in the Academic_paper database and links to the Dataset table as a primary key. Conversely, the primary key “Paper” in the Academic_paper database will automatically link to the Dataset table.</p><p>Now, let’s open the Dataset Database on the right to have a more visual understanding. You will see that a “Paper” Relation property automatically appears in the Dataset database.</p><blockquote><strong>💡 This means that when you add a dataset to a paper in the Academic_paper database, the “Paper” property in the Dataset table will automatically include that paper. This bidirectional relation ensures that the information stays connected and updated across databases.</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D55CdWlmOxZ3m73ZFZwDDQ.png" /><figcaption>In a bidirectional relation, the Dataset table will automatically link to the primary key (Paper) in the associated table (Academic_paper) and update accordingly. This ensures that the data remains synchronized between the two databases and reflects any changes made in either database.</figcaption></figure><p>Below we will briefly introduce other databases, which can be used in the same way as Academic_Paper.</p><h4>Downstream Task and Dataset</h4><p>These two databases summarize the downstream tasks and datasets used in the RAG domain. The datasets have been presented in the previous section, and the downstream tasks are summarized as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f9HhjzMt4dwRwuGkJ9EtNQ.png" /><figcaption>Downstream Task in Gallery View</figcaption></figure><p>You can also refer to the summary of downstream tasks and datasets in our survey.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iRqKTa_Qb4EhONZuXfzJAQ.png" /><figcaption>《Retrieval-Augmented Generation for Large Language Models: A Survey》</figcaption></figure><h4>RAG Readings</h4><p>In addition to academic papers, there are many other channels that can help us access cutting-edge information about RAG.</p><p>We have selected some important reading materials related to RAG and placed them in this database, including Medium articles, WeChat articles (In Chinese) , Zhihu articls (In Chinese), and official blogs of technical frameworks (such as Langchain, LLamaIndex, Neo4j), and YouTube videos.</p><p>Since these selections are subjective, they may be influenced by personal impressions. If you come across excellent articles, you can also inform me through comments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rwQ5Sy9wzQZS9KXocI8-cA.png" /><figcaption>RAG Readings from different platforms</figcaption></figure><h4>RAG Scholar and Institution</h4><p>Would like to know which individuals and organizations are researching RAG? The Scholar and Institution databases summarize the main researchers and their institutions in the field of RAG based on papers and blogs. For the purpose of statistical analysis, for a single article, we typically only count the first author, corresponding author, or laboratory head.</p><p>The following image is our RAG Scholar Gallery, displaying the institutions of relevant authors and their representative works. <strong>Red icons represent researchers in academia, while green icons represent practitioners in the industry. It can be seen that RAG is indeed a direction of great interest in both academia and industry</strong>.</p><p><em>The “High” label only represents a subjective evaluation of the researcher’s relevance to the research direction and RAG (usually a researcher’s work involves multiple directions), for reference only, and does not imply any other meaning.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HLMaXlt0gIE0pG__GwD3ug.png" /><figcaption>RAG Scholar Gallery</figcaption></figure><h3>Evaluation, Benchmark and Toolkit <a href="https://www.notion.so/ToolKits-4edad30c33484f228647d75431ba335c?pvs=21">ToolKits</a></h3><p>The evaluation of RAG has always been a very important step. Here we will summarize the current evaluation tools and benchmark tests. And the technology frameworks that we can use when developing the RAG system, such as Langchain, LLamaIndex, etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hr3xH0bKv311tVoahK8fvg.png" /><figcaption>Evaluation method and Benchmark In RAG</figcaption></figure><p>…</p><p><strong><em>More content awaits your exploration.</em></strong></p><h3>What else ？</h3><ul><li>Comment！</li></ul><p>You can comment and engage in friendly discussions on any topic of interest to you, such as Database or Pages details. Please maintain good social etiquette and refrain from discussing topics unrelated to RAG.</p><ul><li><strong>DUPLICATE！</strong></li></ul><p><em>💡 Anyone can clone the entire repository to local, and make more flexible modifications. </em><strong><em>Start building your own exclusive RAG knowledge base from here!</em></strong></p><ul><li>Contribute！</li></ul><p>If you are interested in contributing to maintaining this project, please email us !</p><h3>Who are we ?</h3><p>This project is jointly initiated by</p><ul><li>Haofen Wang (王昊奋) 、Meng Wang (王萌) ,<strong>Tongji University</strong></li><li>Yun Xiong (熊贇) Shanghai Key Laboratory of Data Science,<strong> Fudan University</strong></li></ul><p><strong>Contact Us</strong></p><p>For questions and suggestions about this project, please contact:</p><ul><li><strong>Yunfan Gao</strong> (高云帆）Shanghai Research Institute for Intelligent Autonomous Systems (Tongji University) Email: gaoyunfan1602@gmail.com</li></ul><p>For collaboration and other related matters, please contact:</p><ul><li><strong>Haofen Wang</strong>(王昊奋) Tongji University Email: haofen.wang@tongji.edu.cn</li><li><strong>Meng Wang</strong>(王萌) Tongji University Email: mengwangtj@tongji.edu.cn</li><li>Y<strong>un Xiong</strong>(熊贇) Fudan University Email: yunx@fudan.edu.cn</li></ul><h4><strong>Others</strong></h4><p>Our Survey：<a href="https://arxiv.org/pdf/2312.10997.pdf">Retrieval-Augmented Generation for Large Language Models: A Survey</a></p><ul><li><strong>Our LLMs Evaluation Project: </strong><a href="https://ai-ceping.com/"><strong>AI-Ceping</strong></a><strong> !</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7Fua6Ss512PIxzHpI78BRA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7b4f34208d09" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Modular RAG and RAG Flow: Part II]]></title>
            <link>https://medium.com/@OpenRAG/modular-rag-and-rag-flow-part-ii-77b62bf8a5d3?source=rss-52d08ad306b------2</link>
            <guid isPermaLink="false">https://medium.com/p/77b62bf8a5d3</guid>
            <category><![CDATA[large-language-models]]></category>
            <category><![CDATA[modular-rag]]></category>
            <category><![CDATA[rags]]></category>
            <dc:creator><![CDATA[OpenRAG]]></dc:creator>
            <pubDate>Mon, 29 Jan 2024 05:32:46 GMT</pubDate>
            <atom:updated>2024-01-29T06:34:06.244Z</atom:updated>
            <content:encoded><![CDATA[<h4>How to design your own RAG Flow?</h4><p>In Part I, we primarily discussed the three-tier structure of modular RAG (Module Type - Module- Operator) and briefly mentioned the concept of RAG Flow.</p><p><a href="https://medium.com/@OpenRAG/modular-rag-and-rag-flow-part-%E2%85%B0-e69b32dc13a3">Modular RAG and RAG Flow: Part Ⅰ</a></p><p>After defining Module and Operator, they can help us to view various RAG methods from a flow perspective. Each RAG can be arranged with a set of operators.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ammdaKI9Hxlr2d5Js1pRcQ.png" /><figcaption>Framework of Modular RAG</figcaption></figure><p>So, under the paradigm of modular RAG, how should we design our RAG system?</p><p>In Part II, we will delve into the<strong> typical RAG Flow pattern</strong>, <strong>specific RAG Flow implementation</strong>, and <strong>best industry case.</strong></p><h3>Typical RAG Flow Pattern and Implementation</h3><p>First, let’s explore the prominent patterns for RAG flow, along with the specific flows under each template, illustrating how different modules and operators are orchestrated.</p><p>In the context of RAG Flow, we will delineate three distinct flows for the fine-tuning stage and four flows for the inference stage.</p><h3>Tuning Stage</h3><blockquote>Retriever Fine-tuning, Generator Fine-tuning, and Dual Fine-tuning.</blockquote><h4>Retriever FT</h4><p>In the RAG Flow, common methods for fine-tuning the retriever include:</p><ul><li><strong>Direct fine-tuning of the retriever. </strong>Constructing a specialized dataset for retrieval and fine-tuning the dense retriever. For example, using open-source retrieval datasets or constructing one based on your domain-specific data.</li><li><strong>Adding trainable Adapter modules. </strong>Sometimes, direct fine-tuning of the API-base embedding model (e.g., OpenAI Ada-002 and Cohere) is not feasible. Incorporating an Adapter module can enhance the representation of your data. Additionally, the adapter module facilitates better alignment with downstream tasks, whether for task-specific (e.g., <a href="https://arxiv.org/pdf/2310.18347.pdf">PCRA</a>) or general purposes (e.g., <a href="https://arxiv.org/abs/2305.17331">AAR</a>).</li><li><strong>LM-supervised Retrieval (LSR).</strong> Fine-tuning the retriever based on the results generated by LLM.</li><li><strong>LLM Reward RL</strong> : Still using the LLM output results as the supervisory signal. Employing reinforcement learning to align the retriever with the generator. The whole retrieval process is disassembled in the form of a generative Markov chain.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sJF5Fr5urHPlMx5FwQYK-g.png" /><figcaption>Typical RAG Flow Pattern for Retriever FT</figcaption></figure><h4>Generator FT</h4><p>The primary methods for fine-tuning a generator in RAG Flow include:</p><ul><li><strong>Direct fine-tuning.</strong> Fine-tuning through an external dataset can supplement the generator with additional knowledge. Another benefit is the ability to customize input and output formats. By setting theQ&amp;A format, LLM can understand specific data formats and output according to instructions.</li><li><strong>GPT-4 distillation.</strong> When using on-premise deployment of open-source models, a simple and effective method is to use GPT-4 to batch construct fine-tuning data to enhance the capabilities of the open-source model.</li><li><strong>Reinforcement Learning from LLM/Human Feedback. </strong>Reinforcement learning based on feedback from the final generated answers. In addition to using human evaluations, GPT-4 can also serve as an evaluative judge.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sJU5gG7CRdNsn3v3CSSQFg.png" /><figcaption>Typical RAG Flow Pattern for Generator FT</figcaption></figure><h4>Dual FT</h4><p>In the RAG system, fine-tuning both the retriever and the generator simultaneously is a unique feature of the RAG system. It is important to note that the emphasis of system fine-tuning is on the coordination between the retriever and the generator. Fine-tuning the retriever and the generator separately separately belongs to the combination of the former two, rather than being part of Dual FT.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1022/1*6mKaQah_jwBbGf9pwapTog.png" /><figcaption>Typical RAG Flow Pattern for Dual FT</figcaption></figure><p>An exemplary implementation is <a href="https://arxiv.org/abs/2310.01352">RA-DIT</a>, which fine-tunes both the LLM and the retriever. The LM-ft component updates the LLM to maximize the likelihood of the correct answer given the retrieval-augmented instructions while the R-ft component updates the retriever to minimize the KL-Divergence between the retriever score distribution and the LLM preference.</p><p>The framework employs a on-premises Llama as the generator and a state-of-the-art dual-encoder based dense retriever, DRAGON+, as the retriever.</p><p>Following <a href="https://arxiv.org/abs/2301.12652">REPLUG</a>, RA-DIT retrieve relevant text chunks based on the language model prompt. Each retrieved chunk is prepended to the prompt, and the predictions from multiple chunks are computed in parallel and ensembled by weighted possibilty to produce the final output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hF3HTJbA-9WFSC9DjTD_VQ.png" /><figcaption>RAG Flow in RA-DIT</figcaption></figure><h3>Inference Stage</h3><p>In the inference stage, we have distilled four typical RAG Flow patterns.</p><h4>Sequential</h4><p>The sequential structure of the RAG Flow organizes the modules and operators of RAG in a linear pipeline, as depicted in the following diagram. If it includes both Pre-Retrieval and Post-Retrieval module types, it represents the typical Advanced RAG paradigm; otherwise, it embodies the typical Naive RAG paradigm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rzsCcy7kX5hCgT7GlaszFg.png" /><figcaption>Sequential RAG Flow Pattern</figcaption></figure><p>The most widely used RAG Pipeline currently is the Sequential, which commonly includes Query Rewrite or HyDE before retrieval and Rerank operator after retrieval, such as in the case of <a href="https://github.com/netease-youdao/QAnything">QAnything</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ny-beI5uSfhhCv9IUomcsw.png" /><figcaption>The most commonly used sequential RAG Flow</figcaption></figure><p><a href="https://arxiv.org/pdf/2305.14283.pdf">Rewrite-Retrieve-Read </a>(RRR) is also a typical sequential structure. The Query Rewrite module is a smaller trainable language model, and in the context of reinforcement learning, the optimization of the rewriter is formalized as a Markov decision process, with the final output of the LLM serving as the reward. The retriever utilizes a sparse encoding model, BM25.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O687iy-6VzWodxi-F_XTBw.png" /><figcaption>RAG Flow in RRR</figcaption></figure><h4>Conditional</h4><p>The RAG Flow with conditional structure involves selecting different RAG pathways based on different conditions. Typically, this is accomplished through a<strong> Routing module</strong> that determines the route based on query <strong>keywords</strong> or <strong>semantics</strong>.</p><p>Different routes are chosen based on the type of question, directing to different flows for specific scenarios. For instance, when users inquire about serious issues, political matters, or entertainment topics, the tolerance for answers from large models varies. Different routing branches usually differ in retrieval sources, retrieval processes, configuration , model , and prompts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CNCTu32WgMelhfNjTNGe7g.png" /><figcaption>Conditional RAG Flow Pattern</figcaption></figure><p>A classic implementation of Conditional RAG is the <a href="https://github.com/aurelio-labs/semantic-router">Semantic Router</a>.</p><h4>Branching</h4><p>The RAG Flow with a branching structure differs from the conditional approach in that it involves multiple parallel branches, as opposed to selecting one branch from multiple options in the conditional approach. Structurally, it can be categorized into two types:</p><ul><li><strong>Pre-Retrieval Branching (Multi-Query, Parallel Retrieval).</strong> This involves expanding the original query to obtain multiple sub-queries, and then conducting separate retrieval for each sub-query. After retrieval, the approach allows for immediate answer generation based on the sub-questions and the corresponding retrieval content. Alternatively, it may involve using only the expanded retrieval content and merging it into a unified context for generation.</li><li><strong>Post-Retrieval Branching (Single Query, Parallel Generation).</strong> This approach maintains the original query and retrieves multiple document chunks. Subsequently, it concurrently uses the original query and each document chunks for generation, and finally merges the generated results together.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3Ius_4RarMXiAVYI4-Eqww.png" /><figcaption>Branching RAG Flow Pattern</figcaption></figure><p>REPLUG embodies a classic post-retrieval branching structure, wherein the probability of each token is predicted for each branch. Through weighted possibility ensemble, the different branches are aggregated, and the final generation result is used to fine-tune the retriever, known as Contriever, through feedback.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GXuDmV008IZkmbY-ACchMg.png" /><figcaption>RAG Flow in REPLUG</figcaption></figure><h4>Loop</h4><p>The RAG Flow with a loop structure, an important characteristic of Modular RAG, involves interdependent retrieval and reasoning steps. It typically includes a <strong>Judge module</strong> for flow control.This can be further categorized into iterative, recursive, and adaptive (active) retrieval approaches.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jeqi2sQIHU2SFhzP55brRg.png" /><figcaption>Loop RAG Flow Pattern</figcaption></figure><p><strong>Iterative Retrieval</strong></p><p>At times, a single retrieval and generation may not effectively address complex questions requiring extensive knowledge. Therefore, an iterative approach can be used in RAG, typically involving a fixed number of iterations for retrieval.</p><p>An exemplary case of iterative retrieval is <a href="https://arxiv.org/abs/2305.15294">ITER-RETGEN</a>, which iterates retrieval-augmented generation and generation-augmented retrieval. Retrieval-augmented generation outputs a response to a task input based on all retrieved knowledge. In each iteration, ITER-RETGEN leverages the model output from the previous iteration as a specific context to help retrieve more relevant knowledge. Termination of the loop is determined by a predefined number of iterations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5SEh7nrsrI8BCPTMC6C3Kw.png" /><figcaption>RAG Flow in ITER-RETGEN</figcaption></figure><p><strong>Recursive Retrieval</strong></p><p>The characteristic feature of recursive retrieval, as opposed to iterative retrieval, is its clear dependency on the previous step and its continuous deepening of retrieval. Typically, there is a termination mechanism as an exit condition for recursive retrieval. In RAG systems, recursive retrieval usually involves Query Transformation, relying on the newly rewritten query for each retrieval.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xvs8OJUvY-X-xcKtE7D7MA.png" /><figcaption>RAG Flow in ToC</figcaption></figure><p>A typical implementation of recursive retrieval, such as ToC, involves recursively executing RAC (Recursive Augmented Clarification) to gradually insert sub-nodes into the clarification tree from the initial ambiguous question (AQ). At each expansion step, paragraph re-ranking is performed based on the current query to generate a disambiguous Question (DQ). The exploration of the tree concludes upon reaching the maximum number of valid nodes or the maximum depth. Once the clarification tree is constructed, ToC gathers all valid nodes and generates a comprehensive long-text answer to address AQ.</p><p><strong>Adaptive(Active) Retrieval</strong></p><p>With the advancement of RAG, there has been a gradual shift beyond passive retrieval to the emergence of adaptive retrieval, also known as proactive retrieval, which is partly attributed to the powerful capabilities of LLM. This shares a core concept with LLM Agent.</p><p>RAG systems can actively determine the timing of retrieval and decide when to conclude the entire process and produce the final result. Based on the criteria for judgment, this can be further categorized into Prompt-based and Tuning-based approaches.</p><ul><li><strong>Prompt-base.</strong>The Prompt-based approach involves controlling the flow using Prompt Engineering to direct LLM. A typical implementation example is FLARE. Its core concept is that the language model should only retrieve when essential knowledge is lacking, to avoid unnecessary or inappropriate retrieval in an enhanced LM. FLARE iteratively generates the next provisional sentence and checks for the presence of low-probability tokens. If found, the system retrieves relevant documents and regenerates the sentence.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uCiwmcdGC2fFJmfnEjFihw.png" /><figcaption>RAG Flow in FLARE</figcaption></figure><ul><li><strong>Tuning-base. </strong>The Tuning-based approach involves fine-tuning LLM to generate <strong>special tokens</strong>, thereby triggering retrieval or generation. This concept can be traced back to <strong>Toolformer</strong>, where the generation of specific content assists in invoking tools. In RAG systems, this approach is used to control both retrieval and generation steps. A typical case is Self-RAG. Specifically:</li></ul><p>1.Given an input prompt and the preceding generation result, first predict whether the special token “Retrieve” is helpful for enhancing the continued generation through paragraph retrieval.</p><p>2.If retrieval is needed, the model generates: a critique token to evaluate the retrieved passage’s relevance, the next response segment, and a critique token to evaluate if the information inthe response segment is supported by the passage.</p><p>3.Finally, a critique token evaluates the overall utility of the response and selects the optimal result as the final output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e_dROt1TAFyCOLwy-QbclQ.png" /><figcaption>RAG Flow in Self-RAG</figcaption></figure><h3>Best Industry Case</h3><p>In the preceding sections, we have delved into various research papers, with their distinctive feature being an emphasis on addressing specific details and intricacies. RAG, on the other hand, stands out as a technology that shines brightly in the industrial domain, enabling LLM to be applied across a wide range of task scenarios. This chapter will shed light on several industry-leading RAG practices from the perspective of RAG Flow, offering insights into how to effectively combine and construct the flow of RAG in real-world application scenarios.</p><h4>OpenAI</h4><p>The insights from OpenAI’s Demo Day presentation do not fully represent the actual operations of OpenAI.</p><p>In their efforts to enhance the success of RAG, the OpenAI team started with a 45% accuracy rate and experimented with various methods, identifying which methods were ultimately adopted for production. They explored hypothetical document embeddings (HyDE), fine-tuning embeddings, and other methods, but the results were not satisfactory. By experimenting with different-sized chunks of information and embedding different content sections, they were able to increase the accuracy to 65%. Through reranking and methods tailored to handle different types of questions, they further improved the accuracy to 85%. Ultimately, by combining prompt engineering, query expansion, and other methods, they achieved a 98% accuracy rate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9mrkV3jG2jU3XX8diztnPw.png" /><figcaption>OpenAI RAG Flow</figcaption></figure><p>The team emphasized the powerful potential of model fine-tuning and the integration of RAG, particularly in approaching industry-leading levels without the use of complex techniques, solely through simple model fine-tuning and prompt engineering.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FahnGLM-RC1Y%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DahnGLM-RC1Y&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FahnGLM-RC1Y%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/330e73429992c21ec3e36c1d2efc77df/href">https://medium.com/media/330e73429992c21ec3e36c1d2efc77df/href</a></iframe><h4>Baichuan</h4><p>Based on the publicly available information from various sources, the available data is limited, and the author has made some speculative assumptions about certain details. See the <a href="https://mp.weixin.qq.com/s?__biz=MzA3MzI4MjgzMw==&amp;mid=2650901201&amp;idx=1&amp;sn=3a9bd61403fb4b024ec5d8c128990495&amp;scene=21#wechat_redirect">original</a> (in Chinese)</p><p>Baichuan, drawing inspiration from Meta’s <strong>CoVe, </strong>has devised a method to deconstruct complex prompts into multiple independent and parallel retrievable search-friendly queries. This enables large models to conduct targeted knowledge base searches for each sub-query, thereby providing more accurate and detailed answers and reducing spurious outputs. Additionally, they have leveraged their proprietary <strong>TSF (Think-Step Further) </strong>to infer and unearth the deeper underlying questions behind user input, allowing for a more precise and comprehensive understanding of user intent. While the technical details of TSF have not been disclosed, it is speculated to be an enhancement of the Step-back prompting method.</p><p>In the retrieval step, Baichuan Intelligence has developed the Baichuan-Text-Embedding vector model, pre-trained on high-quality Chinese data comprising over 1.5 trillion tokens. They have addressed the issue of batch size dependency in contrastive learning through a proprietary loss function. This vector model has <strong>surpassed the C-MTEB</strong>.</p><p>Additionally, they have introduced <strong>sparse</strong> retrieval and <strong>rerank </strong>models (not disclosed.), forming a <strong>hybrid retrieval</strong> approach that combines vector retrieval with sparse retrieval in parallel, significantly enhancing the recall rate to 95%.</p><p>Furthermore, they have introduced <strong>self-critique</strong>, enabling large models to introspect on the retrieved content based on prompt, relevance, and utility, and undergo a secondary review to select the most matching and high-quality candidate content.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qrvfZenrV0AtvZdY12EcQA.png" /><figcaption>Baichuan RAG Flow</figcaption></figure><p>Given the numerous branches in the entire Baichuan RAG Flow and the lack of specific disclosure, it is reasonable to speculate that reranking and selection entail reordering and screening of all materials, whether retrieved or generated from other branches.</p><h4>Databricks</h4><p>Databricks, as a leading service provider in the big data domain, has maintained its distinctive features and advantages in RAG design.</p><p>When a user inputs a question, the system retrieves relevant information from pre-processed text vector indices, incorporating prompt engineering to generate responses. The upper half, the <strong>Unstructured Data Pipeline</strong>, follows the mainstream RAG approach and does not exhibit any particular uniqueness.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Iq1OzCIqEY71E_DR6xCcPA.png" /><figcaption>Databricks RAG Flow</figcaption></figure><p>The lower half, the <strong>Structured Data Pipeline</strong>, represents Databricks’ feature engineering process and is the most significant aspect of Databricks’ RAG implementation. Leveraging its expertise in big data, Databricks conducts additional retrieval from its highly accurate data storage, fully utilizing its advantage in <strong>Real Time Data Serving.</strong> It is evident that Databricks’ strategy in the era of GenAI is to empower RAG applications with broad market demand, integrating its robust Delta lake processing capabilities with generative AI technology to build an integrated solution, and promoting this unified service to its customers.</p><p><a href="https://docs.databricks.com/en/generative-ai/retrieval-augmented-generation.html">RAG (Retrieval Augmented Generation) on Databricks</a></p><h3>Conclusion</h3><p>The article delineates three patterns of fine-tuning stages, four patterns of inference stages, as well as the specific flow implementations in seven papers and three industrial best practices. The overall framework is illustrated as follows.</p><p>As we also mentioned in Part 1, summarization and abstraction of the RAG paradigm are crucial in this era of rapid technological advancement. It is essential to transcend specific implementations and comprehend the current technological features and trends from a higher dimension, in order to grasp the direction of future development.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mMwI8BTa0IPtyD3PFGvmeA.jpeg" /><figcaption>Modular RAG Technical Map</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=77b62bf8a5d3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Modular RAG and RAG Flow: Part Ⅰ]]></title>
            <link>https://medium.com/@OpenRAG/modular-rag-and-rag-flow-part-%E2%85%B0-e69b32dc13a3?source=rss-52d08ad306b------2</link>
            <guid isPermaLink="false">https://medium.com/p/e69b32dc13a3</guid>
            <category><![CDATA[large-language-models]]></category>
            <category><![CDATA[rags]]></category>
            <dc:creator><![CDATA[OpenRAG]]></dc:creator>
            <pubDate>Wed, 24 Jan 2024 16:10:35 GMT</pubDate>
            <atom:updated>2024-01-24T16:10:35.428Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>A compressive and high-level summarization of RAG .</blockquote><blockquote>In Part I, we will focus the concept and components of Modular RAG, containing 6 module types, 14 modules and 40+ operators.</blockquote><h3>Intro</h3><p>Over the past year, the concept of <strong>Retrieval-Augmented Generation (RAG)</strong> as a method for implementing LLM applications has garnered considerable attention. We have authored a comprehensive<a href="https://arxiv.org/abs/2312.10997"> survey</a> on RAG , delving into the shift from Naive RAG to Advanced RAG and Modular RAG. However, the survey primarily scrutinized RAG technology through the lens of Augmentation (e.g. Augmentation Source/Stage/Process).</p><p>This piece will specifically center on the Modular RAG paradigm. We further defined a <strong>three-tier Modular RAG</strong> paradigm, comprising <strong>Module Type</strong>, <strong>Module</strong>, and <strong>Operator.</strong> Under this paradigm, we expound upon the core technologies within the current RAG system, encompassing 6 major Module Types, 14 Modules, and 40+Operators, aiming to provide a comprehensive understanding of RAG.</p><p>By orchestrating different operators, we can derive various <strong>RAG Flows</strong>, a concept we aim to elucidate in this article. Drawing from extensive research, we have distilled and summarized typical patterns, several specific implementation cases and best industry cases. (Due to space constraints, this part will be addressed in Part II.)</p><p>The <strong>objective</strong> of this article is to offer a more sophisticated comprehension of the present state of RAG development and to pave the way for future advancements. Modular RAG presents plenty opportunities, facilitating the definition of new operators, modules, and the configuration of new Flows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0g3d-oldnGDwdGP0zQGmzQ.png" /><figcaption>The Figures in our RAG Survey</figcaption></figure><h3>What is Modular RAG？</h3><p>The progress of RAG has brought about a more diverse and flexible process, as evidenced by the following crucial aspects:</p><ol><li><strong>Enhanced Data Acquisition:</strong> RAG has expanded beyond traditional unstructured data and now includes semi-structured and structured data, with a focus on preprocessing structured data to improve retrieval and reduce the model’s dependence on external knowledge sources.</li><li><strong>Incorporated Techniques</strong>: RAG is integrating with other techniques, including the use of fine-tuning, adapter modules, and reinforcement learning to strengthen retrieval capabilities.</li><li><strong>Adaptable Retrieval Process</strong>: The retrieval process has evolved to support multi-round retrieval enhancement, using retrieved content to guide generation and vice versa. Additionally, autonomous judgment and the use of LLM have increased the efficiency of answering questions by determining the need for retrieval.</li></ol><p><strong>Definition of Modular RAG</strong></p><p>Above, we can see that the rapid development of RAG has surpassed the <strong>Chain-style Advanced RAG</strong> paradigm, showcasing a modular characteristic. To address the current lack of organization and abstraction, we propose a Modular RAG approach that seamlessly integrates the development paradigms of Naive RAG and Advanced RAG.</p><p>Modular RAG presents a highly <strong>scalable</strong> paradigm, dividing the RAG system into a <strong>three-layer</strong> structure of Module Type, Modules, and Operators. Each Module Type represents a core process in the RAG system, containing multiple functional modules. Each functional module, in turn, includes multiple specific operators. The entire RAG system becomes a permutation and combination of multiple modules and corresponding operators, forming what we refer to as RAG Flow. Within the Flow, different functional modules can be selected in each module type, and within each functional module, one or more operators can be chosen.</p><p><strong>The relationship with the previous paradigm</strong></p><p>The Modular RAG organizes the RAG system in a multi-tiered modular form. Advanced RAG is a modular form of RAG, and Naive RAG is a special case of Advanced RAG. The relationship between the three paradigms is one of inheritance and development.</p><p><strong>Opportunities in Modular RAG</strong></p><p>The benefits of Modular RAG are evident, providing a fresh and comprehensive perspective on existing RAG-related work. Through modular organization, relevant technologies and methods are clearly summarized.</p><ul><li><strong>Research perspective</strong>. Modular RAG is highly scalable, facilitating researchers to<strong> propose new Module Types, Modules, and operators </strong>based on a comprehensive understanding of the current RAG development.</li><li><strong>Application perspective. </strong>The design and construction of RAG systems become more convenient, allowing users to customize RAG Flow based on their existing data, usage scenarios, downstream tasks, and other requirements. Developers can also reference current Flow construction methods and <strong>define new flow and patterns </strong>based on different application scenarios and domains.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HH07IB1iC4jbG5tr76emEg.png" /><figcaption>The Framework of Modular RAG</figcaption></figure><h3>Module Type — Module — Operators</h3><blockquote>In this chapter, we will delve into the three-tier structure and constrcuct a technical roadmap for RAG. Due to space constraints, we will refrain from delving into technical specifics; however, comprehensive references will be provided for further reading.</blockquote><h3>1. Indexing</h3><p>Indexing, the process of breaking down text into manageable chunks, is a crucial step in organizing the system, facing three main challenges:</p><ul><li><strong>Incomplete Content Representation.</strong>The semantic information of chunks is influenced by the segmentation method, resulting in the loss or submergence of important information within longer contexts.</li><li><strong>Inaccurate Chunk Similarity Search. </strong>As data volume increases, noise in retrieval grows, leading to frequent matching with erroneous data, making the retrieval system fragile and unreliable.</li><li><strong>Unclear Reference Trajectory. </strong>The retrieved chunks may originate from any document, devoid of citation trails, potentially resulting in the presence of chunks from multiple different documents that, despite being semantically similar, contain content on entirely different topics.</li></ul><h4>Chunk Optimization</h4><p>Larger chunks can capture more context, but they also generate more noise, requiring longer processing time and higher costs. While smaller chunks may not fully convey the necessary context, they do have less noise.</p><ul><li><strong><em>Sliding Window</em></strong></li></ul><p>One simple way to balance these demands is to use overlapping chunks.By employing a sliding window, semantic transitions are enhanced. However, limitations exist, including imprecise control over context size, the risk of truncating words or sentences, and a lack of semantic considerations.</p><ul><li><strong><em>Small-to-Big</em></strong></li></ul><p>The key idea is to separate the chunks used for retrieval from the chunks used for synthesis. Using smaller chunks can improve the accuracy of retrieval, while larger chunks can provide more context information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BD501aONQpI9yOJuYH7Nfg.png" /></figure><p>Specifically, one approach could involve retrieving <strong>smaller chunks</strong> and then <strong>referencing parent IDs</strong> to return larger chunks. Alternatively, individual sentences could be retrieved, and the <strong>surrounding text window</strong> of the sentence returned.</p><p>Detailed information and <a href="https://llamahub.ai/l/llama_packs-recursive_retriever-small_to_big?from=all">LlamaIndex Implementation.</a></p><p><a href="https://towardsdatascience.com/advanced-rag-01-small-to-big-retrieval-172181b396d4">How to Make Your LLM More Accurate with RAG &amp; Fine-Tuning | Towards Data Science</a></p><ul><li><strong><em>Summary</em></strong></li></ul><p>It is akin to the Small-to-Big concept, where a summary of larger chunks is generated first, and the retrieval is performed on the summary. Subsequently, a secondary retrieval can be conducted on the larger chunks.</p><ul><li><strong>Metadata Attachment</strong></li></ul><p>Chunks can be enriched with metadata information such as <strong>page number</strong>, <strong>file name, author, timestamp, summary</strong>, or the questions that the chunk can answer. Subsequently, retrieval can be filtered based on this metadata, limiting the scope of the search. See the implementation in<a href="https://docs.llamaindex.ai/en/stable/module_guides/loading/documents_and_nodes/usage_metadata_extractor.html"> LlamaIndex</a>.</p><h3>Structural Oraginzation</h3><p>One effective method for enhancing information retrieval is to establish a hierarchical structure for the documents. By constructing chunks structure, RAG system can expedite the retrieval and processing of pertinent data.</p><ul><li><strong><em>Hierarchical Index</em></strong></li></ul><p>In the hierarchical structure of documents, nodes are arranged in parent-child relationships, with chunks linked to them. Data summaries are stored at each node, aiding in the swift traversal of data and assisting the RAG system in determining which chunks to extract. This approach can also mitigate the illusion caused by block extraction issues.</p><p>The methods for constructing a structured index primarily include：</p><ul><li><strong>Structural awareness</strong>.paragraph and sentence segmentation in docs</li><li><strong>Content awareness .</strong>inherent structure in PDF, HTML, Latex</li><li><strong>Semantic awareness</strong>.Semantic recognition and segmentation of text based on NLP techniques, such as leveraging NLTK.</li></ul><p>Check <a href="https://www.arcus.co/blog/rag-at-planet-scale">Arcus</a>’s hierarchical index at large-scale.</p><ul><li><strong><em>KG Organization Docs</em></strong></li></ul><p>The utilization of Knowledge Graphs (KGs) in constructing the hierarchical structure of documents contributes to maintaining consistency. It delineates the connections between different concepts and entities, markedly reducing the potential for illusions.</p><p>Another advantage is the transformation of the information retrieval process into instructions that LLM can comprehend, thereby enhancing the accuracy of knowledge retrieval and enabling LLM to generate contextually coherent responses, thus improving the overall efficiency of the RAG system.</p><p>Check <a href="https://neo4j.com/developer-blog/advanced-rag-strategies-neo4j/">Neo4j implementation</a> and <a href="https://docs.llamaindex.ai/en/stable/examples/index_structs/knowledge_graph/Neo4jKGIndexDemo.html">LllmaIndex Neo4j query </a>engine.</p><p>For organizing multiple documents using KG, you can refer to this research paper<strong> </strong><a href="https://arxiv.org/abs/2308.11730"><strong>KGP:Knowledge Graph Prompting for Multi-Document Question Answering</strong></a><strong>.</strong></p><p><a href="https://medium.com/@alcarazanthony1/knowledge-graph-prompting-a-new-approach-for-multi-document-question-answering-ab5c4006a429">Knowledge Graph Prompting: A New Approach for Multi-Document Question Answering</a></p><h3>2. Pre-Retrieval</h3><p>One of the primary challenges with Naive RAG is its direct reliance on the user’s orginal query as the basis for retrieval. Formulating a precise and clear question is difficult, and imprudent queries result in subpar retrieval effectiveness.</p><p>The primary challenges in this stage include:</p><ul><li><strong>Poorly worded queries. </strong>The question itself is complex, and the language is not well-organized.</li><li><strong>language complexity &amp; ambiguity.</strong>Language models often struggle when dealing with specialized vocabulary or ambiguous abbreviations with multiple meanings. For instance, they may not discern whether “LLM” refers to <em>large language model</em> or a <em>Master of Laws</em> in a legal context.</li></ul><h3>Query Expansion</h3><p>Expanding a single query into multiple queries enriches the content of the query, providing further context to address any lack of specific nuances, thereby ensuring the optimal relevance of the generated answers.</p><ul><li><strong><em>Multi-Query</em></strong></li></ul><p>By employing prompt engineering to expand queries via LLMs, these queries can then be executed in parallel. The expansion of queries is not random, but rather meticulously designed. Two crucial criteria for this design are the <strong>diversity</strong> and <strong>coverage</strong> of the queries.</p><p>One of the challenges of using multiple queries is the potential <strong>dilution</strong> of the user’s original intent. To mitigate this, we can instruct the model to assign greater weight to the original query in prompt engineering.</p><ul><li><strong><em>Sub-Query</em></strong></li></ul><p>The process of sub-question planning represents the generation of the necessary sub-questions to contextualize and fully answer the original question when combined. This process of adding relevant context is, in principle, similar to query expansion. Specifically, a complex question can be decomposed into a series of simpler sub-questions using the <strong>l</strong><a href="https://arxiv.org/abs/2205.10625"><strong>east-to-most prompting</strong></a> method.</p><p><a href="https://docs.llamaindex.ai/en/stable/examples/query_engine/sub_question_query_engine.html">Sub Question Query Engine - LlamaIndex 🦙 0.9.36</a></p><ul><li><strong><em>CoVe</em></strong></li></ul><p>Another approach to query expansion involves the use of the<strong> </strong><a href="https://arxiv.org/abs/2309.11495"><strong>Chain-of-Verification(CoVe)</strong></a> proposed by Meta AI. The expanded queries undergo validation by LLM to achieve the effect of reducing hallucinations. Validated expanded queries typically exhibit higher reliability.</p><h3>Query Transformation</h3><blockquote>Retrieve and generate using a transformed query instead of the user’s original query.</blockquote><ul><li><strong><em>Rewrite</em></strong></li></ul><p>The original queries are not always optimal for LLM retrieval, especially in real-world scenarios. Therefore, we can prompt LLM to rewrite the queries. In addition to using LLM for query rewriting, specialized smaller language models, such as <a href="https://arxiv.org/abs/2305.14283"><strong>RRR（Rewrite-retrieve-read)</strong></a>, can also be utilized.</p><p>The implementation of the Query Rewrite method in the Taobao promotion system, known as <a href="https://arxiv.org/abs/2305.14283"><strong>BEQUE:Query Rewriting for Retrieval-Augmented Large Language Models</strong></a>, has notably enhanced recall effectiveness for long-tail queries, resulting in a rise in GMV.</p><ul><li><strong><em>HyDE</em></strong></li></ul><p>When responding to queries, LLM constructs hypothetical documents (assumed answers) instead of directly searching the query and its computed vectors in the vector database. It focuses on embedding similarity from answer to answer rather than seeking embedding similarity for the problem or query. In addition, it also includes <strong>Reverse HyDE</strong>, which focuses on retrieval from query to query.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/1*OH_UOn0D8VlTqpPVQwK3UA.png" /><figcaption>The core idea of bothHyDE and Reverse HyDE is to bridge the map between query and answer.</figcaption></figure><p><a href="https://medium.aiplanet.com/advanced-rag-improving-retrieval-using-hypothetical-document-embeddings-hyde-1421a8ec075a">Advanced RAG — Improving retrieval using Hypothetical Document Embeddings(HyDE)</a></p><ul><li><strong><em>Step-back Prompting</em></strong></li></ul><p>Using the<a href="https://arxiv.org/abs/2310.06117"> Step-back Prompting</a> method proposed by Google DeepMind, the original query is abstracted to generate a high-level concept question (step-back question). In the RAG system, both the step-back question and the original query are used for retrieval, and both the results are utilized as the basis for language model answer generation.</p><p><a href="https://cobusgreyling.medium.com/a-new-prompt-engineering-technique-has-been-introduced-called-step-back-prompting-b00e8954cacb">A New Prompt Engineering Technique Has Been Introduced Called Step-Back Prompting</a></p><h3>Query Routing</h3><p>Based on varying queries, routing to distinct RAG pipeline,which is suitable for a versatile RAG system designed to accommodate diverse scenarios.</p><ul><li><strong><em>Metadata Router/ Filter</em></strong></li></ul><p>The first step involves extracting keywords (entity) from the query, followed by filtering based on the keywords and metadata within the chunks to narrow down the search scope.</p><ul><li><strong><em>Semantic Router</em></strong></li></ul><p>Another method of routing involves leveraging the semantic information of the query. Specific apporch see Semantic Router.Certainly, a hybrid routing approach can also be employed, combining both semantic and metadata-based methods for enhanced query routing.</p><p>Check <a href="https://github.com/aurelio-labs/semantic-router/">Semantic router</a> repo.</p><p><a href="https://medium.com/ai-insights-cobet/beyond-basic-chatbots-how-semantic-router-is-changing-the-game-783dd959a32d">Beyond Basic Chatbots: How Semantic Router is Changing the Game</a></p><h3>Query Construction</h3><p>Converting a user’s query into another query language for accessing alternative data sources. Common methods include:</p><ul><li><strong><em>Text-to-Cypher</em></strong></li><li><strong><em>Text-to-SQL</em></strong></li></ul><p>In many scenarios, structured query languages (e.g., SQL, Cypher) are often used in conjunction with semantic information and metadata to construct more complex queries. For specific details, please refer to the Langchain blog.</p><p><a href="https://blog.langchain.dev/query-construction/">Query Construction</a></p><h3>3 Retrieval</h3><p>The retrieval process plays a crucial role in RAG. Leveraging powerful PLMs enables the effective representation of queries and text in latent spaces, facilitating the establishment of semantic similarity between questions and documents to support retrieval.</p><p>Three main considerations need to be taken into account :</p><ul><li><strong>Retrieval Efficiency</strong></li><li><strong>Embedding Quality</strong></li><li><strong>Alignment of tasks , data and models</strong></li></ul><h3>Retriver Selection</h3><p>Since the release of ChatGPT, there has been a frenzy of development in embedding models.Hugging Face’s<strong> MTEB</strong> leaderboard evaluates nearly all available embedding models across 8 tasks — Clustering,Classification,Bitext Ming, Pair Classification, Reranking, Retrieval, Semantic Text Similarity (STS), and Summarization, covering 58 dataset Additionally, <strong>C-MTEB </strong>focuses on evaluating the capabilities of Chinese embedding models, covering 6 tasks and 35 datasets.</p><p>When constructing RAG applications, there is no one-size-fits-all answer to “which embedding model to use.” However, you may notice that specific embeddings are better suited for particular use cases.</p><p>Check the MTEB/C-MTEB Leaderboard.</p><p><a href="https://huggingface.co/spaces/mteb/leaderboard">MTEB Leaderboard - a Hugging Face Space by mteb</a></p><ul><li><strong><em>Sparse Retriever</em></strong></li></ul><p>While sparse encoding models may be considered a somewhat antiquated technique, often based on statistical methods such as word frequency statistics, they still hold a certain place due to their higher encoding efficiency and stability. Common coefficient encoding models include <strong>BM25</strong> and <strong>TF-IDF.</strong></p><ul><li><strong><em>Dense Retriever</em></strong></li></ul><p>Neural network-based dense encoding models encompass several types:</p><ul><li>Encoder-Decoder language models built on the BERT architecture, such as ColBERT.</li><li>Comprehensive multi-task fine-tuning models like BGE and Baichuan-Text-Embedding.</li><li>Cloud API-based models such as OpenAI-Ada-002 and Cohere Embedding.</li><li>Next-generation accelerated encoding framework Dragon+, designed for large-scale data applications.</li><li><strong><em>Mix/hybrid Retrieval</em></strong></li></ul><p>Two embedding approaches capture different relevance features and can benefit from each other by leveraging complementary relevance information. For instance, sparse retrieval models can be used to provide initial search results for training dense retrieval models. Additionally, PLMs can be utilized to learn term weights to enhance sparse retrieval. Specifically, it also demonstrates that sparse retrieval models can enhance the zero-shot retrieval capability of dense retrieval models and assist dense retrievers in handling queries containing rare entities, thereby improving robustness.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KBSbl59TXMEMzORXbN-3WA.png" /><figcaption>Image from <a href="https://pub.towardsai.net/advanced-rag-techniques-an-illustrated-overview-04d193d8fec6">IVAN ILIN:Advanced RAG Techniques: an Illustrated Overview</a></figcaption></figure><h3>Retriever Fine-tuning</h3><p>In cases where the context may diverge from what the pre-trained model deems similar in the embedding space, particularly in highly specialized fields like healthcare, law, and other domains abundant in proprietary terminology, adjusting the embedding model can address this issue. While this adjustment demands additional effort, it can substantially enhance retrieval efficiency and domain alignment.</p><ul><li><strong><em>SFT</em></strong></li></ul><p>You can construct your own fine-tuning dataset based on domain-specific data, a task that can be swiftly accomplished using LlamaIndex.</p><ul><li><strong><em>LSR (LM-supervised Retriever)</em></strong></li></ul><p>In contrast to directly constructing a fine-tuning dataset from the dataset, LSR utilizes the LM-generated results as supervisory signals to fine-tune the embedding model during the RAG process.</p><ul><li><strong>RL(R</strong>einforcement learning)</li></ul><p>Inspired by RLHF(Reinforcement Learning fromHuman Feedback), utilizing LM-based feedback to reinforce the Retriever through reinforcement learning.</p><ul><li><strong>Adapter</strong></li></ul><p>At times, fine-tuning an entire retriever can be costly, especially when dealing with API-based retrievers that cannot be directly fine-tuned. In such cases, we can mitigate this by incorporating an adapter module and conducting fine-tuning.Another benefit of adding an adapter is the ability to achieve better alignment with specific downstream tasks.</p><ul><li>Task Specific.<a href="https://arxiv.org/pdf/2310.18347.pdf">PRCA: Fitting Black-Box Large Language Models for Retrieval QuestionAnswering via Pluggable Reward-Driven Contextual Adapter.</a></li><li>Task Agnostic.The <a href="https://arxiv.org/abs/2305.17331">AAR(Augmentation -Adapted Retriver)</a> introduces a universal adapter designed to accommodate multiple downstream tasks.</li></ul><h3>4 Post-Retrieval</h3><p>Retrieving entire document chunks and feeding them directly into the LLM’s contextual environment is not an optimal choice. Post-processing the documents can aid LLM in better leveraging the contextual information.</p><p>The primary challenges include:</p><ul><li><a href="https://arxiv.org/abs/2307.03172"><strong>Lost in the middle</strong></a>. Like humans, LLM tends to remember only the beginning and end of long texts, while forgetting the middle portion.</li><li><strong>Noise/anti-fact chunks</strong>. Retrieved noisy or factually contradictory documents can impact the final retrieval generation.</li><li><strong>Context Window.</strong> Despite retrieving a substantial amount of relevant content, the limitation on the length of contextual information in large models prevents the inclusion of all this content.</li></ul><h3>Rerank</h3><p>Rerank the retrieved document chunks without altering their content or length, to enhance the visibility of the more crucial document chunks for LLM. In specific terms：</p><ul><li><strong><em>Rule-base Rerank</em></strong></li></ul><p>According to certain rules, metrics are calculated to rerank chunks. Common metrics include:</p><ul><li>Diversity</li><li>Relevance</li><li>MRR (Maximal Marginal Relevance, 1998)</li></ul><p>The idea behind MMR is to reduce redundancy and increase result diversity, and it is used for text summarization. MMR selects phrases in the final key phrase list based on a combined criterion of query relevance and information novelty.</p><p>Check there rerank implementation in HayStack</p><p><a href="https://towardsdatascience.com/enhancing-rag-pipelines-in-haystack-45f14e2bc9f5">Enhancing RAG Pipelines in Haystack: Introducing DiversityRanker and LostInTheMiddleRanker</a></p><ul><li><strong><em>Model-base Rerank</em></strong></li></ul><p>Utilize a language model to reorder the document chunks, with options including:</p><ul><li>Encoder-Decoder models from the BERT series, such as SpanBERT</li><li>Specialized reranking models, such as <a href="https://txt.cohere.com/rerank/">Cohere rerank</a> or <a href="https://huggingface.co/BAAI/bge-reranker-large">bge-raranker-large</a></li><li>General large language models, such as GPT-4</li></ul><h3>Compression and Selection</h3><p>A common misconception in the RAG process is the belief that retrieving as many relevant documents as possible and concatenating them to form a lengthy retrieval prompt is beneficial. However, excessive context can introduce more noise, diminishing the LLM’s perception of key information and leading to issues such as “ lost in the middle” . A common approach to address this is to compress and select the retrieved content.</p><ul><li><strong><em>（Long)LLMLingua</em></strong></li></ul><p>By utilizing aligned and trained small language models, such as GPT-2 Small or LLaMA-7B, the detection and removal of unimportant tokens from the prompt is achieved, transforming it into a form that is challenging for humans to comprehend but well understood by LLMs. This approach presents a direct and practical method for prompt compression, eliminating the need for additional training of LLMs while balancing language integrity and compression ratio.</p><p>check the <a href="https://llmlingua.com">LLMLingua project</a>.</p><p><a href="https://wyydsb.xin/NLP/LLMLingua_en.html">LLMLingua | Explore the special language for LLMs via Prompt Compression</a></p><ul><li><strong><em>Recomp</em></strong></li></ul><p><a href="https://arxiv.org/pdf/2310.04408.pdf">Recomp</a> introduces two types of compressors: an <strong>extractive compressor</strong> that selects pertinent sentences from retrieved documents, and an <strong>abstractive compressor</strong> that produces concise summaries by amalgamating information from multiple documents. Both compressors are trained to enhance the performance of language models on end tasks when the generated summaries are prepended to the language models’ input, while ensuring the conciseness of the summary. In cases where the retrieved documents are irrelevant to the input or do not provide additional information to the language model, compressor can return an empty string, thereby implementing selective augmentation.</p><ul><li><strong><em>Selective Context</em></strong></li></ul><p>By <strong>identifying and removing redundant content in the input context</strong>, the input can be streamlined, thus improving the language model’s reasoning efficiency. <a href="https://aclanthology.org/2023.emnlp-main.391.pdf">Selective Context</a> is akin to a “stop-word removal” strategy. In practice, selective context assesses the information content of lexical units based on the self-information computed by the base language model. By retaining content with higher self-information, this method offers a more concise and efficient textual representation for language model processing, without compromising their performance across diverse applications. However, it overlooks the interdependence between compressed content and the alignment between the targeted language model and the small language model utilized for prompting compression.</p><ul><li><strong><em>Tagging-Filter</em></strong></li></ul><p>Tagging is a relatively intuitive and straightforward approach. Specifically, the documents are first labeled, and then filtered based on the metadata of the query.</p><p><a href="https://python.langchain.com/docs/use_cases/tagging">Tagging | 🦜️🔗 Langchain</a></p><ul><li><strong>LLM-Critique</strong></li></ul><p>Another straightforward and effective approach involves having the LLM evaluate the retrieved content before generating the final answer. This allows the LLM to filter out documents with poor relevance through LLM critique. For instance, in <a href="https://arxiv.org/pdf/2306.16092.pdf">Chatlaw</a>, the LLM is prompted to self-suggestion on the referenced legal provisions to assess their relevance.</p><h3>5 Generation</h3><p>Utilize the LLM to generate answers based on the user’s query and the retrieved context information.</p><h3>Generator Selection</h3><p>Depending on the scenario, the choice of LLM can be categorized into the following two types:</p><ul><li><strong><em>Cloud API-base Generator</em></strong></li></ul><p>Cloud API-based Utilize third-party LLMs by invoking their APIs, such as OpenAI’s ChatGPT, GPT-4, and Anthropic Claude, among others. <strong>Benefits:</strong></p><ul><li>No server pressure</li><li>High concurrency</li><li>Ability to use more powerful models</li></ul><p><strong>Drawbacks:</strong></p><ul><li>Data passes through third parties, leading to data privacy concerns</li><li>Inability to adjust the model (in the vast majority of cases)</li><li><strong><em>On-Premises</em></strong></li></ul><p>Locally deployed open-source or self-developed LLMs, such as the Llama series, GLM, and others.The advantages and disadvantages are opposite to those of Cloud API-based models. Locally deployed models offer greater flexibility and better privacy protection but require higher computational resources.</p><h3>Generator Fine-tuning</h3><p>In addition to directl LLM usage, targeted fine-tuning based on the scenario and data characteristics can yield better results. This is also one of the greatest advantages of using an on-premise setup. Common fine-tuning methods include the following:</p><ul><li><strong><em>SFT</em></strong></li></ul><p>When LLMs lack data in a specific domain, additional knowledge can be provided to the LLM through fine-tuning. Huggingface’s fine-tuning data can also be used as an initial step.</p><p>Another benefit of fine-tuning is the ability to adjust the model’s input and output. For example, it can enable LLM to adapt to specific data formats and generate responses in a particular style as instructed.</p><ul><li><strong><em>RL</em></strong></li></ul><p>Aligning LLM outputs with human or retriever preferences through reinforcement learning is a potential approach. For instance, manually annotating the final generated answers and then providing feedback through reinforcement learning. In addition to aligning with human preferences, it is also possible to align with the preferences of fine-tuned models and retrievers.</p><ul><li><strong><em>Distillation</em></strong></li></ul><p>When circumstances prevent access to powerful proprietary models or larger parameter open-source models, a simple and effective method is to distill the more powerful models(e.g. GPT-4).</p><ul><li><strong><em>Dual FT</em></strong></li></ul><p>Fine-tuning both Generator and Retriever to align their preferences. A typical approach, such as <a href="https://arxiv.org/pdf/2310.01352.pdf"><em>RA-DIT</em></a>, aligns the scoring functions between Retriever and Generator using KL divergence.</p><h3>6 Orchestration</h3><p>Orchestration refers to the modules used to control the RAG process. RAG no longer follows a fixed process, and it involves making decisions at key points and dynamically selecting the next step based on the results. This is also one of the key features of modularized RAG compared to Naive RAG.</p><h3>Scheduling</h3><p>The Judge module assesses critical point in the RAG process, determining the need to retrieve external document repositories, the satisfaction of the answer, and the necessity of further exploration. It is typically used in recursive, iterative, and adaptive retrieval. Specifically, it mainly includes the following two operators:</p><ul><li><strong><em>Rule-base</em></strong></li></ul><p>The next course of action is determined based on predefined rules. Typically, the generated answers are scored, and then the decision to continue or stop is made based on whether the scores meet predefined thresholds. Common thresholds include confidence levels for tokens.</p><ul><li><strong><em>Prompt-base</em></strong></li></ul><p>LLM autonomously determines the next course of action. There are primarily two approaches to achieve this. The first involves prompting LLM to reflect or make judgments based on the conversation history, as seen in the ReACT framework. The benefit here is the elimination of the need for fine-tuning the model. However, the output format of the judgment depends on the LLM’s adherence to instructions. A prompt-base case is<a href="https://arxiv.org/pdf/2305.06983.pdf"> FLARE</a>.</p><ul><li><strong><em>Tuning-base</em></strong></li></ul><p>The second approach entails LLM generating specific tokens to trigger particular actions, a method that can be traced back to Toolformer and is applied in RAG, such as in <a href="https://arxiv.org/pdf/2310.11511.pdf">Self-RAG</a>.</p><h3>Fusion</h3><p>This concept originates from RAG Fusion. As mentioned in the previous section on <em>Query Expansion</em>, the current RAG process is no longer a singular pipeline. It often requires the expansion of retrieval scope or diversity through multiple branches. Therefore, following the expansion to multiple branches, the Fusion module is relied upon to merge multiple answers.</p><ul><li><strong><em>Possibility Ensemble</em></strong></li></ul><p>The fusion method is based on the weighted values of different tokens generated from multiple beranches, leading to the comprehensive selection of the final output. Weighted averaging is predominantly employed. See <a href="https://arxiv.org/pdf/2301.12652.pdf">REPLUG</a>.</p><ul><li><strong>RRF (Reciprocal Rank Fusion )</strong></li></ul><p>RRF, is a technique that combines the rankings of multiple search result lists to generate a single unified ranking. Developed in collaboration with the University of Waterloo (CAN) and Google, RRF produces results that are more effective than reordering chunks under any single branch.</p><ul><li><a href="https://towardsdatascience.com/forget-rag-the-future-is-rag-fusion-1147298d8ad1">Forget RAG, the Future is RAG-Fusion</a></li><li><a href="https://pub.towardsai.net/advanced-rag-techniques-an-illustrated-overview-04d193d8fec6">Advanced RAG Techniques: an Illustrated Overview</a></li></ul><p><strong>Conclusion</strong></p><p>The upcoming content on RAG Flow will be introduced in PART II, to be published soon.</p><p>As this is my first time publishing an article on Medium, I am still getting familiar with many features. Any feedback and criticism are welcome.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e69b32dc13a3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>