追踪 LlamaIndex🦙
LlamaIndex 是一个开源框架,用于构建智能体生成式AI应用程序,允许大型语言模型处理您任何格式的数据。
MLflow 追踪 为 LlamaIndex 提供自动追踪能力。您可以通过调用 mlflow.llama_index.autolog()
函数来为 LlamaIndex 启用追踪,并且在调用 LlamaIndex 引擎和工作流时,嵌套追踪会自动记录到活动的 MLflow 实验中。
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("https://: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 的下一代 GenAI 编排框架。它被设计为一个灵活且可解释的框架,用于构建任意 LLM 应用程序,例如智能体、RAG 流程、数据提取管道等。MLflow 支持对 Workflow 对象进行跟踪、评估和追踪,这使得它们更具可观测性和可维护性。
通过调用相同的 mlflow.llama_index.autolog()
,LlamaIndex 工作流的自动追踪功能即可开箱即用。
要了解更多关于 MLflow 与 LlamaIndex Workflow 集成的信息,请继续阅读以下教程
禁用自动跟踪
通过调用 mlflow.llama_index.autolog(disable=True)
或 mlflow.autolog(disable=True)
,可以全局禁用 LlamaIndex 的自动追踪功能。