Skip to Content
Databricks 上生成式人工智能的实用 MLflow 指南 (Chinese Edition)
book

Databricks 上生成式人工智能的实用 MLflow 指南 (Chinese Edition)

by Nuwan Ganganath, Julie Nguyen, Chang Shi Lim
August 2026
Intermediate
336 pages
4h 30m
Chinese
O'Reilly Media, Inc.
Content preview from Databricks 上生成式人工智能的实用 MLflow 指南 (Chinese Edition)

第 5 章. 用于生成式人工智能应用可观测性的MLflow 追踪

本作品已使用人工智能进行翻译。欢迎您提供反馈和意见:translation-feedback@oreilly.com

在第 4 章中,我们构建了一个调用工具的代理,用于回答关于 Unity Airways 的常见问题。这是一个相对简单的架构,由两个组件构成:向量数据库和 LLM。但即使在这种简单的架构下,我们与从业者合作时的经验表明,许多人仍难以调试质量问题。他们清楚一些典型的陷阱,例如文档分块不佳、检索能力薄弱或 prompt 设计不当。 然而,我们发现真正的挑战往往在于缺乏能够帮助他们系统地诊断和解决这些质量问题的工具。

这正是的MLflow Tracing能够发挥真正作用的地方。基于开放标准构建的MLflow Tracing,可捕获生成式AI应用程序每个步骤的详细信息。这使您能够:

  • 检查代理的每个步骤和行为。

  • 精确定位错误和意外行为的根源。

  • 评估并提升应用程序质量。

  • 监控性能并优化成本。

随着行业开始构建由多个组件组成的更复杂的代理式应用程序(第 7 章将进一步探讨),相比第4 章中的简单示例,追踪正变得越来越重要。

在本章中,我们将介绍 MLflow 追踪的基础知识,这对您生成式 AI 应用程序的可观测性至关重要。

了解 MLflow 追踪

的MLflow追踪旨在提供一种工具,用于详细追踪和可视化进入您生成式AI(GenAI)应用程序的请求,在请求穿梭于各个组件的过程中捕获每个步骤的关键信息,其最终目标是提升可观测性。 例如,在第 4 章中的工具调用代理中,MLflow 追踪可以记录输入问题、用于向量数据库检索的查询、检索到的信息块、发送给 LLM 的 prompt 以及最终响应。通过捕获和可视化这些信息,从业者可以轻松调试并理解应用程序中可能出现的问题。图 5-1说明了这一过程。

Diagram illustrating the information capture process in an MLflow tracing system for a tool-calling agent, showing the flow from a user's question through an LLM, agent loop, and vector search tool, with annotations for capturing input, output, and execution details.
图 5-1. 调用工具的代理在跟踪中应捕获的信息示例

虽然 这听起来可能与传统软件应用开发中的日志记录类似——即通过配置应用程序代码来捕获日志以增强可观测性——但这两种方法之间仍存在一些细微差别。表 5-1描述了这些差异。

表 5-1. 日志记录与追踪的区别
  日志记录 跟踪
目的 捕获应用程序中的离散事件。 每个跟踪记录都会捕获一个传入请求的端到端路径。
上下文 本身不会显示事件之间的关系。 在整个跟踪过程中保持上下文,展示每个步骤中的交互情况。
性能监控 延迟等指标不会直接记录在日志中。相反,需要对日志进行进一步处理才能得出这些指标。 无需额外配置即可自动捕获关键指标。

话虽如此,日志记录和追踪通常会结合使用。例如,在作为 REST API 端点部署的生成式 AI 应用中,日志记录会捕获构建进度、身份验证和授权状态、健康检查以及 API 端点的其他运行细节等单个事件。而追踪则会追踪每个传入请求的端到端路径,全面展示该请求与应用中不同组件的交互情况。

在为我们的生成式人工智能(GenAI)应用程序配置追踪功能之前,让我们先回顾一下 MLflow 追踪中的核心概念。

跟踪

如前所述,MLflowTrace对象会捕获请求在 GenAI 应用程序中流经各个组件时的端到端路径。在 MLflow 中,每个追踪由两个组件组成:TraceInfo和

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

人工智能系统性能工程 (Chinese Edition)

人工智能系统性能工程 (Chinese Edition)

Chris Fregly

Publisher Resources

ISBN: 0642572444167