解决检索增强生成的核心挑战
原文地址:archive.is/bNbZo
- Pain Point 1: Missing Content 内容缺失
- Pain Point 2: Missed the Top Ranked Documents 错过排名靠前的文档
- Pain Point 3: Not in Context — Consolidation Strategy Limitations 不在上下文中 — 整合战略的局限性
- Pain Point 4: Not Extracted 未提取
- Pain Point 5: Wrong Format 格式错误
- Pain Point 6: Incorrect Specificity 不正确的具体性
- Pain Point 7: Incomplete 不完整
- Pain Point 8: Data Ingestion Scalability 数据摄入的可扩展性
- Pain Point 9: Structured Data QA 结构化数据QA
- Pain Point 10: Data Extraction from Complex PDFs 从复杂PDF中提取数据
- Pain Point 11: Fallback Model(s) 回退模型
- Pain Point 12: LLM Security LLM安全
受Barnett等人的论文《设计检索增强生成系统时的七个故障点》的启发,让我们在本文中探讨论文中提到的七个失效点以及开发RAG管道时的五个额外常见痛点。更重要的是,我们将深入研究这些RAG痛点的解决方案,以便在日常RAG开发中更好地解决这些痛点。
我用“痛点”而不是“失败点”,主要是因为这些点都有相应的解决方案。让我们试着在它们成为RAG管道中的故障之前进行修复。
首先,让我们研究一下上述论文中提到的七个痛点;请参阅下图。然后,我们将添加另外五个痛点及其建议的解决方案。
痛点1:内容缺失
当实际答案不在知识库中时,RAG系统提供了一个看似合理但不正确的答案,而不是说它不知道。用户收到误导性信息,导致沮丧。
我们提出了两种解决方案:清理数据,更好的提示
- 清理数据
垃圾进,垃圾出。如果你的源数据质量很差,比如包含冲突信息,无论你构建的RAG管道有多好,它都无法从你提供的垃圾中输出黄金。这个拟议的解决方案不仅适用于这个痛点,也适用于本文中列出的所有痛点。干净的数据是任何运行良好的RAG管道的先决条件。
- 更好的提示
在由于知识库中缺乏信息而导致系统可能提供看似合理但不正确的答案的情况下,更好的提示会有很大帮助。通过用“如果你不确定答案,告诉我你不知道”等提示来指导系统,你鼓励模型承认其局限性,并更透明地传达不确定性。无法保证100%的准确性,但制作提示是清理数据后所能做的最大努力之一。
痛点2:错过排名靠前的文档
重要文档可能不会出现在系统检索组件返回的顶部结果中。忽略了正确的答案,导致系统无法提供准确的响应。该报暗示,“问题的答案在文档中,但排名不够高,无法返回给用户”。
我想到了两个建议的解决方案:chunk_size和similarity_top_k的超参数调整
chunk_size和similarity_top_k都是用于管理RAG模型中数据检索过程的效率和有效性的参数。调整这些参数可能会影响计算效率和检索信息质量之间的权衡。我们在上一篇文章《使用LlamaIndex自动进行超参数调整》中探讨了chunk_size和similarity_top_k的超参数调整细节。请参阅下面的示例代码片段。
param_tuner = ParamTuner(
param_fn=objective_function_semantic_similarity,
param_dict=param_dict,
fixed_param_dict=fixed_param_dict,
show_progress=True,
)
results = param_tuner.tune()
函数objective_function_semantic_eximality定义如下,param_dict包含参数chunk_size和top_k及其相应的建议值:
# contains the parameters that need to be tuned
param_dict = {"chunk_size": [256, 512, 1024], "top_k": [1, 2, 5]}
# contains parameters remaining fixed across all runs of the tuning process
fixed_param_dict = {
"docs": documents,
"eval_qs": eval_qs,
"ref_response_strs": ref_response_strs,
}
def objective_function_semantic_similarity(params_dict):
chunk_size = params_dict["chunk_size"]
docs = params_dict["docs"]
top_k = params_dict["top_k"]
eval_qs = params_dict["eval_qs"]
ref_response_strs = params_dict["ref_response_strs"]
# build index
index = _build_index(chunk_size, docs)
# query engine
query_engine = index.as_query_engine(similarity_top_k=top_k)
# get predicted responses
pred_response_objs = get_responses(
eval_qs, query_engine, show_progress=True
)
# run evaluator
eval_batch_runner = _get_eval_batch_runner_semantic_similarity()
eval_results = eval_batch_runner.evaluate_responses(
eval_qs, responses=pred_response_objs, reference=ref_response