Skip to content

Commit 340bb34

Browse files
committed
docs(knowledge): one passage per unit recipe; name chunk_target the longest passage
Teach the markdown split's one-passage-per-unit shape in the knowledge guide (one heading per unit, a derived field on the same record that carries the index text, an optional top heading naming the document, minChars as the merge threshold of a unit that does not fit), with a pointer from the protocol's split section. Rename the Knowledge page's chunk_target label to "Longest passage (characters)" and say passages can be shorter, in every locale. Claude-Session: https://claude.ai/code/session_01FEkQ5mDidoPNcFwxVX65bA Co-Authored-By: Claude <noreply@anthropic.com>
1 parent f459c86 commit 340bb34

15 files changed

Lines changed: 88 additions & 23 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@objectstack/service-settings': patch
3+
---
4+
5+
fix(service-settings): the Knowledge page names `chunk_target` for what it is, the longest passage
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
The Knowledge settings page labelled `knowledge.chunk_target` **Target chunk size**, while its help text, and the splitter that reads it, treat it as a maximum: no passage is longer, and many are shorter (under the `markdown` split, a section that fits is one passage of whatever length it has). The label now reads **Longest passage (characters)**, and the help text adds that passages can be shorter, in every locale the page ships (en, zh-CN, zh-Hant, ja-JP, ko, de, es-ES, fr, pt-BR, ru, ar). Earlier notes that name **Target chunk size** (the splitter, the knowledge skill) mean this same setting under its old label. The key, its default (800), its bounds and what reads it are unchanged.
11+
12+
What to do: nothing. A script or seed that writes `knowledge.chunk_target` keeps working.

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

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,52 @@ source: {
258258
- `markdown` cuts one section per heading; each passage begins with its heading path, which is embedded with it. A section that fits in one passage (its text together with the heading path it is given, within the length below) is one passage; only a section that does not fit is cut as `recursive` cuts, and `minChars` (default 200) merges the short pieces of that cut.
259259
- `whole` keeps each document as one passage.
260260

261-
A passage is at most `split.maxChars` characters — else the **Knowledge → Target chunk size** setting, else 800 — and, when the adapter reports its embedder's input limit, within 80% of that limit by the shared token estimate below. A `whole` document over that budget is **removed from the index and reported** (`failed` and `failures` on the reindex result, an `error` log on the event sync), never truncated; because the estimate runs high, a `whole` document can use about 60% of the model's limit. The full rules are in [the protocol's split section](/docs/protocol/knowledge#35-the-split).
261+
A passage is at most `split.maxChars` characters — else the **Knowledge → Longest passage** setting, else 800 — and, when the adapter reports its embedder's input limit, within 80% of that limit by the shared token estimate below. A `whole` document over that budget is **removed from the index and reported** (`failed` and `failures` on the reindex result, an `error` log on the event sync), never truncated; because the estimate runs high, a `whole` document can use about 60% of the model's limit. The full rules are in [the protocol's split section](/docs/protocol/knowledge#35-the-split).
262+
263+
### One passage per unit
264+
265+
Policies, regulations, contracts and manuals are made of units: an article, a numbered section, a question with its answer. A hit is most useful when it is one whole unit: not half of one, and not three of them. The `markdown` strategy gives exactly that once each unit is its own heading:
266+
267+
- **One heading per unit.** Write each unit as a Markdown heading at the start of its line (`## Article 12 Air travel`), with the unit's text under it. Bold text such as `**Article 12**` is not a heading, so every article under one real heading would share that one section. Keep a unit's sub-items as list items or plain lines, not headings: a sub-heading starts a section of its own, and with it a passage of its own.
268+
- **A unit that fits is one passage.** When a unit's text together with its heading path fits within the passage length above, it is one passage, whatever `minChars` is. A table and the note right after it, written inside the same unit, stay in that passage.
269+
- **A passage never holds two units.** Each section is split on its own, so short neighbouring units are never merged, and every passage begins with its unit's heading path (shortened when it is long, see below; the hit carries all of it as `headingPath`).
270+
- **A unit that does not fit** is cut as `recursive` cuts, its pieces merged up to `minChars`, and every piece still begins with the unit's heading path. A table too long for one passage is cut between rows, each piece repeating the header row; a note after the table can then land in a different piece than the rows it explains.
271+
- **`minChars` only merges the pieces of a unit that does not fit.** It is the merge threshold for that cut: pieces shorter than it are joined up to it. It is not a switch for one passage per unit, which needs no setting, and `minChars: 0` turns nothing off: a unit that fits is still one passage, and only the pieces of a unit that does not fit are left unmerged.
272+
273+
Most apps do not store their text in that shape: articles are bold paragraphs, or the text lives in rich text. Keep it as it is, and give the same record a second text field that holds the index text, the same content rewritten with one heading per unit, filled by the app each time the record is saved (in a record hook, for example). List only that field in `content`:
274+
275+
```ts
276+
source: {
277+
kind: 'object',
278+
object: 'policy',
279+
content: ['index_text'], // the derived field alone
280+
metadataFields: ['department', 'status'],
281+
split: { strategy: 'markdown', maxChars: 800 },
282+
}
283+
```
284+
285+
Keeping the index text on the same record, rather than in a second object with one row per unit, means a hit names the record people open, the search re-checks that record as the asking user, and `where` and `metadataFields` read the record's own fields. There is no second object to secure, keep in step with the first, or delete with it. The field is indexed like any other content field: its text is sent to the embedder, and a credential or internal field is never indexed.
286+
287+
**An optional top heading names the document.** The text the embedder sees is the passage: neither the record's title nor the department that owns it is in it unless the text says so. Starting the index text with one top-level heading that names them, with every unit one level below it, makes each passage's heading path begin with that heading:
288+
289+
```md
290+
# Group travel policy · Finance department
291+
292+
## Article 1 Scope
293+
Applies to every employee travelling on company business.
294+
295+
## Article 7 Hotel limits
296+
| Region | Limit per night |
297+
|---|---|
298+
| Region 1 | 600 |
299+
| Region 2 | 450 |
300+
301+
Region 1 means Beijing, Shanghai, Guangzhou and Shenzhen.
302+
```
303+
304+
Article 7 is then one passage that begins `Group travel policy · Finance department > Article 7 Hotel limits`, the table and its note together, and a question that names the policy or the department matches it. Keep the top heading short: a heading path is written into the passage whole only while it leaves at least half of the passage length for text, and otherwise shortens to the unit's own heading (the hit's `headingPath` still lists all of it). A title that is already in the top heading needs no second `content` entry: a field listed before the index text would become a passage of its own, ahead of the first heading.
305+
306+
Moving an existing source to this shape changes its `content` and `split`, so its index is rebuilt once ([below](#when-the-model-or-the-split-changes-rebuild)), and the rebuild sends the whole source to the embedding provider again.
262307

263308
## Embedder input limits
264309

‎content/docs/protocol/knowledge.mdx‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ closing quote or bracket: 「他说:“好。”然后」 stays one sentence.
583583
clause wherever it stands, `;` only before whitespace.
584584

585585
**How long a passage may be.** `maxChars` is the source's `split.maxChars`,
586-
else the settings page's **Knowledge → Target chunk size**
586+
else the settings page's **Knowledge → Longest passage**
587587
(`knowledge.chunk_target`), else 800. And when the adapter reports its
588588
embedder's `maxInputTokens`, every passage's token estimate (the shared
589589
`estimateTokens` from `@objectstack/spec/shared`) also stays within **80%** of
@@ -594,6 +594,14 @@ the pieces of a section that does not fit, so `minChars: 0` still leaves a
594594
fitting section whole. The splitter never overlaps
595595
passages.
596596

597+
**One passage per unit.** Under `markdown`, text written with one heading
598+
per unit (an article, a numbered section, a question with its answer) gives
599+
one passage per unit that fits, and no passage ever holds two units; it
600+
needs no `minChars` setting. Text stored in another shape is indexed through a
601+
derived field on the same record that carries that rewrite, optionally under
602+
one top heading that names the document; the recipe is in
603+
[the knowledge guide](/docs/ai/knowledge-rag#one-passage-per-unit).
604+
597605
**`whole` over the limit.** A `whole` document whose estimate is over the 80%
598606
budget is **removed from the index and reported, never truncated**:
599607
`reindexSource` counts it in `failed` and names it in `failures`

‎packages/services/service-settings/src/manifests/knowledge.manifest.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ const manifest = {
7070
// ── Indexing defaults ─────────────────────────────────────────
7171
{ type: 'group', id: 'indexing', label: 'Indexing defaults', required: false,
7272
description: 'A value set on a knowledge source itself wins over these defaults.' },
73-
{ type: 'number', key: 'chunk_target', label: 'Target chunk size (chars)',
73+
{ type: 'number', key: 'chunk_target', label: 'Longest passage (characters)',
7474
required: false, default: 800, min: 64, max: 8192,
75-
description: "Longest passage, in characters, when the knowledge service splits a document. A size set on a knowledge source itself wins; the embedding model's input limit can lower it." },
75+
description: "The longest a passage can be, in characters, when the knowledge service splits a document; passages can be shorter. A size set on a knowledge source itself wins; the embedding model's input limit can lower it." },
7676
],
7777
};
7878

‎packages/services/service-settings/src/translations/ar.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,8 +686,8 @@ export const ar: PlatformTranslationData = {
686686
},
687687
keys: {
688688
chunk_target: {
689-
label: 'الحجم المستهدف للمقطع (أحرف)',
690-
help: 'أقصى طول للمقطع بالأحرف عند تقسيم خدمة المعرفة لمستند. تكون الأولوية للحجم المحدد في مصدر المعرفة نفسه، وقد يخفضه حد الإدخال الخاص بنموذج التضمين.',
689+
label: 'أقصى طول للمقطع (أحرف)',
690+
help: 'أقصى طول للمقطع بالأحرف عند تقسيم خدمة المعرفة لمستند، وقد تكون المقاطع أقصر. تكون الأولوية للحجم المحدد في مصدر المعرفة نفسه، وقد يخفضه حد الإدخال الخاص بنموذج التضمين.',
691691
},
692692
},
693693
},

‎packages/services/service-settings/src/translations/de.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,8 +722,8 @@ export const de: PlatformTranslationData = {
722722
},
723723
keys: {
724724
chunk_target: {
725-
label: 'Ziel-Chunkgröße (Zeichen)',
726-
help: 'Längste Passage in Zeichen, wenn der Wissensdienst ein Dokument aufteilt. Eine an der Wissensquelle selbst gesetzte Größe hat Vorrang; das Eingabelimit des Embedding-Modells kann den Wert senken.',
725+
label: 'Längste Passage (Zeichen)',
726+
help: 'Längste Passage in Zeichen, wenn der Wissensdienst ein Dokument aufteilt; Passagen können kürzer sein. Eine an der Wissensquelle selbst gesetzte Größe hat Vorrang; das Eingabelimit des Embedding-Modells kann den Wert senken.',
727727
},
728728
},
729729
},

‎packages/services/service-settings/src/translations/en.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,8 @@ export const en: PlatformTranslationData = {
422422
description: 'A value set on a knowledge source itself wins over these defaults.' },
423423
},
424424
keys: {
425-
chunk_target: { label: 'Target chunk size (chars)',
426-
help: 'Longest passage, in characters, when the knowledge service splits a document. A size set on a knowledge source itself wins; the embedding model\'s input limit can lower it.' },
425+
chunk_target: { label: 'Longest passage (characters)',
426+
help: 'The longest a passage can be, in characters, when the knowledge service splits a document; passages can be shorter. A size set on a knowledge source itself wins; the embedding model\'s input limit can lower it.' },
427427
},
428428
},
429429
},

‎packages/services/service-settings/src/translations/es-ES.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,8 @@ export const esES: PlatformTranslationData = {
588588
description: 'Un valor definido en la propia fuente de conocimiento prevalece sobre estos valores predeterminados.' },
589589
},
590590
keys: {
591-
chunk_target: { label: 'Tamaño objetivo de fragmento (caracteres)',
592-
help: 'Longitud máxima de un pasaje, en caracteres, cuando el servicio de conocimiento divide un documento. Un tamaño fijado en la propia fuente tiene prioridad; el límite de entrada del modelo de embeddings puede reducirlo.' },
591+
chunk_target: { label: 'Pasaje más largo (caracteres)',
592+
help: 'Longitud máxima de un pasaje, en caracteres, cuando el servicio de conocimiento divide un documento; los pasajes pueden ser más cortos. Un tamaño fijado en la propia fuente tiene prioridad; el límite de entrada del modelo de embeddings puede reducirlo.' },
593593
},
594594
},
595595

‎packages/services/service-settings/src/translations/fr.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,8 +731,8 @@ export const fr: PlatformTranslationData = {
731731
},
732732
keys: {
733733
chunk_target: {
734-
label: 'Taille cible des morceaux (caractères)',
735-
help: 'Longueur maximale d’un passage, en caractères, lorsque le service de connaissances découpe un document. Une taille fixée sur la source elle-même l’emporte ; la limite d’entrée du modèle d’embedding peut l’abaisser.',
734+
label: 'Passage le plus long (caractères)',
735+
help: 'Longueur maximale d’un passage, en caractères, lorsque le service de connaissances découpe un document ; un passage peut être plus court. Une taille fixée sur la source elle-même l’emporte ; la limite d’entrée du modèle d’embedding peut l’abaisser.',
736736
},
737737
},
738738
},

‎packages/services/service-settings/src/translations/ja-JP.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,8 +587,8 @@ export const jaJP: PlatformTranslationData = {
587587
description: 'ナレッジソース自体に設定した値が、これらの既定値より優先されます。' },
588588
},
589589
keys: {
590-
chunk_target: { label: '目標チャンクサイズ(文字数)',
591-
help: 'ナレッジサービスがドキュメントを分割するときの、パッセージ 1 件あたりの最大文字数。ナレッジソース自身に設定したサイズが優先され、埋め込みモデルの入力上限によって小さくなることがあります。' },
590+
chunk_target: { label: 'パッセージの最大長(文字数)',
591+
help: 'ナレッジサービスがドキュメントを分割するときの、パッセージ 1 件あたりの最大文字数。これより短いパッセージもあります。ナレッジソース自身に設定したサイズが優先され、埋め込みモデルの入力上限によって小さくなることがあります。' },
592592
},
593593
},
594594

0 commit comments

Comments
 (0)