Skip to content

service-knowledge: search takes a record scope (scope: [{ object, ids }]) and hands adapters a typed filter they apply before ranking #37308

Description

@objectstack-fleet

repo:cloud#1 · os-warren · session_01JQwxbW5anP6GDaVi5LKi2U
Body edit 2026-11-25T16:44Z by the epic seat: Blocked-by: gains the ADR card that lands first.
Ruled: 7168192820 · Q3 letter B · 2026-11-25T16:37Z

Filing gate: ③ maintainer-directed (topic child). Source: topic #37000; maintainer 2026-11-25 「现在拆阶段三」 (decision card in the project thread) and 「#4 只负责在手任务,你接手专题剩余任务」. Reviewed by an independent Fable pass before filing.
Grading: area:ai · Feature · p2 (topic) · reach: apps that mount service-knowledge and need to search inside chosen records · evidence: read.

维护者速读

  • 做什么:检索可以限定范围,比如「只在这一份制度里搜」:调用方给出对象和记录 id,平台只返回这些记录里的片段,向量存储在排序前就按范围过滤,所以「前 5 条」都在范围内。
  • 谁受益:制度问询在用户打开某份制度时只在这份里找;以后 AI 工具(第 12 行)也用它。
  • 要知道的:范围只会缩小可见结果,不会放宽权限;每条命中仍按提问人的权限重新读取。
  • 需要你做的:合并一条 ADR 补充说明(范围过滤的接口形状,含一个要你定的问题:范围能否指上级对象)。

What

Carries ADR-0161 (docs/adr/0161-knowledge-platform-boundary-platform-owns-assembly-sync-split-record-return-knowledge-source-is-a-governed-type.md) Execution row "rows 11, 12": K8 item 17 ("A typed form for what is an opaque filter record on AdapterSearchOptions today, built by the service from scope: [{ object, ids }]", first reader row 11). K9 rule 2's scope argument is row 12's.

  1. The final shape first (K8 rules 3 and 5). Item 17 is marked "Deferred" with no final shape. Decide it as a dated note under K8's table, landed first, as its own PR (a docs/adr change in a mixed diff makes the whole PR Tier H; PR docs(adr): ADR-0161 dated note — the document hash covers the organization of a document that has one (K8 items 2 and 9) #37263 went first for service-knowledge: documents carry their organization, and search hands the caller's organizations to the adapter #37097). The note answers: the member's name and type on AdapterSearchOptions (packages/spec/src/contracts/knowledge-adapter.ts:41); whether object in a scope entry must be the object a source indexes, or may name another object reached through a field the source projects (Decision needed, Q3, below); and whether the opaque filter (:47) stays beside it.
  2. KnowledgeSearchOptions.scope? (packages/spec/src/contracts/knowledge-service.ts:26): a list of { object, ids }. An option of IKnowledgeService, not a contract member (K8 "What counts as a member"); search's signature and return type do not change (K9 rule 3). State and enforce bounds (entries, ids per entry) with a coded refusal (ADR-0112) past them.
  3. The service (packages/services/service-knowledge/src/knowledge-service.ts, search at :521): with a scope, a source whose object no entry reaches is not searched; for the others the service builds the typed filter and passes it to the adapter beside organizationIds (:540). After the adapter answers, the service drops every hit outside the scope whatever the adapter did, because an adapter written before the member ignores it (K8 rule 2: nothing skipped silently — the service logs once per adapter that it ranks before filtering). A non-object source, while one exists, answers nothing under a scope. Scope narrows; the permission re-read (applyPermissionFilter, :925) stays the access decision.
  4. The adapters. knowledge-memory (packages/plugins/knowledge-memory/src) filters before ranking as the reference; a contract-suite case in packages/services/service-knowledge/src/testing.ts pins "filtered before ranking: topK is filled from in-scope documents". Every in-tree adapter on main that runs the suite when this lands implements it (knowledge-pgvector from knowledge-pgvector: an open vector store on PostgreSQL — tables, exact search, listing, chunks #37100 and knowledge-turso from knowledge-turso moves into objectstack: Apache-2.0, the platform embedder and splitter, listing, generations, the contract suite #37107 if they have landed; otherwise their cards pick the case up).
  5. Docs. content/docs/protocol/knowledge.mdx (search options) and content/docs/ai/knowledge-rag.mdx.

Rulings carried (ADR-0161 K10): the member lands with its first reader and a contract-suite case in this PR; answers read content as the asking user; the count of hits the scope or the permission filter removed is never returned to the caller (logs only).

Acceptance

  • A source over 20 records, scope: [{ object, ids: [two ids] }], topK: 5: every hit belongs to those two records, and the page is full when they hold five matching passages.
  • A stub adapter that ignores the typed filter: no out-of-scope hit is returned; the service logs once.
  • A scope naming an object no searched source reaches: that source answers nothing; nothing in the result says how many hits were dropped.
  • A caller who cannot read one of the scoped records gets no hit from it.
  • Bounds exceeded: a coded refusal naming the bound.
  • The contract suite passes on knowledge-memory and on every in-tree adapter that runs it.
  • Container run per AGENTS.md.

Out of scope

Decision needed

维护者速读(待你定)

  • 问题:制度问询要「只在这一份制度里找」,但索引是按条款建的。只能按条款的记录指定范围时,调用方得先把这份制度的所有条款查出来,才能限定检索。
  • 选项:A 范围只能写知识源自己的对象(条款),一个 PR;B 范围也能写上级对象(制度),前提是知识源把指向制度的字段列在筛选字段里,平台自动换算,同样一个 PR,略大。
  • 推荐 B:用户在一份制度上提问是这个专题第三阶段写明的场景,按条款列范围要每次多一次查询。
  • 不定会怎样:范围过滤的接口形状定不下来,第 11、12 行都开不了工。

Q3 — May a scope entry name a parent object

Problem. A user asking inside one policy expects answers from that policy only, but the index holds clauses; if a scope can only name clause records, every caller must first list a policy's clauses.

Governing text. ADR-0161 K8 item 17: "A typed form for what is an opaque filter record on AdapterSearchOptions today, built by the service from scope: [{ object, ids }]" — decision "Deferred", no final shape. Epic #37000 phase 3 outcome: 「并能限定在一份制度里搜」. K8 rule 3: "A reader card that finds one cannot be built as written stops and says so on its card; the change is a dated note on this record."

Protocol. The dated note decides the member; KnowledgeSearchOptions.scope is not a member. No metadata key either way (the parent link is an existing metadataFields member).

Premise, re-check. grep -n "filter" packages/spec/src/contracts/knowledge-adapter.ts (the opaque record at :47); grep -n "metadataFields" packages/spec/src/ai/knowledge-source.zod.ts (:72).

Option What it does What the customer sees Effort
A — the source's own object only a scope entry names the indexed object; the typed filter is "source record id in ids" an app scopes to one policy by listing its clauses first (an extra read per question) domain:server · 1 PR plus the note PR · no measured precedent
B — own object, or a parent reached through a projected lookup as A, plus: an entry naming another object is valid for a source that lists a lookup field to that object in metadataFields; the typed filter becomes "that field in ids", applied before ranking an app scopes to one policy by its id; a source without that projection answers nothing for the entry domain:server · 1 PR plus the note PR, somewhat larger (the field resolution and one more suite case) · no measured precedent

Business meaning: A is "search these pages"; B is "search this binder", provided the binder label was printed on each page.

os-decision-facets
① Long-term: B keeps record-level scoping in the platform instead of every caller re-deriving child ids; it uses a field the author already declared, adding no key.
② Business pull: BrightRule's policy inquiry is the named consumer and indexes clauses under a policy.
③ AI-error: both are closed shapes; B answers nothing (not everything) when the projection is missing — a loud empty, stated in the tool description by row 12.
④ Startup scope: neither adds a metadata key; B adds one resolution path.
Prior rulings read: knowledge scope parent object → 200 hits (open #37000, #37103, #37100, #37098 — none rules on scope); ADR-0161 K8 item 17; thread: none.

Recommendation: B. End state: retrieval scoped by the business container the user is looking at, as search engines filter on a parent or join field. Confidence gap: a parent two hops away (policy → chapter → clause) is not covered by B; the note says so.
Self-check: only ① gives B; ②③④ flip it: no.
After the ruling: the dated note PR (Tier H) records the chosen shape; this card then builds it.

Blocked-by: #37324 (the dated ADR-0161 K8 note that fixes the scope member; docs/adr lands as its own card).
Done: #36993 (PR #37301; the refill a scope post-filter relies on), #37096 (row 2, the epic's listed blocker). Coordinates with #37103 (same function; whichever lands second merges main).
Parent: #37000. Reader: domain:server lane (packages/services/service-knowledge, packages/plugins/knowledge-*; spec edits per spec.md); the dated ADR note through the Tier H path.
Dedupe: knowledge scope filter 441 (open: #37103, #37100, #37107, #37098 — each names "the typed filter (row 11)" as out of scope; none builds it) · AdapterSearchOptions filter 2 (none open) · knowledge typed filter 131 (open: #37100, #37107, as above).

Activity

  1. added
    priority:p2
    needs-user-decision
    area:ai
    domain:server
    on Nov 25, 2026
  2. objectstack-fleet commented on Nov 25, 2026

    @objectstack-fleet
    ContributorAuthor

    triage#1 · os-warren · session_01JQwxbZKP5YM48rWMWTS7wE

    First touch 2026-11-25T14:34Z. Confirmed as filed: Feature · area:ai · domain:server · p2, needs-user-decision (row 11). It is a row of topic #37000, so it routes to repo:objectstack#1 (maintainer 13:49Z 「继续专题 开发 37000」). It waits on the maintainer's ruling and on #36993.

  3. objectstack-fleet commented on Nov 25, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:cloud#1 · os-warren · session_01JQwxbXE9zoxu8jDCNXN8CC
    Ruling: decision thread · Q3 · letter B · maintainer 「也能指定上级对象(制度)」 2026-11-25T16:33Z

    The maintainer tapped option B on the Q3 decision card in the project decision thread at 2026-11-25T16:31:50Z. The card read: 「问题三:检索范围能否直接指定整份制度?」, option 「也能指定上级对象(制度)」 — 「直接给制度 id 就只在这份制度里搜;前提是知识源把指向制度的字段列为筛选字段,没列就返回空。1 个 PR,略大。」

    What is ruled. B — a scope entry may name the source's own object, or a parent object reached through a lookup field the source lists in metadataFields; the typed filter becomes "that field in ids", applied before ranking. A source without that projection answers nothing for the entry (a loud empty, which row 12's tool description states). A parent two hops away is not covered; the dated note says so.

    Effort of the chosen letter (card's effort column): domain:server · 1 PR plus the dated ADR-0161 note PR, somewhat larger than A (the field resolution and one more contract-suite case).

    Execution. Item 1's dated note under ADR-0161 K8 lands first as its own Tier H PR and records shape B; this card then builds it.

    State. needs-user-decision → pm:queue: the card's only blocker, #36993, closed completed at 2026-11-25T15:34:07Z by PR #37301 (merged), read now. Coordinates with #37103 (same function) as written.

  4. added
    pm:queue
    pm:blocked
    and removed
    needs-user-decision
    pm:queue
    on Nov 25, 2026
  5. objectstack-fleet commented on Nov 25, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:cloud#1 · os-warren · session_01JQwxbW5anP6GDaVi5LKi2U

    Claim: PM loop round 2 (epic #37000 owner seat, card thread; step 2 of #37308, the code)
    Session: session_01JQwxbW5anP6GDaVi5LKi2U
    Thread session: session_01JQwxbZmjM1KubX3ZAoJPPm
    Account: os-warren
    Branch: claude/project-thread-3zr6fx
    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 scope option, the typed filter member and KnowledgeHit.metadata TSDoc only), packages/spec/src/ai/knowledge-document.zod.ts (the KnowledgeHit.metadata TSDoc sentence only; amended at review, PR #37342), the generated spec artifacts that regenerate from these, packages/core/src/security/second-object-read-exposure.pin.test.ts (one CALLERS row for knowledge-search-scope.ts only; maintainer approved on the thread's decision card 2026-11-25 22:48Z), packages/plugins/knowledge-memory/**, packages/plugins/knowledge-pgvector/** (the scope filter in its search SQL as bound parameters, implements.scope and its suite cases only; added 2026-11-25 23:3xZ because #37100 landed first and card item 4 makes every in-tree adapter on main implement the case), content/docs/protocol/knowledge.mdx, content/docs/ai/knowledge-rag.mdx, .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: none
    Responsibility: n/a — not a defect card
    Thread-read: 7168192820
    Premise: holds (Blocked-by #37324 closed; its note PR #37329 merged as 13ffe1c and fixes the K8 item 17 member; ruling 7168192820 Q3 = B)
    Serial constraints cleared: #37103 (this seat, PR #37335, draft) changes search() and KnowledgeSearchOptions in the same files; build on #37335's shape, the second to land merges main. #37100 (this seat, branch claude/project-thread-vcp8s3) changes search() for K7 rule 5; overlap-check before each push. #37311 (row 12) adds the scope argument to search_knowledge later and waits for this card.

    Ownership: maintainer 2026-11-25 13:49Z, 「#4 只负责在手任务,你接手专题剩余任务」; ruling as cited. Clause-② yes: the scope option and the typed filter member widen the published search contract and owe a contract review at the ceiling tier before the queue. Carried from the #37329 review: hit metadata TSDoc and pin, string id compare and pin, an empty scope never reads as "no scope", the bounds on the member's TSDoc, and the opaque filter finding in the PR's acceptance notes.

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

    @objectstack-fleet
    ContributorAuthor

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

    Card thread report for #37308 at head 857a2e20, 2026-11-25T19:26Z. Default tier, effort high, as the claim (7170857814) orders.

    {
      "issue": 37308,
      "status": "done",
      "branch": "claude/project-thread-3zr6fx",
      "pr": "https://github.com/objectstack-ai/objectstack/pull/37342",
      "session": "session_01JQwxbZmjM1KubX3ZAoJPPm",
      "premise_still_valid": true,
      "summary": "Draft PR #37342 builds ADR-0161 K8 item 17 as the 2026-11-25 note (#37324, 13ffe1c0) shapes it, in one PR: KnowledgeSearchOptions.scope [{ object, ids }] and AdapterSearchOptions.scope / AdapterScopeTerm in spec (types and TSDoc only; bounds 10 entries x 500 ids stated on both members); service-knowledge knowledge-search-scope.ts (bounds with VALIDATION_ERROR 400 before any adapter call; per-source terms: own object -> record term, a parent -> the one listed lookup/master_detail field whose referenceTargetOf is that object; user, withheld, unreadable-target and two-or-more links reach nothing; hit check by String(v), lists by any element, fail closed); search() validates first and drops unreached sources (an empty scope asks no adapter); searchRound hands each adapter a copy of its terms and checks every hit, warn once per adapter; knowledge-memory applies scope before ranking; contract suite gains required implements.scope with per-term-kind adapter cases and service-level cases incl. the adapter with the member stripped; docs (protocol Record scope section, RAG guide section); patch changeset with Clause-②: yes / Metadata-protocol: none.",
      "tests": "service-knowledge: 12 files / 323 tests pass (new knowledge-search-scope.test.ts; new 'search scope' describe in knowledge-service.test.ts covering every Acceptance bullet of the card); knowledge-memory: 2 files / 44 tests pass; both packages typecheck incl. check:test-typecheck. Mutation checks, reverted: memory adapter without its scope filter -> 7 suite cases red; service without the after-answer check -> 7 cases red.",
      "gates": "dispatch-gates --commands derived 118 at the head's path set; all run, final record 118 x exit 0 (three first answered 3: teardown self-test needed its pinned fixture fetched, check:skill-examples and check:dual-build-cjs-loads needed builds; each re-run after the prerequisite, both pass). --ran: 'Run reconciliation — 118 derived, 118 run, 0 NOT-MEASURED, 0 UNRUN.' 25 doc-family commands re-run at 857a2e20 after a doc-only section move, all 0. spec check:generated --fix regenerated api-surface/contracts.json and export-origins/contracts.json. PR check-runs: pending at report time.",
      "dogfood_battery": "n/a — no `!` in the PR title and no (narrowing) arm",
      "mcp_calls": "0 GitHub MCP calls; one subscribe_pr_activity on #37342",
      "api_writes": "2 — relay pr_create (#37342 draft, assignee os-warren), and this comment",
      "open_questions": [],
      "security_findings": "none",
      "surface_breaches": [
        "packages/spec/api-surface/contracts.json and packages/spec/export-origins/contracts.json — generated artifacts check:generated requires for the new export AdapterScopeTerm; outside the claimed file list.",
        "Not touched although owed by carry item 1: KnowledgeHit.metadata TSDoc lives in packages/spec/src/ai/knowledge-document.zod.ts (outside the surface, also edited by #37335); the requirement is stated on AdapterSearchOptions.scope and pinned by suite and service cases. Seat decides: extend the surface for a one-line TSDoc, or leave.",
        "Not touched: scripts/adr-anchors (outside the surface); pnpm check:adr-anchors exits 0 without an entry; #37329's body said the code PR anchors the member. Seat decides: surface extension or follow-up."
      ],
      "overlap": "overlap-check at 857a2e20: main merges cleanly. #37335 conflicts in knowledge-service.ts only (one line after `let sources`, keep both filters; trial merge done locally). #37337 (#37100) conflicts in knowledge-service.ts (searchRound), testing.ts, the two implements lines and protocol knowledge.mdx's suite sample. #37265 now clean after moving the RAG-guide section. #37187 clean. Whichever lands second merges main; this thread merges main once #37335 lands.",
      "out_of_scope_findings": [
        "carrier: none · noted, not filed — KnowledgeSearchOptions.filter / AdapterSearchOptions.filter has no producer in this tree (createKnowledgeTools, the one non-test caller of IKnowledgeService.search, passes none) and gets no service guarantee; unchanged here; its retirement is its own card. Dedupe words: knowledge opaque filter, AdapterSearchOptions filter retire, KnowledgeSearchOptions filter producer",
        "carrier: none · noted, not filed — knowledge-ragflow does not run the contract suite and ignores scope; the service check keeps its answers in scope (a parent scope answers nothing from it when its hits carry no metadata). #37004 retires it."
      ]
    }

    Decided here, where the note left it to this PR (each written in the PR's Acceptance notes): an empty scope or an entry with no ids is answered empty, never refused, and asks no adapter; bounds 10 x 500; answered stays the adapter's own count, so the refill after the permission filter counts records among hits that passed both checks; log levels warn (ignoring adapter, once per adapter; two-lookup ambiguity, once per source and object) and debug (unreached source); an entry with any key besides object/ids, and any id that is not a non-empty string, is refused. The PR owes a ceiling-tier contract review (CONTRACT_REVIEW_TIER) for the new member.

  8. objectstack-fleet commented on Nov 25, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:cloud#1 · os-warren · session_01JQwxbW5anP6GDaVi5LKi2U

    ACCEPT → PR #37342 comment 7176979005 (round 3: L1 ACCEPT + contract review PASS at head d1ca7f0; rounds 1 and 2 REWORK 7172822171, 7173187773). The census row was added after the maintainer's approval on the thread's decision card. Not governed; CI green at that head (the cancelled PR-body guards run was superseded by a green re-run); readied and in the merge queue. #37311 (row 12) can start after this merges.

  9. removed
    pm:dispatched
    on Nov 26, 2026
  10. github-actions commented on Nov 26, 2026

    @github-actions
    Contributor

    os-closed-card-sweep — machine-findable marker for this generated comment.

    Removed the pm-loop state label(s) this closed card no longer claims: pm:dispatched.

    A state label claims work is in flight. This card is closed on a merged delivery, so the claim
    is stale; every other label is left exactly as it was found. Nothing here is a judgement about
    the card, and no verdict-bearing label is ever touched by this sweep.

    posted by half-state-patrol run 45733194792 · trigger workflow_dispatch

    Generated by Claude Code

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