Skip to content

Commit 43de68d

Browse files
committed
docs(knowledge): every record-level unit statement names the document unit
The topK TSDoc in the knowledge-service contract, and in search_knowledge the topK, granularity and groupBy input descriptions, the matching input and output TSDoc and the granularity refusal, say that for a source that declares documentBy (its document unit) a record-level result counts one hit per parent record instead. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5oQLfL8thb6wtUHnTb
1 parent e0ebb9a commit 43de68d

2 files changed

Lines changed: 22 additions & 11 deletions

File tree

‎packages/services/service-knowledge/src/knowledge-tools.ts‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,16 @@ export interface SearchKnowledgeInput {
111111
topK?: number;
112112
/** Search only inside these records, or inside the children of these parent records (ADR-0161 K8, item 17). */
113113
scope?: SearchKnowledgeScopeEntry[];
114-
/** One hit per passage (`chunk`, the default) or per record (`record`) (ADR-0161 K1). */
114+
/**
115+
* One hit per passage (`chunk`, the default) or per record (`record`)
116+
* (ADR-0161 K1); under `record`, for a source that declares `documentBy` (its document unit), one hit per parent record instead.
117+
*/
115118
granularity?: SearchKnowledgeGranularity;
116-
/** One hit per value of this metadata field instead of per record; implies `granularity: 'record'`. */
119+
/**
120+
* One hit per value of this metadata field instead of per record (or per
121+
* parent record, for a source that declares `documentBy`); implies
122+
* `granularity: 'record'`.
123+
*/
117124
groupBy?: string;
118125
}
119126

@@ -178,7 +185,9 @@ export interface SearchKnowledgeRefusedSource {
178185
export interface SearchKnowledgeOutput {
179186
/**
180187
* The hits, most relevant first, at most `topK`: passages, or one per
181-
* record under `granularity: 'record'`, or one per group under `groupBy`.
188+
* record under `granularity: 'record'` (one per parent record, for a source
189+
* that declares `documentBy`, its document unit), or one per group under
190+
* `groupBy`.
182191
* No count of what the permission re-check or the scope removed, and
183192
* nothing derived from one (ADR-0161 K9, rule 6).
184193
*/
@@ -260,7 +269,7 @@ const SEARCH_KNOWLEDGE_PARAMETERS: Record<string, unknown> = Object.freeze({
260269
type: 'integer',
261270
minimum: 1,
262271
maximum: SEARCH_KNOWLEDGE_MAX_TOP_K,
263-
description: `At most this many hits (default ${SEARCH_KNOWLEDGE_DEFAULT_TOP_K}): passages, or records or groups under \`granularity: "record"\` or \`groupBy\``,
272+
description: `At most this many hits (default ${SEARCH_KNOWLEDGE_DEFAULT_TOP_K}): passages, or records (parent records, for a source that declares \`documentBy\`, its document unit) or groups under \`granularity: "record"\` or \`groupBy\``,
264273
},
265274
scope: {
266275
type: 'array',
@@ -286,11 +295,11 @@ const SEARCH_KNOWLEDGE_PARAMETERS: Record<string, unknown> = Object.freeze({
286295
granularity: {
287296
type: 'string',
288297
enum: ['chunk', 'record'],
289-
description: 'One hit per passage (`chunk`, the default) or per record (`record`)',
298+
description: 'One hit per passage (`chunk`, the default) or per record (`record`); under `record`, for a source that declares `documentBy` (its document unit), one hit per parent record instead',
290299
},
291300
groupBy: {
292301
...NAME_SCHEMA,
293-
description: 'One hit per value of this indexed field instead of per record; not with `granularity: "chunk"`',
302+
description: 'One hit per value of this indexed field instead of per record (or per parent record, for a source that declares `documentBy`); not with `granularity: "chunk"`',
294303
},
295304
},
296305
required: ['query'],
@@ -438,7 +447,7 @@ function parseInput(input: unknown): SearchKnowledgeInput {
438447
if (record.scope !== undefined) parsed.scope = parseScope(record.scope);
439448
if (record.granularity !== undefined) {
440449
if (record.granularity !== 'chunk' && record.granularity !== 'record') {
441-
throw refusal('VALIDATION_ERROR', 400, '`granularity` is "chunk" (one hit per passage) or "record" (one hit per record).');
450+
throw refusal('VALIDATION_ERROR', 400, '`granularity` is "chunk" (one hit per passage) or "record" (one hit per record, or per parent record for a source that declares `documentBy`).');
442451
}
443452
parsed.granularity = record.granularity;
444453
}

‎packages/spec/src/contracts/knowledge-service.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ export interface KnowledgeSearchOptions {
2929
/**
3030
* Max number of hits to return. Adapters may cap further. Under
3131
* `granularity: 'record'` it counts records (or `groupBy` groups), not
32-
* passages.
32+
* passages. For a source that declares `documentBy` (its document unit),
33+
* it counts parent records instead.
3334
*/
3435
topK?: number;
3536
/**
@@ -40,8 +41,8 @@ export interface KnowledgeSearchOptions {
4041
* record, so `topK` counts records. For a source that declares
4142
* `documentBy` (its document unit), one hit per parent record instead —
4243
* the best passage among that parent's records, the parent read from the
43-
* hit's `metadata[documentBy]` — and a record with no parent is its own
44-
* hit; two sources never share a parent. Each hit returned is checked against
44+
* hit's `metadata[documentBy]`, so `topK` counts parent records — and a
45+
* record with no parent is its own hit; two sources never share a parent. Each hit returned is checked against
4546
* the record as it reads now: a record that was deleted, left the
4647
* source's `where`, or changed since it was indexed is not returned, and
4748
* its document is repaired in the background — except in a source with
@@ -53,7 +54,8 @@ export interface KnowledgeSearchOptions {
5354
granularity?: 'chunk' | 'record';
5455
/**
5556
* Group record-level hits by the value of this metadata field instead of by
56-
* record — "which policies", not "which clauses" — keeping the best hit of
57+
* record (or by parent record, for a source that declares `documentBy`) —
58+
* "which policies", not "which clauses" — keeping the best hit of
5759
* each group; the group value is the hit's `metadata[groupBy]`, and hits
5860
* with the same value form one group whichever source they come from. Implies
5961
* `granularity: 'record'`; passing it with `granularity: 'chunk'` (or

0 commit comments

Comments
 (0)