Docs
Contents

Knowledge Base Wiki and GraphRAG (Index Governance)

Overview and use cases

Starting with 2.7.0, knowledge bases provide three types of enhanced index capabilities (Knowledge Index) on top of basic RAG: GraphRAG (entity knowledge graph), RAPTOR (summary tree), and LLM Wiki (compiling knowledge base content into maintainable canonical Wiki pages). This page covers their management surface:

When to use: when knowledge base content needs to be consolidated into a structured, governable Wiki (for consumption by humans or agents), or when GraphRAG / RAPTOR is needed to enhance retrieval quality. For basic ingestion and retrieval, see Knowledge Base, Documents and Ingestion, and Retrieval and Sources.

Prerequisites

Usage workflow

  1. Capability configuration: listIndexCapabilities checks available / configured / enabled / state respectively (deployment unavailable and not enabled by the user are different signals); updateIndexCapability saves the complete configuration of graphrag / raptor / wiki.

  2. Build: call createIndexOperation (build / repair) with a stable idempotencyKey, poll getIndexOperation until a terminal state; use cancelIndexOperation to request cancellation when needed.

  3. Wiki pages: createWikiPage creates a page ([[slug]] links are extracted automatically; unresolved targets are kept as red links); read getWikiPage / listWikiPages; optimistic concurrent update updateWikiPage (carrying the current contentRevision); version history listWikiPageRevisions / getWikiPageRevision, restore restoreWikiPage (a historical version generates a new revision without altering history).

  4. Proposals and conflicts: listWikiProposals / acceptWikiProposal handle compiler proposals; listWikiConflicts / getWikiConflictProposal / resolveWikiConflict handle conflict pages.

  5. Query: createWikiQuery (explicit library list, 1–20 libraries) or createWikiProjectSearch (all libraries visible to the caller); getWikiOverview gets the project-level Wiki status card.

  6. Graph browsing: getWikiGraph to view the Wiki page link graph; GraphRAG uses getGraph (text / type / community filtering or seed + hops bounded exploration), getGraphEntityNeighbors, and listGraphCommunityReports.

  7. Maintenance: getWikiRecommendedLimits gets compile limit recommendations; createWikiPageMemoryExport exports pages as Memory facts; clearIndexCapability clears only derived indexes; resetWiki deletes the entire canonical Wiki.

Key parameters and returns

Errors and boundaries

SDK Category Differences

Examples by language

Each card has switchable language tabs (synchronized across the page). The Web client SDK has none of the capability surfaces on this page, so no card offers a Web tab.

Capability Configuration and Build (Including Cancellation)

First query available / configured / enabled / state, then save the graphrag (entityTypes, lexiconEnabled, graphragEmbedBatchSize, language), raptor (scope: "knowledgeBase" | "document" and GMM+BIC clustering parameters maxLevels, clusterDimension, bicThreshold, summaryTokenBudget), and wiki (await_graphrag, pageMaxConcurrent, sources) configurations respectively, and trigger the build / repair / cancel / clear operations; poll the operation until it reaches a terminal state.

import { Capability, Kind, Scope } from 'agentbase-node-sdk';

const caps = await kb.listIndexCapabilities({ knowledgeBaseId: base.$id });
// Check available / configured / enabled / state per item; deployment unavailable ≠ user has not enabled it
// 1. Configure GraphRAG (entity type whitelist, enable lexicon alignment lexiconEnabled, vector batch size graphragEmbedBatchSize)
await kb.updateIndexCapability({
    knowledgeBaseId: 'kb_enterprise_support',
    capability: Capability.Graphrag,
    config: {
        enabled: true,
        language: 'zh',
        entityTypes: ['Product', 'Component', 'ErrorCode', 'Parameter', 'SOP'],
        lexiconEnabled: true,
        graphragEmbedBatchSize: 32,
    },
});
// 2. Configure RAPTOR (supports knowledgeBase or document granularity, plus GMM+BIC hierarchical clustering parameters)
await kb.updateIndexCapability({
    knowledgeBaseId: 'kb_enterprise_support',
    capability: Capability.Raptor,
    config: {
        enabled: true,
        language: 'zh',
        scope: 'knowledgeBase',
        maxLevels: 3,
        clusterDimension: 16,
        bicThreshold: 0.15,
        summaryTokenBudget: 512,
    },
});
// 3. Configure LLM Wiki (enable await_graphrag and compilation concurrency pageMaxConcurrent)
await kb.updateIndexCapability({
    knowledgeBaseId: base.$id,
    capability: Capability.Wiki,
    config: {
        enabled: true,
        language: 'zh',
        await_graphrag: true,
        pageMaxConcurrent: 4,
        sources: ['rag', 'graphrag', 'memory'],
    },   // Full replacement; language: auto/zh/en/ja
});
// 4. Trigger asynchronous build or repair, and poll progress or cancel (cancel)
const op = await kb.createIndexOperation({
    knowledgeBaseId: base.$id,
    capability: Capability.Wiki,
    idempotencyKey: 'wiki-build-20260918-01',   // Stable idempotency key, reused on retries
    kind: Kind.Build,                           // Kind.Build or Kind.Repair
    scope: Scope.Knowledgebase,
});
// Poll for final state succeeded / failed / cancelled / cleared
const st = await kb.getIndexOperation({ knowledgeBaseId: base.$id, operationId: op.$id });
await kb.cancelIndexOperation({ knowledgeBaseId: base.$id, operationId: '<operationId>' });   // Request cancellation

Wiki Pages and Version Restore

Page write operations carry the current contentRevision for optimistic concurrency; every successful write produces an immutable revision, and restoring means writing a historical revision as a new revision (history is never modified).

import { PageType, Status } from 'agentbase-node-sdk';

const page = await kb.createWikiPage({
    knowledgeBaseId: base.$id,
    slug: 'refund-policy',
    title: '退款政策',
    pageType: PageType.Topic,
    contentMd: '# 退款政策\n\n详见 [[order-lifecycle]]。',   // [[slug]] automatic link extraction; unresolved targets are kept as red links
    status: Status.Published,
});
const cur = await kb.getWikiPage({ knowledgeBaseId: base.$id, slug: 'refund-policy' });
await kb.updateWikiPage({
    knowledgeBaseId: base.$id,
    slug: 'refund-policy',
    contentRevision: cur.contentRevision,   // Must match the current version
    page: { contentMd: '# 退款政策(v2)\n\n……' },          // Changed field set; if links/aliases are omitted they are preserved
    reason: '补充跨境订单条款',
});
const revs = await kb.listWikiPageRevisions({ knowledgeBaseId: base.$id, slug: 'refund-policy' });
const latest = await kb.getWikiPage({ knowledgeBaseId: base.$id, slug: 'refund-policy' });   // Re-read to get the latest revision after updating
await kb.restoreWikiPage({
    knowledgeBaseId: base.$id,
    slug: 'refund-policy',
    revisionId: '<revisionId>',
    contentRevision: latest.contentRevision,   // Restore also requires the current contentRevision fence
});
// Optional destructive operation: re-read the page before deleting to obtain the latest numeric revision.
const beforeDelete = await kb.getWikiPage({ knowledgeBaseId: base.$id, slug: 'refund-policy' });
await kb.deleteWikiPage({
    knowledgeBaseId: base.$id, slug: 'refund-policy',
    contentRevision: beforeDelete.contentRevision, confirmation: 'delete:refund-policy',
});

Proposals and Conflict Resolution

Compiler proposals are immutable revisions and do not replace the canonical content until accepted or resolved; the conflicts page lists unresolved items, which can be resolved one by one or submitted as a manual merge document.

// Proposal: list → accept (contentRevision prevents overwriting manually applied updates)
const proposals = await kb.listWikiProposals({ knowledgeBaseId: base.$id });
const cur = await kb.getWikiPage({ knowledgeBaseId: base.$id, slug: '<slug>' });   // CAS uses the current revision
await kb.acceptWikiProposal({
    knowledgeBaseId: base.$id, proposalId: '<proposalId>', contentRevision: cur.contentRevision,
});
// Conflict: list → review the compiler's proposals → resolve individual items or submit a manual merge
const conflicts = await kb.listWikiConflicts({ knowledgeBaseId: base.$id });
const proposal = await kb.getWikiConflictProposal({ knowledgeBaseId: base.$id, slug: '<slug>' });
await kb.resolveWikiConflict({
    knowledgeBaseId: base.$id,
    slug: '<slug>',
    contentRevision: cur.contentRevision,
    resolvedConflictId: '<conflictId>',              // Resolve a single conflicting item
    resolvedConflictOptionText: '<chosenOption>',
    // or manual merge: contentMd: '<merged markdown>'
    // When part of a resolution proposal: proposalId + proposalMd (remaining content), so unresolved parts are not silently dropped
});

createWikiQuery explicitly specifies 1–20 knowledge bases; createWikiProjectSearch covers all knowledge bases visible to the caller in the project; getWikiOverview returns permission-filtered project-level Wiki status cards (deployment availability, enabled status, index status, page count, and conflict count in separate columns).

import { Mode } from 'agentbase-node-sdk';

const overview = await kb.getWikiOverview();   // Project-level status card (no parameters)
const hits = await kb.createWikiQuery({
    knowledgeBaseIds: [base.$id],   // 1–20 explicit libraries
    query: '退款流程是什么?',
    mode: Mode.Auto,                // auto / wiki_direct / wiki_retrieved / rag_first
    topK: 5,
});
// Project-level search (all visible knowledge bases; capability failures are explicitly listed in degradedKnowledgeBases):
const all = await kb.createWikiProjectSearch({ query: '退款流程是什么?', mode: Mode.Auto });

getWikiGraph returns the canonical page link graph (redLink=true are red links); the three GraphRAG methods browse a bounded snapshot of the active generation.

const wikiGraph = await kb.getWikiGraph({ knowledgeBaseId: base.$id });   // canonical page + resolved/unresolved links
// GraphRAG: filter by text/type/community, or bounded exploration via seed + hops; pagination via hasMore + nextCursor, truncated=true means a subset
const graph = await kb.getGraph({ knowledgeBaseId: base.$id, seed: '<entityId>', hops: 2, limit: 50 });
const neighbors = await kb.getGraphEntityNeighbors({ knowledgeBaseId: base.$id, entityId: '<entityId>', hops: 1 });
const reports = await kb.listGraphCommunityReports({ knowledgeBaseId: base.$id, limit: 20 });

clearIndexCapability only clears derived indexes (keeping canonical pages / links / versions / aliases); resetWiki deletes the entire canonical Wiki — the two are not the same action; the confirmation value and idempotency key are both required.

// Compilation limit recommendations; enableLlmRefine=false returns purely deterministic suggestions
const limits = await kb.getWikiRecommendedLimits({ knowledgeBaseId: base.$id, enableLlmRefine: false });
// Export a single page as a Memory fact (the project must have Memory activated, otherwise 503 memory_service_unavailable)
const exported = await kb.createWikiPageMemoryExport({
    knowledgeBaseId: base.$id, slug: 'refund-policy', agentId: '<agentId>',   // agentId is optional
});
// Only clears wiki-derived projections (canonical is preserved); confirmation value is clear:<capability>
await kb.clearIndexCapability({
    knowledgeBaseId: base.$id, capability: Capability.Wiki,
    confirmation: 'clear:wiki', idempotencyKey: 'clear-wiki-01',
});
// Delete the entire canonical Wiki (most destructive); confirmation value is reset:wiki
await kb.resetWiki({
    knowledgeBaseId: base.$id, confirmation: 'reset:wiki', idempotencyKey: 'reset-wiki-01',
});

Example Guide