Skip to content

service-knowledge: search returns records, not chunks — granularity and groupBy #37103

Backlog

Description

@os-bob

maintainer · os-bob · session_012dn2AecKpLaYkUtNRiqtby

Filing gate: ③ maintainer-directed (topic child). Source: topic #37000 (phase 2 row 10); maintainer 2026-11-24 「用fable评审,并分拆第二阶段的任务」. Reviewed by an independent Fable pass before filing.
Grading: area:ai · Feature · p2 (topic) · reach: apps that mount service-knowledge · evidence: read.

维护者速读

  • 做什么:检索可以按记录返回。同一份制度命中多个片段时合成一条,取最高分;也可以按某个字段分组(比如按制度),返回「哪几份制度」。
  • 记录在建索引之后改过内容的,不返回旧片段。
  • 谁受益:制度问询先找到「哪几份制度」,再把全文交给模型;BrightRule 可以删掉自己写的去重。
  • 需要你做的:无。

What

  1. KnowledgeSearchOptions (packages/spec/src/contracts/knowledge-service.ts): granularity?: 'chunk' | 'record' (default chunk, today's behaviour) and groupBy?: string. Return type stays KnowledgeHit[].
  2. knowledge-service.ts search(): in record mode keep the best hit per group; topK counts groups; builds on service-knowledge: search returns a short page after the permission filter instead of refilling #36993's refill after the permission filter, with a stated refill cap.
  3. groupBy must be one of the source's metadataFields; a source without it answers no hits for that search (never ungrouped); the group value is returned in the hit's metadata. File and http sources group by documentId.
  4. The permission re-read stays id + the display field (resolveDisplayField, shared with service-knowledge: a knowledge hit's title is read from a hard-coded title field #36994), as the asking user, in the same query.
  5. Freshness, a separate query only for the hits that would be returned (at most topK records): one system-context read per object of the source's content and metadata fields with { $and: [where, { id: { $in } }] }. A record that no longer matches where, or whose recomputed docHash differs from the hit's, is dropped. Repair is in process, not awaited, in system context, single-flight per (source, record) through service-knowledge: record-change sync ignores the source where, and a restored record never re-enters the index #36991's path, at most once per record per process lifetime until its hash matches; it never throws into the search. It moves to the queue with row 15. The hit carries the stored hash (KnowledgeHit.docHash?, per ADR: knowledge platform boundary — the platform owns document assembly, sync and reconcile, structural split and record-level return; knowledge_source becomes a governed type #37001).
  6. When a chunk has headingPath (service-knowledge: one service-layer splitter (whole / recursive / markdown, Chinese-aware), the chunk channel and the split key #37098), the hit carries it (KnowledgeHit.headingPath?, per ADR: knowledge platform boundary — the platform owns document assembly, sync and reconcile, structural split and record-level return; knowledge_source becomes a governed type #37001).

Acceptance

  • One record with 3 matching chunks → 1 hit, the highest score.
  • topK: 5 → 5 records when that many exist within the refill cap (cap stated); fewer otherwise, logged.
  • A record deleted, unreadable, or out of where after indexing → absent; content changed → no stale snippet, one repair.
  • groupBy: 'policy'; a groupBy field missing from one source; system identity; several sources mixed; a file source.
  • Container run per AGENTS.md.

Out of scope

Blocked-by: #37001, #36993 (same function; record mode builds on its refill), #37098, #37096 (docHash). Coordinates with #36994: both use resolveDisplayField; #36994 sets the title at index time, this card reads it live in the permission re-read.
Parent: #37000. Reader: domain:server lane (spec edits per spec.md).
Dedupe: granularity 227 (open: none on knowledge besides #37000) · groupBy knowledge 25 (open 3: #37000, unrelated skills and seat posts).

Activity

  1. added theissue type on Nov 24, 2026
  2. added
    priority:p2
    area:ai
    on Nov 24, 2026
  3. objectstack-fleet commented on Nov 24, 2026

    @objectstack-fleet
    Contributor

    triage#1 · os-warren · session_01JQwxbZKP5YM48rWMWTS7wE

    Triage: first touch 2026-11-24T20:37Z

  4. added
    domain:server
    pm:blocked
    on Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:aidomain:serverpm:blockedpriority:p2

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions