Skip to content

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

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
  5. added
    pm:queue
    and removed
    pm:blocked
    on Nov 25, 2026
  6. objectstack-fleet commented on Nov 25, 2026

    @objectstack-fleet
    Contributor

    repo:cloud#1 · os-warren · session_01JQwxbW5anP6GDaVi5LKi2U

    Claim: PM loop round 2 (epic #37000 owner seat, card thread)
    Session: session_01JQwxbW5anP6GDaVi5LKi2U
    Thread session: session_01JQwxbZmvWffL8FZzRX8ZSb
    Account: os-warren
    Branch: claude/project-thread-oc6nsu
    Worktree: objectstack (the card thread's own checkout)
    Domain: domain:server
    Seat: repo:cloud#1
    File surface: packages/services/service-knowledge/**, packages/spec/src/contracts/knowledge-service.ts and packages/spec/src/contracts/knowledge-adapter.ts (the search options and hit shape only), packages/plugins/knowledge-memory/** (the reference adapter's hash and heading path; widened at review, PR #37335), content/docs/** knowledge pages, .changeset/ (stop on breach; explain in the report)
    Container & model: M, mode:thread, model: default (dispatch-gates --tier: no path-derived mandate; floor sonnet · default opus · ceiling fable), effort: high
    Clause-②: yes
    Metadata-protocol: added (revised at build: the gate reads KnowledgeHit.docHash and headingPath in packages/spec/authorable-surface/ai.json as added authorable keys)
    Responsibility: n/a — not a defect card
    Thread-read: 7169793093
    Premise: holds (Blocked-by #37001, #36993 (PR #37301), #37098, #37096 all closed; read 17:45Z)
    Serial constraints cleared: #37100 (this seat, branch claude/project-thread-vcp8s3) changes KnowledgeService.search for K7 rule 5 in the same file; overlap-check before each push, the second to land merges main. #37308 (row 11, blocked on the ADR note PR #37329) adds scope to the same search path later. #36994's display-field title (PR #37301) is read live here per the card.

    Ownership: maintainer 2026-11-25 13:49Z, 「#4 只负责在手任务,你接手专题剩余任务」; unlocked by triage 17:41Z. Clause-② yes: granularity and groupBy widen the published search options and owe a contract review at the ceiling tier before the queue.

  7. added
    pm:dispatched
    and removed
    pm:queue
    on Nov 25, 2026
  8. objectstack-fleet commented on Nov 25, 2026

    @objectstack-fleet
    Contributor

    repo:cloud#1 · os-warren · session_01JQwxbZmvWffL8FZzRX8ZSb
    os-dev-report

    {
      "issue": 37103,
      "status": "done",
      "branch": "claude/project-thread-oc6nsu",
      "pr": "https://github.com/objectstack-ai/objectstack/pull/37335",
      "session": "session_01JQwxbZmvWffL8FZzRX8ZSb",
      "premise_still_valid": true,
      "summary": "KnowledgeSearchOptions gains granularity ('chunk' default, unchanged) and groupBy; KnowledgeHit gains docHash? and headingPath?. Under record granularity search() answers one best hit per record (or per groupBy value, merged across sources; file/http per document), widens the #36993 refill to every source and caller (cap topK x 20 passages per source), reads the display field live in the one permission re-read, and checks each hit about to be answered against its record (system read of where AND id in, projected): deleted, out of where or recomputed docHash differs => dropped, next moves up (max 3 rounds), background single-flight repair through syncRecord. knowledge-memory returns docHash and headingPath; the contract suite pins both plus a record-level freshness case through a real service.",
      "tests": "at 9652c238: service-knowledge vitest 292/292 (11 files); knowledge-memory 37/37; knowledge-ragflow 10/10; typecheck exit 0 on service-knowledge and knowledge-memory. Ablation via scripts/ablation-replace.mjs (restored, git diff HEAD empty): hash compare -> false turns 2 freshness cases red; grouping map read disabled turns 3 grouping cases red.",
      "gates": "local: spec check:generated 13/14 green, check:docs stale -> --fix -> green; eslint changed .ts exit 0; check:doc-authoring, check:durability-log-level, check:startup-registry-verdict, check:adr-anchors, check:adr-0087-registration, check:pm-skill-id-lint, check-nul-bytes exit 0. dispatch-gates --commands derived 117 commands; the rest declared to CI (PR check-runs in_progress at report time).",
      "dogfood_battery": "n/a — no `!` in the PR title and no (narrowing) arm",
      "mcp_calls": "4 — issue_read x2, get_session, subscribe_pr_activity (no write tool)",
      "api_writes": "2 — relay pr_create (POST /pulls + assignees leg), this os-dev-report comment",
      "open_questions": [],
      "security_findings": "none",
      "out_of_scope_findings": ["carrier: #37100 — knowledge-pgvector now owes docHash and headingPath on hits under the contract suite; told to that thread"]
    }
  9. objectstack-fleet commented on Nov 25, 2026

    @objectstack-fleet
    Contributor

    repo:cloud#1 · os-warren · session_01JQwxbW5anP6GDaVi5LKi2U

    ACCEPT → PR #37335 comment 7171310022 (round 2: L1 ACCEPT + contract review PASS at head f5c87f7; round 1 REWORK 7170913599). Not governed; CI all green at that head; readied and auto-merge armed.

  10. removed
    pm:dispatched
    on Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:aidomain:serverpriority:p2

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions