追踪 LlamaIndex🦙
LlamaIndex 是一个开源框架,用于构建代理式生成式 AI 应用程序,允许大型语言模型以任何格式处理您的数据。
MLflow 追踪 为 LlamaIndex 提供了自动追踪功能。您可以通过调用 mlflow.llama_index.autolog()
函数来启用 LlamaIndex 的追踪,当 LlamaIndex 引擎和工作流被调用时,嵌套的追踪将自动记录到当前活跃的 MLflow Experiment 中。
import mlflow
mlflow.llama_index.autolog()
提示
MLflow LlamaIndex 集成不仅提供追踪功能。MLflow 为 LlamaIndex 提供了完整的追踪体验,包括模型追踪、索引管理和评估。请查看 MLflow LlamaIndex Flavor 以了解更多信息!
使用示例
首先,让我们下载测试数据来创建一个玩具索引
!mkdir -p data
!curl -L https://raw.githubusercontent.com/run-llama/llama_index/main/docs/docs/examples/data/paul_graham/paul_graham_essay.txt -o ./data/paul_graham_essay.txt
将它们加载到一个简单的内存向量索引中
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
documents = SimpleDirectoryReader("data").load_data()
index = VectorStoreIndex.from_documents(documents)
现在您可以启用 LlamaIndex 自动追踪并开始查询索引
import mlflow
# Enabling tracing for LlamaIndex
mlflow.llama_index.autolog()
# Optional: Set a tracking URI and an experiment
mlflow.set_tracking_uri("http://localhost:5000")
mlflow.set_experiment("LlamaIndex")
# Query the index
query_engine = index.as_query_engine()
response = query_engine.query("What was the first program the author wrote?")
LlamaIndex 工作流
Workflow
是 LlamaIndex 的下一代生成式 AI 编排框架。它被设计为一个灵活且可解释的框架,用于构建任意 LLM 应用程序,例如代理、RAG 流程、数据提取管道等。MLflow 支持追踪、评估和追踪 Workflow 对象,使它们更具可观测性和可维护性。
通过调用相同的 mlflow.llama_index.autolog()
,LlamaIndex 工作流的自动追踪功能可直接使用。
要了解有关 MLflow 与 LlamaIndex Workflow 集成的更多信息,请继续阅读以下教程
禁用自动追踪
通过调用 mlflow.llama_index.autolog(disable=True)
或 mlflow.autolog(disable=True)
,可以在全局范围内禁用 LlamaIndex 的自动追踪。