Retrieval-Augmented Generation

Introduction to RAG, LlamaIndex, examples.


RAG (檢索增強生成)

blog: RAG 檢索增強生成— 讓大型語言模型更聰明的秘密武器


RAG Survey

Paper: Retrieval-Augmented Generation for Large Language Models: A Survey
Paper: Retrieval-Augmented Generation for AI-Generated Content: A Survey
Paper: A Survey on Retrieval-Augmented Text Generation for Large Language Models
Paper: RAG and RAU: A Survey on Retrieval-Augmented Language Model in Natural Language Processing
Paper: A Survey on RAG Meeting LLMs: Towards Retrieval-Augmented Large Language Models
Paper: Evaluation of Retrieval-Augmented Generation: A Survey
Paper: Retrieval-Augmented Generation for Natural Language Processing: A Survey
Paper: Graph Retrieval-Augmented Generation: A Survey
Paper: RAG and Beyond: A Comprehensive Survey on How to Make your LLMs use External Data More Wisely
Paper: A Comprehensive Survey of Retrieval-Augmented Generation (RAG): Evolution, Current Landscape and Future Directions


A Guide on 12 Tuning Strategies for Production-Ready RAG Applications


NLP • Retrieval Augmented Generation


BGE (BAAI General Embedding)

Code: https://github.com/FlagOpen/FlagEmbedding


EAGLE-LLM

3X faster for LLM
Blog: EAGLE: Lossless Acceleration of LLM Decoding by Feature Extrapolation
Code: https://github.com/SafeAILab/EAGLE
Kaggle: https://www.kaggle.com/code/rkuo2000/eagle-llm


PurpleLlama CyberSecEval

Paper: PurpleLlama CyberSecEval: A Secure Coding Benchmark for Language Models
Code: CybersecurityBenchmarks
meta-llama/LlamaGuard-7b

Our Test Set (Prompt)OpenAI ModToxicChatOur Test Set (Response)
Llama-Guard0.9450.8470.6260.953
OpenAI API 0.7640.8560.5880.769
Perspective API0.7280.7870.5320.699

Contextual Retrieval RAG

Anthropic Prompt Caching

Standard RAG

Contextual Retrieval RAG

Blog: Implementing Contextual Retrieval in RAG pipeline


Frameworks

LlamaIndex

Code: https://github.com/run-llama/llama_index
Docs:


LangChain

  • langchain-core: Base abstractions and LangChain Expression Language.
  • Integration packages (e.g. langchain-openai, langchain-anthropic, etc.): Important integrations have been split into lightweight packages that are co-maintained by the LangChain team and the integration developers.
  • langchain: Chains, agents, and retrieval strategies that make up an application’s cognitive architecture.
  • langchain-community: Third-party integrations that are community maintained.
  • LangGraph: Build robust and stateful multi-actor applications with LLMs by modeling steps as edges and nodes in a graph. Integrates smoothly with LangChain, but can be used without it. To learn more about LangGraph, check out our first LangChain Academy course, Introduction to LangGraph, available here.
  • LangGraph Platform: Deploy LLM applications built with LangGraph to production.
  • LangSmith: A developer platform that lets you debug, test, evaluate, and monitor LLM applications.

Kaggle: https://www.kaggle.com/code/rkuo2000/rag-with-langchain


RAG with MATLAB


Building RAG-based LLM Applications for Production

https://github.com/ray-project/llm-applications/blob/main/notebooks/rag.ipynb
(1)將外部文件做分塊(chunking)再分詞(tokenize)轉成token
(2)利用嵌入模型,將token做嵌入(embeds)運算,轉成向量,儲存至向量資料庫(Vector Database)並索引(Indexes)
(3)用戶提出問題,向量資料庫將問題字串轉成向量(利用前一個步驟的嵌入模型),再透過餘弦(Cosine)相似度或歐氏距離演算法來搜尋資料庫裡的近似資料
(4)將用戶的問題、資料庫查詢結果一起放進Prompt(提示),交由LLM推理出最終答案
以上是基本的RAG流程,利用Langchain或LlamaIndex或Haystack之類的應用程式開發框架,大概用不到一百行的程式碼就能做掉(含LLM的裝載)。

Anyscale剛剛發布的一篇精彩好文,裡頭介紹了很多提升RAG成效的高段技巧,內容包括:
🚀從頭開始建構基於RAG的LLM應用程式。
🚀 在具有不同運算資源的多個工作人員之間擴展主要工作負載(載入、分塊、嵌入、索引、服務等)。
🚀評估應用程式的不同配置,以最佳化每個元件(例如retrieval_score)和整體效能(quality_score)。
🚀 透過開源和閉源LLM實作混合代理路由方法,以建立效能最佳且最具成本效益的應用程式。
🚀以高擴展性與高可用性的方式為應用程式提供服務。
🚀了解微調、提示工程、詞彙搜尋(lexical search)、重新排名、資料飛輪(data flywheel)等方法如何影響應用程式的效能。


CRAG

Paper: Corrective Retrieval Augmented Generation
Blog: CRAG: 檢索增強生成的糾錯機制 - 提升大型語言模型問答精確度
Code: https://github.com/HuskyInSalt/CRAG


GRAG

Paper: From Local to Global: A Graph RAG Approach to Query-Focused Summarization
Paper: GRAG: Graph Retrieval-Augmented Generation
Blog: GraphRAG: Unlocking LLM discovery on narrative private data
Blog: Knowledge Graph + RAG | Microsoft GraphRAG 實作與視覺化教學
Code: https://github.com/microsoft/graphrag
Code: GraphRAG Accelerator


HippoRAG

Paper: HippoRAG: Neurobiologically Inspired Long-Term Memory for Large Language Models
Code: https://github.com/OSU-NLP-Group/HippoRAG


TAG (Table-Augmented Generation)

Paper: Text2SQL is Not Enough: Unifying AI and Databases with TAG
Blog: Goodbye, Text2SQL: Why Table-Augmented Generation (TAG) is the Future of AI-Driven Data Queries!
Code: https://github.com/TAG-Research/TAG-Bench


Groq(Llava) + Qwen2-VL

Blog: Implement Multimodal RAG with ColPali and Vision Language Model Groq(Llava) and Qwen2-VL


MemoRAG

paper: MemoRAG: Moving towards Next-Gen RAG Via Memory-Inspired Knowledge Discovery
Code: https://github.com/qhjqhj00/MemoRAG


VisRAG

Paper: VisRAG: Vision-based Retrieval-augmented Generation on Multi-modality Documents
Code: https://github.com/openbmb/visrag



This site was last updated December 15, 2024.