Phoenix 过滤器表达式在跨度、追踪与会话三个层面的用法

Phoenix 把 Python 布尔表达式编译成数据库查询,用于在界面过滤栏或 API 中缩小结果集。跨度、追踪和会话三类过滤器分别作用于不同层级,会话过滤器还能检查聚合属性与内部追踪。

过滤器是 **Python 布尔表达式** 。凤凰城编译到数据库查询。键入一个过滤栏,以缩小一个表格,或将一个过滤栏传递到 API 范围,用于设定一个结果。凤凰城有三种过滤语言——每个过滤栏各一个。 **间距**, **痕迹**,以及 **届会**。它们共享相同的核心语法;痕量和会话过滤器会添加集合和理解。 会话过滤器需要 Phoenix **19.18.0+**. ## 过滤器工作的地方 | 表面 | Span 过滤器 | 跟踪过滤器 | 会话过滤器 | | --- | --- | --- | --- | | UI 过滤栏 | 是——横幅表(通过GraphQL) | 是——追踪表(通过GraphQL) | 是-会议表(通过GraphQL) | | GraphQL | `filterCondition` 参数 | `traceFilterCondition` 参数 | `sessionFilterCondition` 参数 | | Python / TypeScript 客户端 | 对... `SpanQuery().where(...)`,发送至 `POST /v1/spans` (仅蟒蛇). | `filter` 参数 `traces.get_traces(...)` / `getTraces(...)` | `filter` 参数 `sessions.list(...)` / `listSessions(...)` | | REST 列表/ 搜索终点 | 仅分解查询参数——没有过滤表达式 | `filter` 查询参数 `GET /v1/projects/{project_identifier}/traces` | `filter` 查询参数 `GET /v1/projects/{project_identifier}/sessions` | 跟踪 REST 列表终点上的 Span 过滤表达式 [#15099](<https://github.com/Arize-ai/phoenix/issues/15099>). 那个... **实验比较** 视图有其自身的过滤语言,用于过滤实验运行,与跨度,痕量,和会话过滤语言分开. ## Span 过滤器 一个跨度滤波器匹配单个跨度, 由内置字段匹配, 如 `span_kind`, `latency_ms`,以及 `input.value`: ``` span_kind == 'RETRIEVER' latency_ms > 100 0.5 < latency_ms < 1000 span_kind in ['LLM', 'RETRIEVER'] span_kind == 'LLM' and 'programming' in input.value ``` 访问跨度 **属性** 名称。任何不属于内置字段的标识符都被视为属性路径,以及 `metadata[...]` 是该词的缩写 `metadata` 属性 : ``` attributes['llm.model_name'] == 'gpt-4o' llm.model_name == 'gpt-4o' metadata['topic'] == 'programming' 'programming' in metadata['topic'] ``` 打开过滤器 **说明** 通过标签、分数或解释。 `is None` 匹配的跨度为: 注释尚未写入 : ``` annotations['correctness'].label == 'incorrect' annotations['hallucination'].score > 0.5 evals['correctness'].label == 'incorrect' annotations['correctness'].label is None ``` 使用( U) `parent_span is None` 以匹配根跨度,包括从未收到过记录的父词的跨度。要匹配仅匹配完全没有父词代号的跨度,请使用 `parent_id is None`: ``` parent_span is None parent_span is not None ``` 泛指笔记: - **追踪级别说明 :** `trace_annotations["name"]` 过滤器在父上通过注释横跨 *跟踪*, 使用同样的 `.score` / `.label` / `.explanation` / 存在语法为 `annotations`. - **数字 :** 比较字符串字元 `span_kind` 或 时 间 `status_code` 自动大写—— `span_kind == 'llm'` 财务报告和财务报告 `span_kind == 'LLM'` 匹配相同的跨度。 - **未知名称 :** 一个不是内置字段的名称被读作属性路径,所以一个字节过滤器在不存在的属性上进行,并匹配什么,而不是产生一个错误。 在过滤栏和 Python 客户端中运行的相同表达式 [`SpanQuery().where(...)`](<https://arize.com/docs/phoenix/tracing/how-to-tracing/importing-and-exporting-traces/extract-data-from-spans#running-span-queries>) 导出路径。 ## 跟踪过滤器 微量滤波器与全部痕迹相匹配的字段, 如 `latency_ms` 并按其跨度滚动的数值。没有匹配数据的滚动是 `0`,永不无效 : ``` latency_ms > 1000 num_spans > 10 and error_count > 0 token_count_prompt + token_count_completion > 5000 total_cost > 0.25 ``` 收件机的滚动包括: `token_count_prompt`, `token_count_completion`,以及 `token_count_total`成本滚动包括: `prompt_cost`, `completion_cost`,以及 `total_cost`使用时 `tool_span_count` 财务报告和财务报告 `llm_span_count` 按类型计算。读取 `input`, `output`,属性, `user.id`,以及 `metadata[...]` 从痕量的根部间距: ``` 'refund' in input output is not None attributes['llm.model_name'] == 'gpt-4o' user.id == 'u1' metadata['topic'] == 'support' ``` 跟踪过滤器 **注释** 按名称 `trace_annotations["name"]`。它会暴露 `.score`, `.label`,以及 `.explanation`;没有这些字段之一的查询检查注释是否存在: ``` trace_annotations['quality'].score < 0.5 ``` 如果您使用其他注释查询, 校验错误指向 `trace_annotations[...]` 用于微量说明或 `span_annotations` 用于跨度说明的收藏。 **顾虑** 按追踪时间段、跟踪说明、跨度说明和跨度成本细节进行量化和汇总: ``` any(span.status_code == 'ERROR' for span in spans) any(annotation.label == 'incorrect' for annotation in trace_annotations) any(annotation.score < 0.5 for annotation in span_annotations) sum(detail.cost for detail in span_cost_details if detail.is_prompt) > 0.10 ``` 一个跨度暴露了它的 `children` 财务报告和财务报告 `parent_span`,这样您就可以通过亲子关系过滤: ``` any(any(child.status_code == 'ERROR' for child in span.children) for span in spans) any(span.parent_span.span_kind == 'LLM' and span.span_kind == 'TOOL' for span in spans) ``` 具体追踪注释 : - **严格名称 :** 用“你的意思”建议拒绝未知名称,这与跨度过滤不同,该过滤回溯到属性路径。 - **仅循环变量 :** 在理解内,请参考循环变量的字段(`span.latency_ms`),而不是赤裸的痕量级名称. - 现有汇总、收集和元素域名称为项目专用名称——见 [查找字段名称](<https://arize.com/docs/phoenix/tracing/how-to-tracing/filter-expressions#finding-field-names>). ## 会话过滤器 一个会话分组一个对话的痕迹。 会话过滤器可以测试 **总计属性** 特别会议 **检查它的痕迹 并横跨它内部**. 一个会话中的每一段追踪通常都对应一个 **转弯** 对话框中的用户消息和应用程序的响应。以转弯方式读取过滤器有助于: `num_traces > 5` 是指“五轮以上”,以及 `for trace in traces` 问每个转弯的问题。 将会话的痕迹和跨度滚动。没有匹配数据的集合是 `0`,永不无效;除以集合 `0` 匹配不产生错误的空格 : ``` num_traces > 5 and total_cost > 0.50 num_traces_with_error / num_traces > 0.2 duration_ms > 60000 ``` 读取会话级别 **说明** 届会和届会 **root-span** 属性和 I/O。 `first_input` 财务报告和财务报告 `last_output` 作为字符串的会话开幕输入和最后输出 - 使用 `==`, `in`,或 `is None`. `any_input` 财务报告和财务报告 `any_output` 测试封隔 *全部( E)* 会议投入和产出以及仅支助 `in` / `not in`: ``` session_annotations['Quality'].score <= 0.5 session_annotations['Quality'].score is None attributes['llm.model_name'] == 'gpt-4o' user.id == 'u1' 'refund' in any_input 'refund' in first_input last_output is not None ``` **顾虑** 使用 Python 理解语法对会议成员进行量化和汇总。 `any` 财务报告和财务报告 `all` 提出 " 是 " / " 无 " 问题; `len`, `sum`, `max`,以及 `min` 减为数字 : ``` any(span.status_code == 'ERROR' for span in spans) all(trace.latency_ms < 30000 for trace in traces) len([span for span in spans if span.span_kind == 'TOOL']) > 3 sum(detail.tokens for detail in span_cost_details if detail.token_type == 'input') > 0 any(a.label == 'correct' for a in span_annotations) ``` A `traces` 元素会暴露它自己的 `spans`,这样你就可以用一个水平的筑巢来问每个回合的问题: ``` any(len([span for span in trace.spans if span.span_kind == 'TOOL']) > 5 for trace in traces) ``` 具体会议说明: - **严格名称 :** 用“你的意思”建议拒绝未知名称,这与跨度过滤不同,该过滤回溯到属性路径。 - **仅循环变量 :** 在理解内,请参考循环变量的字段(`span.latency_ms`),而不是赤裸的会话级别名称。 - 现有汇总、收集和元素域名称为项目专用名称——见 [查找字段名称](<https://arize.com/docs/phoenix/tracing/how-to-tracing/filter-expressions#finding-field-names>). ## 查找字段名称 字段名称是特定项目:属性密钥和注释名称来自您的数据。 要发现可用的信息 : - 在任何一项中 **过滤栏**,开始打字,以获得项目中可用的名称的打字头,按类型分组(字段,汇总,集合,属性,注释). - 对于痕迹和会话,请查询 **`traceFilterVocabulary`** 财务报告和财务报告 **`sessionFilterVocabulary`** GraphQL 字段在程序上列出有效名称. Span 过滤器没有等效的端点; 使用滤波栏型号头. ## 语法规则 这些规则适用于跨度、跟踪和会话过滤器,除非有一个注释另有说明。 - **接线员。** 比较 `==` `!=` `<` `<=` `>` `>=` (链式比较,如: `0.5 < latency_ms < 1000` 支持); 将条件与 `and` / `or` / `not`; 测试成员 `in` / `not in`; 检查缺失的值 `is None` / `is not None`;并在数字字段上用 `+` `-` `*` `/` `%` (e.g. `num_traces_with_error / num_traces`, `total_cost - prompt_cost`。整个表达式必须是一个条件,而不是一个赤裸的价值。 - **说明。** 使用( U) `trace_annotations["name"]` 在微量过滤器中, `session_annotations["name"]` 在会话过滤器中。Span过滤器使用 `annotations["name"]` 及其遗留的别名 `evals["name"]`;他们也接受 `trace_annotations["name"]` 用于在包含的痕迹上进行说明。每次查找都显示 `.score`, `.label`,以及 `.explanation`,没有这些字段的搜索就是存在检查。 - **`in` / `not in` 忽略个案。** 与文本相对的封装对大小写不敏感: `'refund' in first_input` 匹配 `REFUND please`. 平等(`==` / `!=`和成员名单(A/C.5/49/L.10)`span_kind in ['LLM']`准确无误。 - **缺失的值与无异 。** 当一个数值不存在时,与它作的每一项比较都是虚假的——包括 `!=`使用时 `is None` / `is not None` 以匹配缺失值(见下文注)。 - **日期字节需要时间区偏移.** 写入 `start_time > '2026-07-01T00:00:00+00:00'` 或使用跟踪 `Z`;没有抵消的字面意思被否定为含糊不清。 - **函数调用 。** `float()` 财务报告和财务报告 `str()` 转换未知类型的属性; 跨度过滤器也接受 `int()`,它的行为像 `float()` 而不截断。跟踪和会话理解接受减员。 `any` / `all` / `len` / `max` / `min` / `sum`。所有其他函数和方法调用(例如: `name.startswith(...)`, `len(span_id)`) 被拒绝,如: `**`, `//`,和位元运算符 `&` `|` `^`。字符串不会被隐含地转换成数字。 例如: ``` start_time > '2024-01-01T00:00:00Z' float(attributes['retry_count']) > 1 ``` **缺失的值行为不同于Python.** 在皮森语中 `None != 'premium'` 评估到 `True`。在过滤器中,跨度为无 `user.tier` 属性匹配 *都没有* 这些表达式: ``` attributes['user.tier'] == 'premium' attributes['user.tier'] != 'premium' ``` 要匹配缺失值的行, 请拼写 : `attributes['user.tier'] != 'premium' or attributes['user.tier'] is None`. 这页有用吗? [建议编辑](<https://github.com/arize-ai/phoenix/edit/main/docs/phoenix/tracing/how-to-tracing/filter-expressions.mdx>)提出问题

查看原始来源