Skip to content

[Decision] knowledge_source: a declarative retrieval block — rank hits by the asker's relation to a declared field, by recency, and expand a hit along declared structure #38412

Backlog

Description

@os-project-manager

maintainer · os-project-manager · session_01FEkQ5oW6SeQkzCccNxEc83

Filing gate: ② a decision only the maintainer can make (topic child; a new authorable key needs a ruling and an ADR-0161 note before any code). Source: topic #38346. Key words (maintainer, 2026-11-29, this session): 「检索按提问人单位加权,每种知识的要求不同吧,你的评估不能只考虑当前的规章制度,要考虑客户可能开发的各种元数据应用」「相关任务都加入知识专题」.
Grading: area:ai · Feature · p3 (dispatched in the topic's order after the ruling, not by grade) · reach: every app whose right answer depends on who asks or on how fresh the record is · evidence: measured in one evaluation with the asker simulated in the prompt (below); the rest read from the code on main 3511432.
Blocked-by: #38363

维护者速读

  • 问题:同一个问题,不同的人问,应该排在前面的内容不一样(本单位的制度先于集团的;自己的客户纪要先于别人的;本产品线的工单知识先于其它线),而且每种知识的规则不同。现在检索对所有人按同一个顺序排,模型只能反问「你是哪个单位的」。
  • 选项:A 在知识源上加一段声明式的「检索排序」配置,写明哪个字段和提问人的哪种身份相关、怎么用(加权、只留相关的、就近优先)、按哪个日期字段衰减、命中后带出哪些相邻或关联内容;不写就完全不加权。B 不加平台能力,把提问人身份告诉模型,由各应用在技能说明里教模型自己加过滤条件。
  • 推荐:待决策线程按四轴写(本卡给证据、形状和四类应用的适配表)。
  • 不定会怎样:每个应用各自在提示词里写一套「按单位找」的规则,效果随模型波动,换一种知识就要重写。

The question

May a knowledge_source declare, per source, how its hits are ordered for the person asking, and what a hit brings with it? If yes, in which shape, and as ranking only.

Evidence

  • In a policy Q&A evaluation (1,923 documents / 67,379 passages, libSQL store, 132 questions; a small model answering over MCP, a separate model grading blind; one run), putting the asker's unit chain in front of the model moved the whole set from 86.7% to 92.4%, the questions whose answer depends on the asker's unit from 59.4% to 93.8%, and the turns that ended in a clarifying question from 41 to 2. That measures "the model knows who asks" (mcp: tell the model who is signed in — the asker's user and business-unit chain reach the ask route (cloud#5099) but not an MCP client #38363), with the model then doing the narrowing itself. It is the upper-bound signal for this card, not a measurement of platform-side ranking.
  • What the platform has today: search_knowledge accepts query, sourceIds, topK, scope, granularity, groupBy (packages/services/service-knowledge/src/knowledge-tools.ts:321). The service contract already has a metadata-equality filter (packages/spec/src/contracts/knowledge-service.ts:62-63, run in both legs by both stores) that the tool does not expose. The search already over-reads and refills after the permission re-check (SEARCH_REFILL_FACTOR = 20, knowledge-service.ts:4402). The adapter contract carries "no rerank toggles" (packages/spec/src/contracts/knowledge-adapter.ts:18-19, ADR-0161 K8 rule 4), so ordering by declared fields belongs to the service, over the indexed metadataFields values, not to adapters.
  • Identity vocabulary that already exists for predicates: current_user.positions, the pre-resolved membership sets (rlsMembership, packages/spec/src/kernel/execution-context.zod.ts:569-585), and the declarative membership keys of Spec design: declarative membership keys for RLS (current_user.<key> from a lookup on records whose user field is the current user) #25234 (ruled, closed).

Proposed shape (option A; for the decision thread to confirm or reshape)

retrieval: {
  affinity: [{ field, asker, mode, weight }],
  recency:  { field, halfLifeDays },
  expand:   { siblingsBy, window, follow },
}
  • affinity[].field: one of the source's metadataFields (refused at publish otherwise).
  • affinity[].asker: a CLOSED vocabulary resolved by the platform from the caller's execution context, the same way row-level predicates read current_user.*: userId | positions | businessUnitChain | teams | organization. ⛔ Never a value the client or the model supplies.
  • affinity[].mode: boost (matching hits rank higher by weight), filter (only matching hits; the service passes it as the existing filter / scope), nearest (for a hierarchy: the asker's own unit first, then each ancestor in order, then the rest).
  • recency: an exponential decay on a declared date field of the source's metadataFields.
  • expand: what a hit brings with it, each part re-checked as the caller:
  • Omitted block: today's behaviour, byte for byte. A public FAQ source declares nothing.
  • Ranking only. It runs over the candidates that survived the permission re-check, inside the existing refill cap; it never widens what a caller may read, and filter can only narrow. The count of hits removed stays unreported, as today.
  • Each key lands with its reader in the same PR (ADR-0049); affinity waits for mcp: tell the model who is signed in — the asker's user and business-unit chain reach the ask route (cloud#5099) but not an MCP client #38363's identity resolution, recency and expand.siblingsBy do not.

The same four keys across unrelated apps

App affinity recency expand
CRM visit notes owner ↔ userId, boost; territory ↔ teams, filter activity_date, 90 days follow: account
Support knowledge base product_line ↔ teams, boost; the public FAQ source declares nothing reviewed_at, 365 days siblingsBy: heading
Contracts signing_entity ↔ businessUnitChain, filter effective_date follow: amends (contract ↔ amendment)
Policies owning_unit ↔ businessUnitChain, nearest (own unit before the group) none follow: supersedes, siblingsBy: heading

No row needs code in the app, and no key names a policy concept.

Options

Decision owed

Analysis (four axes, facets block, prior-rulings line, workload precedents) is owed by a decision thread. Not dispatched before a ruling is recorded here. Open points for that thread: whether filter mode is allowed at all given that sharing already decides visibility (a source-declared filter is a relevance narrowing, and must not be read as access control); the combination rule when several affinity entries match; how granularity: 'record' and groupBy interact with a re-rank; whether the tool gains an explicit opt-out for a caller who wants the unweighted order.

Reader

The decision thread, then repo:objectstack#5 (the seat holding #38346).
Related, not children: #38291 (hit metadataFields, landed as PR #38353), #25234 (declarative membership keys for row-level security, the precedent for a platform-resolved asker vocabulary), #37001 (ADR-0161, the knowledge platform boundary), #37000 (knowledge platform topic), objectstack-ai/brightrule#88 (the evaluation tooling).
Dedupe (open and closed): knowledge rerank 3 (none on declared ranking) · knowledge_source retrieval ranking asker 0 · knowledge recency boost 0 · search_knowledge neighbour passages 2 (#38346 row 2-3 only) · search_knowledge filter metadata argument 13 (all closed; none exposes filter on the tool) · knowledge graph 68 (none on knowledge retrieval; no graph card is filed, by the reasoning under follow).

Activity

  1. added
    needs-user-decision
    on Nov 29, 2026
  2. added
    area:ai
    on Nov 29, 2026
  3. objectstack-fleet commented on Nov 29, 2026

    @objectstack-fleet
    Contributor

    triage#1 · sunhaolin · session_017xRBcSxvUE3fDrox79CL9t

    Triage: lands in packages/spec/src/ai/knowledge-source.zod.ts (a new authorable retrieval block), the readers in service-knowledge (knowledge-service.ts, knowledge-tools.ts) and an ADR-0161 dated note · area:ai · domain:spec (provisional; the readers are domain:server) · Feature · p3 · needs-user-decision (as filed) · size L. Rationale: a new authorable key with no precedent. That is a contract shape, and its filter mode sits beside the permission boundary, so it is on the human floor. The topic pre-authorises building, not the shape. A child of #38346, never folded or moved. Blocked-by: #38363 applies only to option A slice 2. ⛔ The decision thread owes the four-facet block, the Prior rulings read: line and the recommendation before it is presented.

    Recorded 2026-11-29T00:50Z.

  4. added
    domain:spec
    on Nov 29, 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:specneeds-user-decisionpriority:p3

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions