开源库为检索增强生成系统提供自动化评估方案,程序员可用来快速验证 RAG 应用效果。
文档 | 快速开始 | 加入 Discord | 博客 | 通讯 | 招聘
为 LLM 应用提供客观指标、智能测试生成和数据驱动的洞察
Ragas 是评估和优化大型语言模型(LLM)应用的终极工具包。告别耗时的、主观的评估,迎接数据驱动、高效的评估工作流。还没有准备好测试数据集?我们也提供生产对齐的测试集生成。
🎯 客观指标:使用基于 LLM 和传统指标,精确评估你的 LLM 应用。
🧪 测试数据生成:自动创建全面的测试数据集,覆盖各种场景。
🔗 无缝集成:与 LangChain 等流行 LLM 框架和主流可观测性工具完美协作。
📊 构建反馈循环:利用生产数据不断改进你的 LLM 应用。
pip install ragas
或者从源代码安装:
pip install git+https://github.com/vibrantlabsai/ragas
最快开始的方法是使用 ragas quickstart 命令:
# 列出可用模板
ragas quickstart
# 创建一个 RAG 评估项目
ragas quickstart rag_eval
# 指定创建位置
ragas quickstart rag_eval -o ./my-project
rag_eval - 评估 RAG 系统
agent_evals - 评估 AI agents
benchmark_llm - 对 LLM 进行基准测试和对比
prompt_evals - 评估 prompt 变体
workflow_eval - 评估复杂工作流
ragas 为常见评估任务提供预构建的指标。例如,Aspect Critique 可以使用 DiscreteMetric 评估输出的任何方面:
import asyncio
from openai import AsyncOpenAI
from ragas.metrics import DiscreteMetric
from ragas.llms import llm_factory
# Setup your LLM
client = AsyncOpenAI()
llm = llm_factory("gpt-4o", client=client)
# Create a custom aspect evaluator
metric = DiscreteMetric(
name="summary_accuracy",
allowed_values=["accurate", "inaccurate"],
prompt="""Evaluate if the summary is accurate and captures key information.
Response: {response}
Answer with only 'accurate' or 'inaccurate'."""
)
# Score your application's output
async def main():
score = await metric.ascore(
llm=llm,
response="The summary of the text is..."
)
print(f"Score: {score.value}") # 'accurate' or 'inaccurate'
print(f"Reason: {score.reason}")
if __name__ == "__main__":
asyncio.run(main())
注意:确保设置了 OPENAI_API_KEY 环境变量。
查看完整的快速开始指南
在过去的 2 年里,我们看到并帮助改进了许多使用评估的 AI 应用。如果你想要帮助改进和扩展 AI 应用的评估,
🔗 预约一个时间段或给我们写信:founders@vibrantlabs.com。
如果你想更多地参与 Ragas,请查看我们的 Discord 服务器。这是一个有趣的社区,我们在这里讨论 LLM、检索、生产问题等。
+----------------------------------------------------------------------------+
| +----------------------------------------------------------------+ |
| | Developers: Those who built with `ragas`. | |
| | (You have `import ragas` somewhere in your project) | |
| | +----------------------------------------------------+ | |
| | | Contributors: Those who make `ragas` better. | | |
| | | (You make PR to this repo) | | |
| | +----------------------------------------------------+ | |
| +----------------------------------------------------------------+ |
+----------------------------------------------------------------------------+
我们欢迎来自社区的贡献!无论是 bug 修复、功能添加还是文档改进,你的想法都很有价值。
创建你的特性分支 (git checkout -b feature/AmazingFeature)
提交你的改动 (git commit -m 'Add some AmazingFeature')
推送到分支 (git push origin feature/AmazingFeature)
在 Ragas,我们相信透明度。我们收集最少的、匿名的使用数据来改进我们的产品并指导我们的开发工作。
✅ 无个人或公司身份识别信息
✅ 开源数据收集代码
✅ 公开可用的汇总数据
要选择退出,设置 RAGAS_DO_NOT_TRACK 环境变量为 true。
@misc{ragas2024,
author = {VibrantLabs},
title = {Ragas: Supercharge Your LLM Application Evaluations},
year = {2024},
howpublished = {\url{https://github.com/vibrantlabsai/ragas}},
}