Skip to content

feat: Advanced Meta Search with KQL Syntax #54

@pescn

Description

@pescn

Summary

Implement advanced search functionality for request metadata using KQL (Kibana Query Language) style syntax, with aggregation support for A/B testing.

Requirements

Query Syntax (KQL Style)

# Basic filtering
model: "gpt-4" AND status: "completed"

# Range queries
duration >= 1000 AND promptTokens < 5000

# Wildcard search
prompt: *error*

# Nested fields (JSONB)
extraHeaders.x-experiment: "group_a"
toolCalls.name: "get_weather"

# Combined queries
(model: "gpt-4" OR model: "claude-3") AND status: "failed"

Aggregation Functions

model: "gpt-4" | stats avg(duration), count(), p95(ttft) by status

Supported functions:

  • count() - Count
  • avg(field) - Average
  • sum(field) - Sum
  • min(field), max(field) - Min/Max
  • p50(field), p95(field), p99(field) - Percentiles

A/B Testing Support

Users pass experiment tags via extra_header, then filter by that field for comparison.

UI Design (Reference: Kibana Discover)

  • Top: Query input with field autocomplete + time range picker
  • Middle: Histogram with field breakdown
  • Bottom: Document list + field statistics + pagination
  • Export: CSV / JSON

Technical Implementation

  • Backend: KQL parser → PostgreSQL JSONB queries
  • Frontend: Input box with field name autocomplete
  • Parser library: chevrotain or custom PEG grammar

概要

实现基于 KQL(Kibana 查询语言)风格语法的高级元信息搜索功能,支持聚合函数用于 A/B 测试。

需求

查询语法(KQL 风格)

# 基础过滤
model: "gpt-4" AND status: "completed"

# 范围查询
duration >= 1000 AND promptTokens < 5000

# 通配符搜索
prompt: *error*

# 嵌套字段 (JSONB)
extraHeaders.x-experiment: "group_a"
toolCalls.name: "get_weather"

# 组合查询
(model: "gpt-4" OR model: "claude-3") AND status: "failed"

聚合函数

model: "gpt-4" | stats avg(duration), count(), p95(ttft) by status

支持的函数:

  • count() - 计数
  • avg(field) - 平均值
  • sum(field) - 求和
  • min(field), max(field) - 最值
  • p50(field), p95(field), p99(field) - 百分位

A/B 测试支持

用户通过 extra_header 传入实验标记,查询时按该字段过滤对比。

界面设计(参考 Kibana Discover)

  • 顶部:查询输入框 + 字段自动补全 + 时间范围选择器
  • 中间:直方图(可按字段 Breakdown)
  • 底部:文档列表 + 字段统计 + 分页
  • 导出:CSV / JSON

技术实现

  • 后端:KQL 解析器 → PostgreSQL JSONB 查询
  • 前端:输入框 + 字段名自动补全
  • 解析器库:chevrotain 或自定义 PEG 语法

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions