From 8a64f99ffd1d0056e85a3ea9fa233a8b4a12357c Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 16:56:11 +0000 Subject: [PATCH] =?UTF-8?q?docs(adr):=20ADR-0161=20dated=20note=20?= =?UTF-8?q?=E2=80=94=20item=2017,=20the=20typed=20scope=20a=20search=20han?= =?UTF-8?q?ds=20its=20adapter=20(#37324)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A second dated note under the table of K8, and a second Amended bullet in the header list. The note records the maintainer's ruling on Q3 (ruling record 7168192820) and gives item 17 its final shape: the member is AdapterSearchOptions.scope, a list of terms the service builds from scope: [{ object, ids }] and the adapter applies before it ranks. No code, no schema, no changeset. The status line is left as it is. Claude-Session: https://claude.ai/code/session_01JQwxbZmjM1KubX3ZAoJPPm Co-authored-by: Claude --- ...eturn-knowledge-source-is-a-governed-type.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/adr/0161-knowledge-platform-boundary-platform-owns-assembly-sync-split-record-return-knowledge-source-is-a-governed-type.md b/docs/adr/0161-knowledge-platform-boundary-platform-owns-assembly-sync-split-record-return-knowledge-source-is-a-governed-type.md index 971306f9089..eb7ab8d08ae 100644 --- a/docs/adr/0161-knowledge-platform-boundary-platform-owns-assembly-sync-split-record-return-knowledge-source-is-a-governed-type.md +++ b/docs/adr/0161-knowledge-platform-boundary-platform-owns-assembly-sync-split-record-return-knowledge-source-is-a-governed-type.md @@ -17,6 +17,7 @@ - **Leaves unchanged**: permission-aware retrieval (every object-source hit is re-read as the caller, and a source is searched for a caller only after the exposure and field-level admission of PR #36850); the reap guard of #4672 as landed; the signature and return type of `IKnowledgeService.search`; the settings shape of #33933 (knowledge settings only where the service is mounted), which #37102 keeps: without the capability token there is no knowledge service and no knowledge settings page; the open AI door, which stays MCP-only (cloud ADR-0119 D4). - **Inputs**: every code and docs text quoted below was read on `objectstack-ai/objectstack` `main` at `254e396a29`, the commit this record's branch starts from. Positions are in [Readings](#readings-taken-at-254e396a29). PR #36823 and PR #36850 are merged and are in that tree; PR #37075 is open and edits §6 of `content/docs/protocol/knowledge.mdx`, so the §6 quotations may move when it lands. - **Amended** (2026-11-25, [#37097](https://github.com/objectstack-ai/objectstack/issues/37097)): a dated note under the table of [K8](#k8--the-contract-additions-decided-item-by-item) records that the document hash of item 2 covers `organizationId` when the document has one (item 9), with no version bump. The status line above is left as it is. +- **Amended** (2026-11-25, [#37324](https://github.com/objectstack-ai/objectstack/issues/37324)): a second dated note under the table of [K8](#k8--the-contract-additions-decided-item-by-item) gives item 17 its final shape, `AdapterSearchOptions.scope?`: the typed scope the service builds from `scope: [{ object, ids }]`, on the maintainer's ruling of that day, 「也能指定上级对象(制度)」 (record `7168192820` on #37308). The status line above is left as it is. --- @@ -326,6 +327,22 @@ The epic holds the contract shut until this record merges ("No new adapter-contr > > Item 9's first reader, #37097, is built by PR #37256, and this change to item 2 lands with it. The reasoning is contract review [`7157191417`](https://github.com/objectstack-ai/objectstack/pull/37256#issuecomment-7157191417) on that PR (its M1 and S2). The table is left as written; read items 2 and 9 with this note. +> **Note (2026-11-25, [#37324](https://github.com/objectstack-ai/objectstack/issues/37324)) — item 17: the typed scope filter is `AdapterSearchOptions.scope?`, a list of terms the service builds from `scope: [{ object, ids }]` and the adapter applies before it ranks.** Item 17 is accepted with the shape below. Its open question was whether an entry may name a parent object. The maintainer ruled it on 2026-11-25 by choosing option B of the Q3 decision card, verbatim and untranslated: 「也能指定上级对象(制度)」 — 「直接给制度 id 就只在这份制度里搜;前提是知识源把指向制度的字段列为筛选字段,没列就返回空。1 个 PR,略大。」 (ruling record [`7168192820`](https://github.com/objectstack-ai/objectstack/issues/37308#issuecomment-7168192820) on #37308). So an entry names the object a source indexes, or a parent object the source reaches through a lookup field it lists in `metadataFields`, and a source that lists no such field answers nothing for the entry. A ◆ marks what this note decides past those words, for the approver to accept with it or strike. +> +> - **◆ The member.** `AdapterSearchOptions.scope?: AdapterScopeTerm[]`. A term is `{ kind: 'record', ids: string[] }`, which holds for a document whose `sourceRecordId` is in `ids`, or `{ kind: 'metadata', field: string, ids: string[] }`, which holds for a document whose `metadata[field]` is in `ids` or is a list with an element in `ids`. The adapter is handed terms it can apply, never `{ object, ids }`: turning an object into a field needs the object's definition, and reading that is the platform's (K1). +> - **◆ Absent, present, empty**, read as item 9's `organizationIds` is. Absent: no scope; every document of the source is ranked, as before the member. Present: only the documents some term holds for are ranked, and the filter runs BEFORE ranking, so `topK` is filled from in-scope documents alone. Empty: a list with no term ranks nothing, a term with no `ids` holds for no document, and neither is ever read as "no filter". `organizationIds`, `scope` and the opaque `filter` all apply: a document is ranked only when it passes each one that is present. +> - **How the service builds it**, per source, from `KnowledgeSearchOptions.scope?: Array<{ object: string; ids: string[] }>`. An entry that names the source's own object gives a `record` term. An entry that names another object gives a `metadata` term for the member of the source's `metadataFields` that points at that object, by the object's registered definition. A lookup is stored as a record id, and as a list of them under `multiple: true`, which is why a list is in scope when any element is. With no such member, or no registered definition, the entry does not reach the source. A source no entry reaches is not searched, and a `file` or `http` source answers nothing under a scope. +> - **◆ Four readings the ruling's words leave open.** (1) Several entries that reach one source give several terms, and a document is in scope when any term holds: a scope names a set of records. (2) An entry that names the source's own object is the `record` term and nothing else; a field of that object that points back at it (a `tree` field, a self-lookup) adds no term. (3) Only a `lookup` or a `master_detail` field is a parent link, and the object it points at is the spec's one answer, `packages/spec/src/data/field-value.zod.ts#referenceTargetOf`. A `user` field, whose target is fixed to `sys_user`, is not one: nothing scopes by user today, and it returns by a dated note with its reader. A field assembly withholds (credential-class, `internal`) is not one either: no document carries it. (4) A source that lists two or more such fields pointing at the entry's object is not reached by it, and the service logs that once per source, naming the fields. The other answers: a union of the fields, which answers "inside this policy" with clauses that only cite it through the other field; the first field listed, which gives the order of `metadataFields` a meaning no author wrote; and a key on the entry naming the field, which has no consumer and returns by a dated note with its reader. +> - **What a scope does not reach.** A parent two hops away (policy → chapter → clause) is not covered: only a field of the indexed object itself reaches a parent. A scope entry that reaches no searched source answers no hits, the same empty answer a caller gets when the source is withheld from them, so the answer never tells which of the two it was. +> - **◆ The service's guarantee, whatever the adapter does.** After the adapter answers, the service checks every hit against the terms and drops the ones none holds for. It judges a `record` term on `KnowledgeHit.sourceRecordId` and a `metadata` term on `KnowledgeHit.metadata[field]`, and drops a hit that does not carry the value (fail closed). So an adapter returns the document's metadata on its hits, as `knowledge-memory` does. No capability flag is added: `capabilities.chunks` stays the one flag, and the service learns from the answer. The first time an adapter returns a hit that check drops, the service logs once for that adapter: it does not apply `scope` before ranking, or it returns hits without the document's metadata, and its scoped searches may answer fewer than `topK` (rule 2: nothing is skipped silently). +> - **◆ Judged on the index copy; never an access decision.** The adapter and the service judge the same values, the ones assembly stored with the document, fresh as of the last sync, so an adapter that applies the member loses no hit to the service's check. A document indexed before its source listed the field is in no scope through it until a complete reindex writes it again. Scope narrows and never widens. The access decision stays the permission re-read of the live row, for every hit (`applyPermissionFilter` of `packages/services/service-knowledge/src/knowledge-service.ts#KnowledgeService`). +> - **No new permission question.** Source admission (`packages/services/service-knowledge/src/knowledge-source-admission.ts#admitSourceFields`) already requires every `metadataFields` member an index carries to be queryable by the caller before the source is searched for them; the system identity bypasses it, as it bypasses the re-read. So "that field in ids" is a filter the caller could run on the object's own rows. ◆ The parent row is never read and need not be readable by the caller. How many hits the scope or the permission filter removed is never returned to the caller (K9 rule 6, K10 rule 4); it goes to logs only. +> - **◆ The opaque `filter` stays as it is**, on `AdapterSearchOptions` and on `KnowledgeSearchOptions`: handed through, adapter-specific, and checked by nothing in the service after the adapter answers. The typed scope is never built from it, and the service's check judges the typed scope alone. Its readers in this tree are `knowledge-memory` (`matchesFilter`: metadata equality, before ranking) and `knowledge-ragflow`, which #37004 retires; no caller in this tree passes one, tests aside. Whether it retires is its own card, not this note's. +> - **The suite cases the member lands with** (rule 1; `packages/services/service-knowledge/src/testing.ts#runKnowledgeAdapterContract`). On the adapter, for each term kind: filtered before ranking, so `topK` is filled from in-scope documents; an empty list ranks nothing; without the member every document is ranked, as before. Through a real `KnowledgeService`, over an adapter that ignores the member: no out-of-scope hit is answered, and the service logs once. +> - **Not here.** `KnowledgeSearchOptions.scope` is an option of the service, not a member ("What counts as a member", below). #37308 bounds it, in entries and in ids per entry, with a coded refusal (ADR-0112) before any adapter is called, and states the bounds on the member so that an adapter can rely on them; this note fixes no number. The `scope` argument of `search_knowledge` is row 12, #37311 (K9 rule 2). Record-level return is #37103. +> +> This note adds exactly one member, `AdapterSearchOptions.scope` with its term type, and no other: the list stays closed beyond it (rules 3 and 5). #37308 builds it after this note merges, in one PR: the member, its first reader in `knowledge-memory`, and the suite cases. The code this note cites was read on `main` at `829a45e96c`. The table is left as written; read item 17 with this note. + **What "capabilities" became.** #36990's rule named "capabilities" among the members that waited for this record. Two things answer it. A method that is absent is the capability signal for listing, dropping, status, and the start and end of a build: the service asks whether the method is there. One flag covers what a method cannot say, `capabilities.chunks` (item 5). No wider descriptor is added. **What counts as a member** (for rule 5 below, and for the epic's "no new adapter-contract member"). A member is anything an adapter author must read to be correct: