Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .changeset/38537-knowledge-document-by.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
'@objectstack/spec': minor
'@objectstack/service-knowledge': minor
'@objectstack/platform-objects': minor
---

feat(knowledge): a knowledge source declares its document unit, `source.documentBy`; record-level search answers one hit per parent for it

Clause-②: yes (widening)
Metadata-protocol: added

A `knowledge_source` may now name the field that links each indexed record to the parent record it is part of: `source: { kind: 'object', object: 'policy_clause', content: ['body'], metadataFields: ['policy'], documentBy: 'policy' }`. For such a source, `search` / `search_knowledge` with `granularity: 'record'` and no `groupBy` returns one hit per parent (that parent's best passage) instead of one per record. The parent id is in the hit's `metadata[documentBy]` on `search`, and also in `groupValue` on a `search_knowledge` hit. A record with no parent is still its own hit, and two sources never share a parent. An explicit `groupBy`, `granularity: 'chunk'`, and every source without `documentBy` answer exactly as before.

The index does not change: still one document per record. `documentBy` enters neither the index fingerprint nor the recipe hash, so setting it rebuilds nothing (listing the parent field in `metadataFields` for the first time does, as any new metadata field does).

`documentBy` must be listed in `metadataFields`, or the parse refuses it and says to add it there. Saving a source through Studio, the metadata API or MCP also refuses a field that is not a single-valued parent link: it must be a `lookup` or `master_detail` field, not `multiple: true`, and neither a credential nor an `internal` field. A `text` or `user` field is refused, with a message naming the fix.

Studio's knowledge source form offers the key as a "Document unit" field picker beside the filter fields (its label and help translated in the platform's metadata-form bundles).
2 changes: 2 additions & 0 deletions content/docs/references/ai/knowledge-source.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const result = KnowledgeRefreshPolicySchema.parse(data);
| **content** | `string[]` | ✅ | Fields whose text is indexed, in order; every name is listed (no wildcard) |
| **contentFields** | `never` | optional | [REMOVED] `knowledge_source.source.contentFields` was removed in @objectstack/spec 19.0.0 (ADR-0161 K6) — the key is spelled `content` now that a source is a metadata item; use `content`. Rename the key; the value (a list of field names) is unchanged, except that a `'*'` member is no longer accepted and is replaced by the field names it stood for. A source registered in code (`KnowledgeServicePlugin({ sources })`, `registerSource`) is in no stack collection, so `os migrate meta` lists no edit for it: make this edit in the registration itself. Run `os migrate meta --from 18` to list the mechanical edits for existing sources; `--write` applies the ones it can prove, and you apply the rest by hand. |
| **metadataFields** | `string[]` | optional (default: `[]`) | |
| **documentBy** | `string` | optional | Field linking each record to its parent document (a lookup or master_detail listed in metadataFields); record-level search answers one hit per parent |
| **where** | `Record<string, any>` | optional | |
| **split** | `{ strategy: Enum<'whole' \| 'recursive' \| 'markdown'>; maxChars?: integer; minChars?: integer }` | optional | How the service cuts this object's documents into passages; omitted means recursive |

Expand Down Expand Up @@ -126,6 +127,7 @@ const result = KnowledgeRefreshPolicySchema.parse(data);
| **content** | `string[]` | ✅ | Fields whose text is indexed, in order; every name is listed (no wildcard) |
| **contentFields** | `never` | optional | [REMOVED] `knowledge_source.source.contentFields` was removed in @objectstack/spec 19.0.0 (ADR-0161 K6) — the key is spelled `content` now that a source is a metadata item; use `content`. Rename the key; the value (a list of field names) is unchanged, except that a `'*'` member is no longer accepted and is replaced by the field names it stood for. A source registered in code (`KnowledgeServicePlugin({ sources })`, `registerSource`) is in no stack collection, so `os migrate meta` lists no edit for it: make this edit in the registration itself. Run `os migrate meta --from 18` to list the mechanical edits for existing sources; `--write` applies the ones it can prove, and you apply the rest by hand. |
| **metadataFields** | `string[]` | optional (default: `[]`) | |
| **documentBy** | `string` | optional | Field linking each record to its parent document (a lookup or master_detail listed in metadataFields); record-level search answers one hit per parent |
| **where** | `Record<string, any>` | optional | |
| **split** | `{ strategy: Enum<'whole' \| 'recursive' \| 'markdown'>; maxChars?: integer; minChars?: integer }` | optional | How the service cuts this object's documents into passages; omitted means recursive |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3553,6 +3553,10 @@ export const arMetadataForms: NonNullable<TranslationData['metadataForms']> = {
label: "Filter fields",
helpText: "Fields kept beside each passage, so a search can filter on them (for example a status or an owner). Each one must be a field you may query."
},
"source.documentBy": {
label: "Document unit",
helpText: "Optional. The field that links each record to the parent record it is a part of (a clause to its policy): a lookup or master-detail field, single-valued, also listed in Filter fields. A record-level search then answers one hit per parent instead of one per record; a record with no parent is its own hit. The index is unchanged and nothing is rebuilt."
},
"source.where": {
label: "Records to index",
helpText: "An ObjectQL filter on the object, for example {\"status\": {\"$ne\": \"done\"}}. Only the records it matches are indexed. Blank: every record."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export const arGeneratedSourceHashes: Readonly<Record<string, string>> = {
"metadataForms.knowledge_source.fields.refresh.onRecordChange.label": "53a3285b7bcfb91f",
"metadataForms.knowledge_source.fields.source.content.helpText": "a58391e05d69ffe7",
"metadataForms.knowledge_source.fields.source.content.label": "fb33868fefbf74b3",
"metadataForms.knowledge_source.fields.source.documentBy.helpText": "e389b429286eb1a8",
"metadataForms.knowledge_source.fields.source.documentBy.label": "b28af31bc5593158",
"metadataForms.knowledge_source.fields.source.helpText": "0b648dbc7af2f85c",
"metadataForms.knowledge_source.fields.source.kind.helpText": "98e903260393800d",
"metadataForms.knowledge_source.fields.source.kind.label": "3acd2ee4b0e7f2cf",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3553,6 +3553,10 @@ export const deMetadataForms: NonNullable<TranslationData['metadataForms']> = {
label: "Filter fields",
helpText: "Fields kept beside each passage, so a search can filter on them (for example a status or an owner). Each one must be a field you may query."
},
"source.documentBy": {
label: "Document unit",
helpText: "Optional. The field that links each record to the parent record it is a part of (a clause to its policy): a lookup or master-detail field, single-valued, also listed in Filter fields. A record-level search then answers one hit per parent instead of one per record; a record with no parent is its own hit. The index is unchanged and nothing is rebuilt."
},
"source.where": {
label: "Records to index",
helpText: "An ObjectQL filter on the object, for example {\"status\": {\"$ne\": \"done\"}}. Only the records it matches are indexed. Blank: every record."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ export const deGeneratedSourceHashes: Readonly<Record<string, string>> = {
"metadataForms.knowledge_source.fields.refresh.onRecordChange.label": "53a3285b7bcfb91f",
"metadataForms.knowledge_source.fields.source.content.helpText": "a58391e05d69ffe7",
"metadataForms.knowledge_source.fields.source.content.label": "fb33868fefbf74b3",
"metadataForms.knowledge_source.fields.source.documentBy.helpText": "e389b429286eb1a8",
"metadataForms.knowledge_source.fields.source.documentBy.label": "b28af31bc5593158",
"metadataForms.knowledge_source.fields.source.helpText": "0b648dbc7af2f85c",
"metadataForms.knowledge_source.fields.source.kind.helpText": "98e903260393800d",
"metadataForms.knowledge_source.fields.source.kind.label": "3acd2ee4b0e7f2cf",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3553,6 +3553,10 @@ export const enMetadataForms: NonNullable<TranslationData['metadataForms']> = {
label: "Filter fields",
helpText: "Fields kept beside each passage, so a search can filter on them (for example a status or an owner). Each one must be a field you may query."
},
"source.documentBy": {
label: "Document unit",
helpText: "Optional. The field that links each record to the parent record it is a part of (a clause to its policy): a lookup or master-detail field, single-valued, also listed in Filter fields. A record-level search then answers one hit per parent instead of one per record; a record with no parent is its own hit. Setting it rebuilds nothing; adding the field to Filter fields does."
},
"source.where": {
label: "Records to index",
helpText: "An ObjectQL filter on the object, for example {\"status\": {\"$ne\": \"done\"}}. Only the records it matches are indexed. Blank: every record."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3553,6 +3553,10 @@ export const esESMetadataForms: NonNullable<TranslationData['metadataForms']> =
label: "Campos de filtro",
helpText: "Campos que se guardan junto a cada pasaje, para que una búsqueda pueda filtrar por ellos (por ejemplo, un estado o un propietario). Cada uno debe ser un campo que usted pueda consultar."
},
"source.documentBy": {
label: "Unidad de documento",
helpText: "Opcional. El campo que vincula cada registro con el registro padre del que forma parte (una cláusula con su política): un campo de búsqueda o maestro-detalle, de un solo valor, que también figure en Campos de filtro. Una búsqueda por registros devuelve entonces un resultado por padre en lugar de uno por registro; un registro sin padre es su propio resultado. Definirlo no reconstruye nada; añadir el campo a Campos de filtro sí lo hace."
},
"source.where": {
label: "Registros que indexar",
helpText: "Un filtro ObjectQL sobre el objeto, por ejemplo {\"status\": {\"$ne\": \"done\"}}. Solo se indexan los registros que coinciden. En blanco: todos los registros."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3553,6 +3553,10 @@ export const frMetadataForms: NonNullable<TranslationData['metadataForms']> = {
label: "Filter fields",
helpText: "Fields kept beside each passage, so a search can filter on them (for example a status or an owner). Each one must be a field you may query."
},
"source.documentBy": {
label: "Document unit",
helpText: "Optional. The field that links each record to the parent record it is a part of (a clause to its policy): a lookup or master-detail field, single-valued, also listed in Filter fields. A record-level search then answers one hit per parent instead of one per record; a record with no parent is its own hit. The index is unchanged and nothing is rebuilt."
},
"source.where": {
label: "Records to index",
helpText: "An ObjectQL filter on the object, for example {\"status\": {\"$ne\": \"done\"}}. Only the records it matches are indexed. Blank: every record."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ export const frGeneratedSourceHashes: Readonly<Record<string, string>> = {
"metadataForms.knowledge_source.fields.refresh.onRecordChange.label": "53a3285b7bcfb91f",
"metadataForms.knowledge_source.fields.source.content.helpText": "a58391e05d69ffe7",
"metadataForms.knowledge_source.fields.source.content.label": "fb33868fefbf74b3",
"metadataForms.knowledge_source.fields.source.documentBy.helpText": "e389b429286eb1a8",
"metadataForms.knowledge_source.fields.source.documentBy.label": "b28af31bc5593158",
"metadataForms.knowledge_source.fields.source.helpText": "0b648dbc7af2f85c",
"metadataForms.knowledge_source.fields.source.kind.helpText": "98e903260393800d",
"metadataForms.knowledge_source.fields.source.kind.label": "3acd2ee4b0e7f2cf",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3553,6 +3553,10 @@ export const jaJPMetadataForms: NonNullable<TranslationData['metadataForms']> =
label: "フィルターフィールド",
helpText: "各パッセージの横に保持されるフィールドで、検索でこれらによる絞り込みができます(例:ステータスや所有者)。それぞれ、あなたがクエリできるフィールドである必要があります。"
},
"source.documentBy": {
label: "ドキュメント単位",
helpText: "任意。各レコードを、それが属する親レコードに結び付けるフィールド(例:条項が属する規程)。単一値の参照または主従フィールドで、フィルターフィールドにも含める必要があります。レコード単位の検索では、レコードごとではなく親レコードごとに 1 件のヒットを返します。親のないレコードはそれ自体で 1 件のヒットになります。この設定だけでは再構築されませんが、フィールドをフィルターフィールドに新たに追加すると再構築されます。"
},
"source.where": {
label: "インデックス化するレコード",
helpText: "オブジェクトに対する ObjectQL フィルター。例:{\"status\": {\"$ne\": \"done\"}}。一致するレコードだけがインデックス化されます。空欄:すべてのレコード。"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3553,6 +3553,10 @@ export const koMetadataForms: NonNullable<TranslationData['metadataForms']> = {
label: "Filter fields",
helpText: "Fields kept beside each passage, so a search can filter on them (for example a status or an owner). Each one must be a field you may query."
},
"source.documentBy": {
label: "Document unit",
helpText: "Optional. The field that links each record to the parent record it is a part of (a clause to its policy): a lookup or master-detail field, single-valued, also listed in Filter fields. A record-level search then answers one hit per parent instead of one per record; a record with no parent is its own hit. The index is unchanged and nothing is rebuilt."
},
"source.where": {
label: "Records to index",
helpText: "An ObjectQL filter on the object, for example {\"status\": {\"$ne\": \"done\"}}. Only the records it matches are indexed. Blank: every record."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export const koGeneratedSourceHashes: Readonly<Record<string, string>> = {
"metadataForms.knowledge_source.fields.refresh.onRecordChange.label": "53a3285b7bcfb91f",
"metadataForms.knowledge_source.fields.source.content.helpText": "a58391e05d69ffe7",
"metadataForms.knowledge_source.fields.source.content.label": "fb33868fefbf74b3",
"metadataForms.knowledge_source.fields.source.documentBy.helpText": "e389b429286eb1a8",
"metadataForms.knowledge_source.fields.source.documentBy.label": "b28af31bc5593158",
"metadataForms.knowledge_source.fields.source.helpText": "0b648dbc7af2f85c",
"metadataForms.knowledge_source.fields.source.kind.helpText": "98e903260393800d",
"metadataForms.knowledge_source.fields.source.kind.label": "3acd2ee4b0e7f2cf",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1355,7 +1355,9 @@ describe('#19403 round 10 — the verdicts, on the live bundles', () => {
// 866 since #37309: the `knowledge_source` form (ADR-0161 K4 clause 2)
// — twenty of its section and row labels, authored in all three
// locales.
expect(translated.length, `${locale} positive control`).toBe(866);
// 867: the `knowledge_source` form's `documentBy` row (the document
// unit) — one row label, authored in all three locales.
expect(translated.length, `${locale} positive control`).toBe(867);
}
// ⭐ DARK — the blindness, executable. On a synthetic two-locale catalog the
// all-three predicate returns 0 while the per-locale one returns 1, so the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3553,6 +3553,10 @@ export const ptBRMetadataForms: NonNullable<TranslationData['metadataForms']> =
label: "Filter fields",
helpText: "Fields kept beside each passage, so a search can filter on them (for example a status or an owner). Each one must be a field you may query."
},
"source.documentBy": {
label: "Document unit",
helpText: "Optional. The field that links each record to the parent record it is a part of (a clause to its policy): a lookup or master-detail field, single-valued, also listed in Filter fields. A record-level search then answers one hit per parent instead of one per record; a record with no parent is its own hit. The index is unchanged and nothing is rebuilt."
},
"source.where": {
label: "Records to index",
helpText: "An ObjectQL filter on the object, for example {\"status\": {\"$ne\": \"done\"}}. Only the records it matches are indexed. Blank: every record."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ export const ptBRGeneratedSourceHashes: Readonly<Record<string, string>> = {
"metadataForms.knowledge_source.fields.refresh.onRecordChange.label": "53a3285b7bcfb91f",
"metadataForms.knowledge_source.fields.source.content.helpText": "a58391e05d69ffe7",
"metadataForms.knowledge_source.fields.source.content.label": "fb33868fefbf74b3",
"metadataForms.knowledge_source.fields.source.documentBy.helpText": "e389b429286eb1a8",
"metadataForms.knowledge_source.fields.source.documentBy.label": "b28af31bc5593158",
"metadataForms.knowledge_source.fields.source.helpText": "0b648dbc7af2f85c",
"metadataForms.knowledge_source.fields.source.kind.helpText": "98e903260393800d",
"metadataForms.knowledge_source.fields.source.kind.label": "3acd2ee4b0e7f2cf",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3553,6 +3553,10 @@ export const ruMetadataForms: NonNullable<TranslationData['metadataForms']> = {
label: "Filter fields",
helpText: "Fields kept beside each passage, so a search can filter on them (for example a status or an owner). Each one must be a field you may query."
},
"source.documentBy": {
label: "Document unit",
helpText: "Optional. The field that links each record to the parent record it is a part of (a clause to its policy): a lookup or master-detail field, single-valued, also listed in Filter fields. A record-level search then answers one hit per parent instead of one per record; a record with no parent is its own hit. The index is unchanged and nothing is rebuilt."
},
"source.where": {
label: "Records to index",
helpText: "An ObjectQL filter on the object, for example {\"status\": {\"$ne\": \"done\"}}. Only the records it matches are indexed. Blank: every record."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export const ruGeneratedSourceHashes: Readonly<Record<string, string>> = {
"metadataForms.knowledge_source.fields.refresh.onRecordChange.label": "53a3285b7bcfb91f",
"metadataForms.knowledge_source.fields.source.content.helpText": "a58391e05d69ffe7",
"metadataForms.knowledge_source.fields.source.content.label": "fb33868fefbf74b3",
"metadataForms.knowledge_source.fields.source.documentBy.helpText": "e389b429286eb1a8",
"metadataForms.knowledge_source.fields.source.documentBy.label": "b28af31bc5593158",
"metadataForms.knowledge_source.fields.source.helpText": "0b648dbc7af2f85c",
"metadataForms.knowledge_source.fields.source.kind.helpText": "98e903260393800d",
"metadataForms.knowledge_source.fields.source.kind.label": "3acd2ee4b0e7f2cf",
Expand Down
Loading
Loading