Skip to content

Commit c35318c

Browse files
feat(knowledge): a knowledge source orders its hits for the person asking (source.affinity) (#38606)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} --> _Requested by **Jianguo** · [project thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbYGovuXpimWzFab7rEUdRYr)_ Part of #38503 Clause-②: yes (widening) Metadata-protocol: added Skills-docs: follow-up #38610 ## 维护者速读 - 用户能看到什么变化:知识源可以声明「和提问人相关的内容排前面」:本单位优先、再按上级单位逐级(nearest),或提问人本人负责的内容往前提若干位(boost,最多 20 位);Studio 知识源表单多一个「按提问人排序」填写项。没声明的知识源、系统身份的检索结果与今天完全相同。 - 为什么做:属于知识切分与检索专题,按 ADR-0161 当天的注记落地裁定「A 精简:排序加带出」里的排序一片;它读的是「告诉模型是谁在问」已落地的同一个身份解析。 - 出错会怎样:只调整同一知识源内命中的先后,不改分数、不丢弃也不增加命中,也不触发重建;排错了只是先后不对,删掉该声明即恢复原顺序。 - 要你做什么:无。三组对照按实测记录(44 道单位题 × 3 轮):不告诉身份 56.1%,告诉身份 82.6%,告诉身份并声明 nearest 86.7%;您 14:44Z 已裁定按提问人排序无需对照证明。 ## What changes PR 1 of 2 for the card. This PR lands the key, its parse refusals, its save-door refusal and its first reader. The `os validate` half of the target-field refusal is PR 2 (the lint package is held by another card's queue). The card's three-arm measurement was run on this branch's build (see Acceptance notes). - **Spec** — `ObjectKnowledgeSourceSchema` gains `affinity?: KnowledgeAffinityEntry[]`, each `{ field, caller, mode, places? }` (`KnowledgeAffinityEntrySchema`, strict; author and `…Parsed` aliases per ADR-0122). `caller` is `user` or `business_unit`; `mode` is `boost` or `nearest`. Refused at parse, each with a sentence naming the fix: a `field` not in `metadataFields`; `mode: 'filter'` (narrowing is the search scope, who may read a record is sharing) and any other mode; a caller outside the two; a second `nearest`; `nearest` with `caller: 'user'`; `places` missing on `boost`, present on `nearest`, or outside 1 to 20. The cross-key rules are refinements JSON Schema cannot state, ledgered in `dropped-refinements.baseline.json` (the entry schema, plus the two source schemas and four installed-package response schemas that embed it; header totals updated). - **The `places` bound: 20** (`KNOWLEDGE_AFFINITY_MAX_PLACES`, stated on the key). It is the most hits one `search_knowledge` answer carries (`SEARCH_KNOWLEDGE_MAX_TOP_K`). A boost of `p` lets a match standing at number `n` in its tier land just behind number `n − p`, so with `p` at the largest answer a match is brought into an answer from at most one answer's length below it. A larger number adds nothing an author can see in an answer and drifts toward "matches first", which the note keeps for `nearest` only. - **The resolver moves to `@objectstack/core`** — `resolveCallerIdentity` (#38363), with its types and `CALLER_UNIT_CHAIN_MAX_DEPTH`, moved unchanged from `packages/runtime/src/domains/mcp.ts` into `packages/core/src/caller-identity.ts`, so the knowledge service (which does not depend on the runtime) calls the same function `get_current_user` does. The runtime imports it from core and re-exports it for its own tests; `get_current_user` behaviour is unchanged and `mcp-asker-38363.test.ts` still pins it through that re-export. This settles where the resolver lives (the note's slice line). - **Reader** — `knowledge-affinity.ts` holds the two halves. `resolveAffinityFacts` resolves only the facts a declared entry reads: `user` is the search's own `ctx.userId` and reads no row; `business_unit` hands the resolver the user id alone, so it reads the caller's user row for the primary unit and each unit up the chain, by id as the caller through `dataEngine.find` with the search's `ExecutionContext` (a unit the caller may not read ends the chain), and no organization row; the system identity has no facts. `orderByAffinity` is the note's rule exactly: per source among the places its units hold; judged on the hit standing for each unit; `nearest` tiers (own unit, each parent in order, every other unit, a hit with no value among them; a multi-value lookup takes its nearest element); inside a tier key = number − sum of matched `places`, ties to the larger sum then the earlier number; values compared as a scope term compares them; no score written. In `searchByKey`, `affinityOrderFor` resolves the facts at most once per search, only when a hit in the list belongs to a source that declares an entry, and only those its entries read; the order runs after the score sort and before `slice(0, topK)` (chunk granularity) or inside `answerByRecord`'s `leads()` before its cut (record granularity, so the freshness check checks the re-ordered top). The rounds, the refill and the re-check are untouched. Moves go to the `debug` log only. A unit read that fails for a reason other than a refusal leaves the units out, reported once at `warn`, and keeps the `user` fact, so a `boost` by user still applies (a functional degradation: every hit is still answered). - **Save door** — `admitAuthoredSource` refuses an entry whose `field` (listed in `metadataFields`) does not point at `sys_user` (for `user`) or `sys_business_unit` (for `business_unit`), judged by `referenceTargetOf`: `400 VALIDATION_ERROR`, `field` set, after the documentBy arm and before every permission arm (`affinityTargetRefusalText` in `knowledge-source-admission.ts`). - **System-identity census** — `content/docs/permissions/system-context.mdx` gains row 46a: under the system identity a source's `affinity` moves nothing and no user or unit is read (`resolveAffinityFacts`, the one `isSystem` read; the register is regenerated). - **Hashes** — `affinity` is in neither the index fingerprint nor the recipe hash; pinned with a control that the recipe hash still reads `metadataFields`. - **Form** — the form-coverage gate needs a row: "Order for the asker", `widget: 'json'`, with its regenerated translation bundles. - **Docs** — `content/docs/protocol/knowledge.mdx` gains "Ordering for the asker"; `content/docs/ai/knowledge-rag.mdx` rewrites "sorted by score, and capped at `topK`", which this code makes untrue for a declaring source, and gains a short "Ordering hits for the asker". The `IKnowledgeService.search` jsdoc says the same. - Regenerated: authorable-surface, api-surface, export-origins, declaration-map, the reference page and index, the strictness-ledger counts, the liveness ledger row (drilled to its four child keys) and counts. ## Tests - `packages/services/service-knowledge/src/__tests__/affinity-38503.test.ts` (new, 24): the order rule on its own (tiers, places, ties, a multi-value lookup, values compared as strings); through the service: `nearest` under chunk granularity at `topK` 5 answers p8, p9, p4, p2, p1 with their original scores; the caller's user row and units read once per search, as the caller, and no organization row; `boost`, with a `user`-only source reading no row; no fact read when no hit belongs to a declaring source; record granularity (the re-ordered top is what the freshness check sees); a source without `affinity` unchanged with no identity read; the system identity; a parent unit the caller may not read (403) ends the chain; a 500 on the unit read leaves the units out with one `warn` and keeps the user boost; nothing dropped or added; `affinity` changes neither hash (with a `metadataFields` control); the save door's target refusals, each with no record read (a `nearest` entry pointed at a `boost`). Forcing the reader to return no facts turns 6 of them red; reading every fact regardless of the entries turns 2 red. - `packages/spec/src/ai/knowledge-source.test.ts`: 10 new parse cases (a positive control, the bound at 20 and 21, `places` type and presence per mode, `filter`, an unknown caller, a second `nearest`, a field outside `metadataFields`, an unknown key). - Suites: spec 913 files / 28,903 tests and `test:repo` 1,608 tests; core 158 files / 3,818 and `test:repo` 110 (the #22661 pin included); service-knowledge 25 files / 830; platform-objects 130 files / 2,218; runtime `mcp-asker` and `mcp-authoring` 91. Every touched package's typecheck exits 0. The dogfood battery at f55fdc0: 495 files / 4,187 tests passed, 3 files skipped. - Gates: `dispatch-gates` derived 127 commands and all 127 ran (`--ran` reconciles 127 of 127). Two were red and are fixed in this PR (`check:spec-parsed-alias`, `check:system-context-census`). Three stopped on a missing prerequisite and pass once it is met (`check-plugin-teardown-shape --self-test`, `check:skill-examples`, `check:published-readme-exports`). `check:dual-build-cjs-loads` needs the whole workspace built and is left to CI. ## Acceptance notes - **Three-arm measurement, as measured.** BrightRule's eval (07e21ac), the 44 `unit_scope` questions, 3 reps each (132 records per arm), asked over MCP against a server started on this branch's build, answered and judged blind on the container's local plan (the AI gateway key generated embeddings only). Tier and effort for both the answering and the judging model are recorded with the run files. | Arm | Score (2/1/0) | Per rep | Run range | Location recall@1 | |---|---|---|---|---| | 1, no identity | 56.1% | 52.3 / 61.4 / 54.5 | 9.1 points | 31.8% | | 2, told who asks | 82.6% | 84.1 / 79.5 / 84.1 | 4.6 points | 33.3% | | 3, told + `nearest` on `owning_unit` | 86.7% | 86.4 / 87.5 / 86.4 | 1.1 points | 67.8% | The English questions moved from arm 2 to arm 3 41.7% → 55.6% (18 records), the Chinese questions 93.8% → 91.9% (105 records). No arm leaked. Four judge replies (two in arm 2, two in arm 3) did not parse and were scored by the rules alone. #38515 has not landed, so the personas are members who already read the units (BrightRule grants employees that read). Arm 3's `affinity` entry was added in a local clone only. The maintainer ruled at 2026-11-29T14:44Z that ordering hits by the asker's relation needs no comparison to justify it, so no conclusion is drawn from these numbers and nothing gates on them. - **Not in this PR:** the `os validate` rule for the target field (PR 2, `packages/lint`); `expand.window` (#38504); `expand.follow` (#38505); a `filter` mode, date decay, other caller facts and any opt-out argument (out of the card). - **Skills-docs:** `skills/objectstack-ai/SKILL.md` documents the source keys and does not yet teach `affinity`; the follow-up is #38610. - Ordering by position means a declaring source's answer may no longer be in descending `score`; this is the note's rule (5) and is pinned. ## Verification Read first, by risk: `packages/services/service-knowledge/src/knowledge-affinity.ts#orderByAffinity` (the rule), `knowledge-service.ts#affinityOrderFor` and the two call sites in `searchByKey` / `answerByRecord` (where the order sits relative to the cut), `packages/spec/src/ai/knowledge-source.zod.ts` (the key and its refusals). Two-minute check: `pnpm --filter @objectstack/service-knowledge exec vitest run --maxWorkers=2 src/__tests__/affinity-38503.test.ts` — 24 passed, including a search where the caller's own unit's policies (ranked 8th and 9th) answer first with their original scores. --- _Generated by [Claude Code](https://claude.ai/code/session_01QsR2jSArETHHmJzkH5368W)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01QsR2jSArETHHmJzkH5368W <!-- signed: repo:objectstack#1 · zhuangjianguo · session_01QsR2jSArETHHmJzkH5368W --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 1fef2ed commit c35318c

47 files changed

Lines changed: 1601 additions & 197 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
'@objectstack/spec': minor
3+
'@objectstack/service-knowledge': minor
4+
'@objectstack/platform-objects': minor
5+
'@objectstack/core': minor
6+
'@objectstack/runtime': patch
7+
---
8+
9+
feat(knowledge): a knowledge source orders its hits for the person asking, `source.affinity` (`nearest` by business unit, `boost` by places)
10+
11+
Clause-②: yes (widening)
12+
Metadata-protocol: added
13+
14+
A `knowledge_source` may now declare how its hits are ordered for the caller: `affinity: [{ field: 'business_unit', caller: 'business_unit', mode: 'nearest' }, { field: 'owner', caller: 'user', mode: 'boost', places: 3 }]`. `nearest` puts the hits of the caller's own primary business unit first, then those of each parent unit in order, then every other hit. `boost` lets a hit whose field holds the caller's user id (`caller: 'user'`) or one of their units (`caller: 'business_unit'`) pass up to `places` hits that match nothing; `places` is a whole number from 1 to 20 (`KNOWLEDGE_AFFINITY_MAX_PLACES`, the most hits one `search_knowledge` answer carries). Several entries add.
15+
16+
It re-orders by position and never by score: each hit keeps the `score` its store answered, only that source's hits move among the places they hold, nothing is dropped or added, and the move happens before the cut to `topK` (inside the refill cap, under chunk and record granularity alike). A source without `affinity`, and every search by the system identity, answers exactly as before. The caller's facts are resolved at most once per search, only when a hit in the list belongs to a source that declares an entry, and only the facts its entries read: `user` is the search's own user id and reads no row; `business_unit` reads the caller's user row and each unit up the chain as the caller may read them (a unit they may not read ends the chain), and no organization row. A fault reading the units leaves them out and keeps the `user` fact. A fact is never a tool argument or a value a client supplies. `affinity` enters neither the index fingerprint nor the recipe hash, so it rebuilds nothing (listing a new field in `metadataFields` for it does).
17+
18+
The parse refuses, each with the fix: a `field` not listed in `metadataFields`; a `mode` other than `boost` or `nearest` (`filter` is answered that narrowing is the search scope and who may read a record is sharing); a `caller` other than `user` or `business_unit`; a second `nearest`; `nearest` with `caller: 'user'`; `places` missing on a `boost`, present on a `nearest`, or outside 1 to 20. Saving a source through Studio, the metadata API or MCP also refuses a `field` that does not point at `sys_user` (for `user`) or `sys_business_unit` (for `business_unit`). Studio's knowledge source form offers the key as an "Order for the asker" JSON field.
19+
20+
`@objectstack/core` now exports `resolveCallerIdentity` (with `CallerIdentity`, `CallerBusinessUnit`, `CallerRecordReader` and `CALLER_UNIT_CHAIN_MAX_DEPTH`), the one resolver of the caller's own user, organization and business-unit chain that the MCP door's `get_current_user` already used; `@objectstack/runtime` now imports it from there, with no change in behaviour; through the runtime's wildcard re-export of `@objectstack/core`, the same five names are now also reachable from the root of `@objectstack/runtime`.

‎content/docs/ai/knowledge-rag.mdx‎

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,9 @@ export default defineStack({
120120

121121
Retrieval is a plain service call — no AI runtime required. Resolve the `knowledge`
122122
service and call `search`. Hits are re-checked against the caller's
123-
`ExecutionContext` (RLS), sorted by score, and capped at `topK` before they come
124-
back. Because the re-check runs after ranking, for a caller other than the
123+
`ExecutionContext` (RLS), sorted by score, re-ordered for the caller when their
124+
source declares an [order for the asker](#ordering-hits-for-the-asker), and
125+
capped at `topK` before they come back. Because the re-check runs after ranking, for a caller other than the
125126
system identity the service asks each source for more hits than `topK`,
126127
and asks once more when too few records survive, so a caller who may read few of
127128
the matching records still gets up to `topK` hits
@@ -180,6 +181,34 @@ Protocol, adapters, embedder, and `KnowledgeService.search` — is open, so you
180181
installed ([Connect an MCP Client](/docs/ai/connect-mcp)).
181182
</Callout>
182183

184+
### Ordering hits for the asker
185+
186+
A source can put the hits related to the person asking first, without
187+
filtering any out: "the policies of my own company first, then the group's".
188+
Declare `affinity` on the source, naming fields it lists in `metadataFields`:
189+
190+
```ts
191+
source: {
192+
kind: 'object',
193+
object: 'policy',
194+
content: ['title', 'body'],
195+
metadataFields: ['business_unit', 'owner'],
196+
affinity: [
197+
{ field: 'business_unit', caller: 'business_unit', mode: 'nearest' }, // own unit, then each parent, then the rest
198+
{ field: 'owner', caller: 'user', mode: 'boost', places: 3 }, // an owned policy passes up to 3 others
199+
],
200+
},
201+
```
202+
203+
The platform reads who is asking from the search's own identity (the user, and
204+
their primary business unit with its parents up to the root, as far as they may
205+
read them), so no tool argument and no model supplies it. Only that source's
206+
hits move, by position: each keeps the `score` its store answered, nothing is
207+
dropped, and a source without `affinity` answers exactly as before. `places` is
208+
a whole number from 1 to 20, and a source declares at most one `nearest`. The
209+
rules, and every refusal, are in
210+
[the protocol](/docs/protocol/knowledge#ordering-for-the-asker).
211+
183212
## Searching inside chosen records
184213

185214
Pass `scope` to search only inside some records: the records a source indexes, or a parent record that source reaches through a lookup it lists in `metadataFields`.

‎content/docs/permissions/system-context.mdx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ One of the largest consumers of the flag;
190190
| 44 | Attachment access hooks return early (insert + update + delete, the referenced-file check on insert + update, and the read AST) | service-storage | Lose: attachment visibility scoping | `installAttachmentAccessHooks`, `installAttachmentFileReferenceGate`, `installAttachmentReadVisibility` |
191191
| 45 | Comment access hooks return early (insert + update + delete, and the read AST), and so do the activity and audit-log read gates (their read AST), the activity field redaction and the audit-log field redaction (the rows a read serves), the activity summary's message code (the rows a read serves), and the query guard over both objects' value-bearing columns (the read AST) | plugin-audit | Get: the whole activity row and the whole `sys_audit_log` row, its before/after snapshots included, and the activity row's stored summary code (`metadata.summary_message`), on `find` / `findOne` — the audit writer, each read gate's bounded probe and the activity backfill — and a filter, sort or grouping by those columns. Lose: comment visibility scoping, the narrowing of `sys_activity` and of `sys_audit_log` to rows whose parent record the caller can read, the redaction of a parent field's value from an activity row's text and recorded change and from a ledger row's before/after snapshots, the withholding of an activity row recording an update whose every changed field the reader is withheld, of a fired milestone row whose watched fields it is not all served, and of an unstamped row (on `count` and `aggregate` too, so a total agrees with the rows), the removal of that summary code from the activity row's `metadata` (its params are field values), and the refusal of a query over those columns for a reader withheld a field of the objects it can reach, and the withholding of those columns from such a reader's server-chosen search set (#34700) | `installCommentAccessHooks`, `installCommentReadVisibility`, `installActivityReadVisibility`, `installAuditLogReadVisibility`, `installActivityFieldRedaction`, `installAuditLogFieldRedaction`, `installActivitySummaryLocale`, `installParentFieldQueryGuard`, `withheldSearchColumns` |
192192
| 46 | Knowledge search returns hits unfiltered, and searches every source; a knowledge source is saved without its author being judged | service-knowledge, metadata-core, runtime | Lose: the permission filter over search results, and the source admission ahead of it — an `object` source over an object the caller's exposure decision refuses (disabled package, `apiEnabled` / `apiMethods` for `search`, a `sys_*` object without `enable.aiReadable: true`), or serving a field the caller may not query, is searched. Lose at the `/meta` and MCP save doors: the same admission asked for the author before a `knowledge_source` is saved (ADR-0161 K4), so the engine's own write saves a source over an object or a field no author was judged for. Lose at the package duplicate door: the same admission asked for the caller, for each knowledge source the copy would save. Lose at the package move-in door: the same admission asked for the caller, for each selected knowledge source the move saves again under the package | `applyPermissionFilter`, `admitSources`, `searchByKey`, `admitAuthoredSource`, `authoredKnowledgeSourceRefusal`, `refuseDuplicatedKnowledgeSources`, `handlePackagesRequest` |
193+
| 46a | Knowledge search under the system identity is not ordered for the asker: a source's `affinity` entries move nothing | service-knowledge | Get: every hit in the order its store answered, and no read of a user or business unit. Lose: nothing a user held. The system identity is no person, so it has no unit to order by; every other caller's user id and unit chain are read as that caller may read them | `resolveAffinityFacts` |
193194
| 47 | The inbound-mail read gates return early (the read AST) | service-mailbox | Get: every `sys_mail_message` and `sys_mail_association` row on `find` / `findOne` — the ingest writer and each gate's own pre-scan, which read the association and mailbox rows a decision needs. Lose: the narrowing of a message to callers who can read a record it is associated with or who own its mailbox (so the unassociated pool is restricted), and of an association to callers who can read the record it names (on `count` and `aggregate` too, so a total agrees with the rows) | `gateMiddleware` |
194195
| 47b | The inbound-mail ingest seam: `ingest` admits the system context ALONE, and `rematch` admits it without the organization, owner or `manage_mailboxes` check | service-mailbox | Get: a mail source hands a mailbox its messages, and server code re-matches any mailbox. Lose: nothing a user held — every other caller of `ingest` is refused (`PERMISSION_DENIED`), because an ingested message is shown on every record its correspondents' addresses match and a user who could hand the seam a message could write one in a correspondent's name; every other caller of `rematch` must be in the mailbox's organization and own the mailbox or hold `manage_mailboxes` | `ingest`, `authorizeRematch` |
195196
| 47c | The inbound-mail IMAP sync: `syncMailbox` and `syncAll` admit the system context ALONE | service-mailbox | Get: the sync job reads every mailbox row (its organization, address and IMAP cursor), writes the cursor back, and hands each fetched message to `ingest` under the system context. Lose: nothing a user held — every other caller is refused (`PERMISSION_DENIED`), because a sync stores a mailbox's mail and moves its cursor | `syncMailbox`, `syncAll` |
@@ -707,6 +708,7 @@ and CI refuses one that differs from what the tree produces.
707708
| `packages/runtime/src/sandbox/body-doors.ts#callerScopeOf` | 1 | 65b |
708709
| `packages/runtime/src/sandbox/body-runner.ts#executionContextFromHook` | 1 | 65 |
709710
| `packages/services/service-automation/src/runtime-identity.ts#stampSystemInsertOwner` | 1 | 60 |
711+
| `packages/services/service-knowledge/src/knowledge-affinity.ts#resolveAffinityFacts` | 1 | 46a |
710712
| `packages/services/service-knowledge/src/knowledge-service.ts#admitAuthoredSource` | 1 | 46 |
711713
| `packages/services/service-knowledge/src/knowledge-service.ts#admitSources` | 1 | 46 |
712714
| `packages/services/service-knowledge/src/knowledge-service.ts#applyPermissionFilter` | 1 | 46 |

‎content/docs/protocol/knowledge.mdx‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,85 @@ until a complete reindex writes it again. How many hits the scope removed is
10131013
logged, never returned, and an entry that reaches no source answers the same
10141014
empty result a source withheld from the caller gives.
10151015

1016+
### Ordering for the asker
1017+
1018+
A source may declare how its hits are ordered for the person asking
1019+
(`source.affinity`, ADR-0161's dated note of 2026-11-29 under K1): "the
1020+
policies of my own unit first". Each entry compares a field the source lists
1021+
in `metadataFields` with a fact the platform resolves about the caller.
1022+
1023+
```ts
1024+
source: {
1025+
kind: 'object',
1026+
object: 'policy',
1027+
content: ['title', 'body'],
1028+
metadataFields: ['business_unit', 'owner'],
1029+
affinity: [
1030+
// The caller's own unit first, then each parent unit in order, then the rest.
1031+
{ field: 'business_unit', caller: 'business_unit', mode: 'nearest' },
1032+
// A policy the caller owns passes up to 3 hits that match nothing.
1033+
{ field: 'owner', caller: 'user', mode: 'boost', places: 3 },
1034+
],
1035+
},
1036+
```
1037+
1038+
- **The caller facts** are a closed list of two. `user` is the caller's user
1039+
id, for a field that points at `sys_user` (a `user` field, or a lookup to
1040+
it). `business_unit` is the caller's primary business unit, then each parent
1041+
unit up to the root, for a lookup to `sys_business_unit`. A fact is
1042+
resolved at most once per search, only when a hit in the list belongs to a
1043+
source that declares an entry, and only if such an entry reads it. `user`
1044+
is the search's own user id and reads no row. `business_unit` is read by
1045+
the one resolver that also answers the MCP door's `get_current_user`: the
1046+
caller's user row for the primary unit, then each unit up the chain, every
1047+
read as the caller, so a unit the caller may not read ends the chain below
1048+
it. No organization row is read. A fault reading the units, other than a
1049+
refusal, leaves them out for that search and keeps the `user` fact. A fact
1050+
is never a tool argument, a `search` option, or a value a client or a model
1051+
supplies. The system identity has no
1052+
facts, and a caller with no primary unit has no chain: an entry that finds
1053+
no fact matches nothing.
1054+
- **`nearest`** parts the source's hits into tiers: the caller's own unit
1055+
first, then each parent in order, then every other hit together, a hit with
1056+
no value among them. A multi-value lookup takes its nearest element. A
1057+
source declares at most one, and its `caller` is `business_unit`.
1058+
- **`boost`** takes `places`, a whole number from 1 to 20 (the most hits one
1059+
`search_knowledge` answer carries). Inside a tier, with its hits numbered
1060+
from 1 in their order, a hit's key is its number minus the `places` of every
1061+
`boost` entry it matches; the tier is ordered by key, a tie going to the
1062+
larger sum, then to the earlier number. So a hit matching `places: 3`
1063+
passes at most three hits of its tier that match nothing. Several entries
1064+
add.
1065+
- **By position, never by score.** The search runs as it always did up to
1066+
its answer: the rounds, the scope check, the permission re-check and the
1067+
record-level grouping. The re-order then works on the units that could be
1068+
answered (passages, records or `groupBy` groups, each judged on the hit that
1069+
stands for it), before the cut to `topK`, so it reads no more passages than
1070+
the refill cap already allows. Only one source's units move, among the
1071+
places they hold: a hit of another source never moves. A hit keeps the
1072+
`score` its store answered, so an answer may no longer be in descending
1073+
`score`. Nothing in the answer says a hit moved; the count goes to the
1074+
`debug` log.
1075+
- **Never an access decision.** Nothing is dropped and nothing is admitted:
1076+
a hit outside the caller's unit is ordered later. Narrowing a search is the
1077+
[record scope](#record-scope); who may read a record is sharing, so there is
1078+
no `filter` mode. An entry is judged on the values the index stores, like a
1079+
scope term, and a document indexed before its source listed the field
1080+
matches nothing until a complete reindex writes it again.
1081+
- **No rebuild.** `affinity` enters neither the index fingerprint nor the
1082+
recipe hash. Listing a new field in `metadataFields` for it does change the
1083+
recipe hash, as it always did.
1084+
- **Refused when it is written**, each with a sentence that names the fix: a
1085+
`field` not listed in `metadataFields`, a `mode` other than `boost` and
1086+
`nearest` (`filter` is answered that narrowing is the search scope and
1087+
visibility is sharing), a caller fact outside the two, a second `nearest`,
1088+
`nearest` with `caller: 'user'`, `places` missing on a `boost`, present on a
1089+
`nearest`, or not a whole number from 1 to 20. Saving a source also refuses
1090+
a `field` that does not point at the object its `caller` names. A unit
1091+
read that fails for a reason other than a refusal leaves the units out of
1092+
that search, logged once at `warn`; its `business_unit` entries then match
1093+
nothing, and its `user` entries still apply.
1094+
10161095
### Source admission: exposure and field-level rules
10171096

10181097
A passage is built at index time, under a system context, from every

0 commit comments

Comments
 (0)