Prompt RAG 是一種類似于傳統 RAG 的方法,但其獨特之處在于無需使用向量數據庫或嵌入技術。傳統 RAG 的工作流程包括以下步驟:
相比之下,Prompt RAG 直接通過文檔目錄(ToC)檢索相關內容,并將其作為上下文注入到提示中,從而生成響應。此方法不僅簡化了實現流程,還能有效減少對復雜數據管理框架的依賴。
在 Prompt RAG 中,第一步是創建文檔目錄(ToC)。目錄的生成方式包括以下幾種:
通過刪除頁眉、頁腳和頁碼等無關元素,可以減少文檔的令牌大小,從而優化 LLM 的上下文窗口利用率。
Prompt RAG 的提示包含用戶查詢和文檔目錄(ToC)。LLM 會根據提示從目錄中選擇與查詢最相關的標題。優化提示的設計對于提高檢索準確性和令牌使用效率至關重要。
以下是一個用于選擇標題的提示示例:
Current context: {history}
Question: {question}Table of Contents: {index}Each heading (or line) in the table of contents above represents a fraction
in a document. Select the five headings that help the best to find out the
information for the question. List the headings in the order of importance
and in the format of
'1. ---
2. ---
---
5. ---'.Don't say anything other than the format.If the question is about greetings or casual talks, just say
'Disregard the reference.'
根據選定的標題,Prompt RAG 會提取相應的文檔部分,并將其作為上下文注入到提示中。注入的內容大小必須小于 LLM 的上下文窗口限制。為滿足這一要求,可以對內容進行總結、截斷或其他形式的優化。
以下是生成答案的提示示例:
Answer in {Language of Choice}:
Here is a record of previous conversations:
{history}
Reference: {context}
Question: {question}
Use the reference to answer the question.
The reference above is only fractions of ''.
Be informative, gentle, and formal.
If you can't answer the question with the reference, just say like
'I couldn't find the right answer this time'.
Answer in {Language of Choice}:
Prompt RAG 的研究為無向量化檢索提供了一種創新思路,即使在某些場景中無法單獨使用,其方法仍可作為更大實現框架中的一個子集。通過優化提示工程,Prompt RAG 能夠在無需復雜數據管理的情況下實現高效的檢索和生成。
Prompt RAG 通過創新的無向量化方法,為檢索增強生成(RAG)提供了新的實現路徑。盡管其在擴展性和復雜場景中的表現不如傳統 RAG,但在小規模實現和特定領域優化中具有顯著優勢。未來,Prompt RAG 的發展可能需要結合應用框架,以更好地管理數據流和優化提示工程,從而進一步提升其實用性。
原文鏈接: https://blog.kore.ai/cobus-greyling/prompt-rag-vector-embedding-free-retrieval-augmented-generation