用Helicone监控Ragas评估RAG系统的集成方法

该资料说明如何把Helicone接入Ragas的RAG评估流程,通过配置写入型API密钥,让评估期间产生的模型调用自动记录到Helicone面板,便于查看调用次数、延迟与错误等信息。

## 希利卡内 该笔记本演示了如何将希利酮与拉加斯结合,用于监测和评估RAG(检索-增强生成)系统. ## 先决条件 在开始前,请确保您有希利酮账户和 API 密钥: 1. 登录到 [希利卡内](<https://www.helicone.ai/>) 或创建账户,如果你没有。 2. 登入后,航行到 [开发者区域](<https://helicone.ai/developer>) 生成 API 密钥。 **说明**: 确保生成只写 API 密钥。关于希利酮认证的更多信息,请参见: [Helicone Auth 文档](<https://docs.helicone.ai/getting-started/helicone-api-keys>). 安全地储存你的Helicone API 密钥, 因为你需要它来整合。 ## 设置 首先,我们安装所需的软件包,建立我们的环境。 ``` !pip install datasets ragas openai ``` ``` import os from datasets import Dataset from ragas import evaluate from ragas.integrations.helicone import helicone_config # import helicone_config from ragas.metrics import answer_relevancy, context_precision, faithfulness # Set up Helicone HELICONE_API_KEY = ( "your_helicone_api_key_here" # Replace with your actual Helicone API key ) helicone_config.api_key = HELICONE_API_KEY os.environ["OPENAI_API_KEY"] = ( "your_openai_api_key_here" # Replace with your actual OpenAI API key ) # Verify Helicone API key is set if HELICONE_API_KEY == "your_helicone_api_key_here": raise ValueError( "Please replace 'your_helicone_api_key_here' with your actual Helicone API key." ) ``` ## 准备数据 让我们准备一些样本数据 用于我们的RAG系统评估。 ``` data_samples = { "question": ["When was the first Super Bowl?", "Who has won the most Super Bowls?"], "answer": [ "The first Super Bowl was held on January 15, 1967.", "The New England Patriots have won the most Super Bowls, with six championships.", ], "contexts": [ [ "The First AFL–NFL World Championship Game, later known as Super Bowl I, was played on January 15, 1967, at the Los Angeles Memorial Coliseum in Los Angeles, California." ], [ "As of 2021, the New England Patriots have won the most Super Bowls with six championships, all under the leadership of quarterback Tom Brady and head coach Bill Belichick." ], ], "ground_truth": [ "The first Super Bowl was held on January 15, 1967.", "The New England Patriots have won the most Super Bowls, with six championships as of 2021.", ], } dataset = Dataset.from_dict(data_samples) print(dataset) ``` ## 与 Ragas 评价 现在,让我们用Ragas来评估我们的RAG系统. Helicone将自动登录本次评估期间的API通话. ``` # Evaluate using Ragas score = evaluate(dataset, metrics=[faithfulness, answer_relevancy, context_precision]) # Display results print(score.to_pandas()) ``` ## 查看希利科内的结果 RAGAS评价期间的API通话自动在Helicone中登录。您可以在Helicone仪表板中查看这些日志,以便深入了解您的RAG系统的性能和行为。 查看结果:1。 [希利酮仪表板](<https://www.helicone.ai/dashboard>) 2. 导航到“ 请求” 部分 3 。 您应该看到在 Ragas 评估期间的 API 呼叫 您可以分析这些日志以了解: - 评估期间的API通话次数 - 每次通话的性能(纬度,使用的令牌等) - 评估期间发生的任何错误或问题. 这种集成使你能够将拉加斯用于RAG系统评价的力量与赫利科内强大的监测和分析能力结合起来. 12月 16, 2025 12月 16, 2025

查看原始来源