parseKnowledgeDocument
KIT · function · Runtime value
Paired, nestable anchors are one text adapter. Other sources supply the same document contract directly.
Import
ts
import { parseKnowledgeDocument } from '@jangts/agent-core/kits/knowledge';js
import { parseKnowledgeDocument } from '@jangts/agent-core/kits/knowledge';Other public entry points:@jangts/agent-core/types, @jangts/agent-core/kits/knowledge, @jangts/agent-core/kits.
Definition
Call
ts
parseKnowledgeDocument(input: { id: string; revision: string; text: string; locale?: string; }): KnowledgeDocumentPaired, nestable anchors are one text adapter. Other sources supply the same document contract directly.
| Parameter | Type | Passing | Description |
|---|---|---|---|
input | { id: string; revision: string; text: string; locale?: string; } | Required | — |
Fields of input
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Required | See the type definition and usage context. |
revision | string | Required | See the type definition and usage context. |
text | string | Required | See the type definition and usage context. |
locale | string | undefined | Optional | See the type definition and usage context. |
Returns: KnowledgeDocument.
Return value structure
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Required | Read-only. Stable document id; duplicate ids are rejected by the catalog. |
revision | string | Required | Read-only. Revision label recorded in every snapshot so a citation names the exact content. |
locale | string | undefined | Optional | Read-only. Locale of the content, when the App maintains translations. |
parts | readonly KnowledgePart[] | Required | Read-only. Ordered content. |
Examples
- Knowledge: documents, sections, and evidence snapshots: One document contract supports plain objects and anchored text; a selection yields an evidence snapshot with an explicit version.
First read one plain-object document
Beginner · Node.js
ts
import { Knowledge } from '@jangts/agent-core/kits/knowledge';
const catalog = Knowledge.defineKnowledgeCatalog([
{ id: 'manual', revision: '1', parts: ['Agent Core 支持普通 Workflow 节点。'] },
]);
const snapshot = catalog.read({ documentId: 'manual', selection: { mode: 'document' } });
console.log(snapshot.content, snapshot.revision);js
import { Knowledge } from '@jangts/agent-core/kits/knowledge';
const catalog = Knowledge.defineKnowledgeCatalog([
{ id: 'manual', revision: '1', parts: ['Agent Core 支持普通 Workflow 节点。'] },
]);
const snapshot = catalog.read({ documentId: 'manual', selection: { mode: 'document' } });
console.log(snapshot.content, snapshot.revision);Add sections and a budget to the same read
Configuration · Node.js
ts
import { Knowledge } from '@jangts/agent-core/kits/knowledge';
const catalog = Knowledge.defineKnowledgeCatalog([
{ id: 'manual', revision: '2', parts: [
{ id: 'start', parts: ['先运行一个节点。', { id: 'advanced', parts: ['再增加模型和工具。'] }] },
] },
], { maxChars: 2000 });
console.log(catalog.sectionIds('manual'));
const snapshot = catalog.read({ documentId: 'manual', selection: { mode: 'subtree', sectionIds: ['start'] } });
console.log(snapshot.content, snapshot.id);js
import { Knowledge } from '@jangts/agent-core/kits/knowledge';
const catalog = Knowledge.defineKnowledgeCatalog([
{ id: 'manual', revision: '2', parts: [
{ id: 'start', parts: ['先运行一个节点。', { id: 'advanced', parts: ['再增加模型和工具。'] }] },
] },
], { maxChars: 2000 });
console.log(catalog.sectionIds('manual'));
const snapshot = catalog.read({ documentId: 'manual', selection: { mode: 'subtree', sectionIds: ['start'] } });
console.log(snapshot.content, snapshot.id);Switch to the text adapter; later catalog and read calls stay identical
Extension · Node.js
Paired anchors must match; markers are just one input for the text adapter, and Core does not require documents to be stored as Markdown.
ts
import { Knowledge } from '@jangts/agent-core/kits/knowledge';
const document = Knowledge.parseKnowledgeDocument({
id: 'manual', revision: '3',
text: ['<!-- agent-section:start -->', '先运行一个节点。', '<!-- /agent-section:start -->'].join('\n'),
});
const catalog = Knowledge.defineKnowledgeCatalog([document], { maxChars: 2000 });
const read = { documentId: 'manual', selection: { mode: 'self' as const, sectionIds: ['start'] } };
catalog.assertSelection(read);
console.log(catalog.read(read).content);js
import { Knowledge } from '@jangts/agent-core/kits/knowledge';
const document = Knowledge.parseKnowledgeDocument({
id: 'manual', revision: '3',
text: ['<!-- agent-section:start -->', '先运行一个节点。', '<!-- /agent-section:start -->'].join('\n'),
});
const catalog = Knowledge.defineKnowledgeCatalog([document], { maxChars: 2000 });
const read = { documentId: 'manual', selection: { mode: 'self', sectionIds: ['start'] } };
catalog.assertSelection(read);
console.log(catalog.read(read).content);