Skip to main content

Worked sequences

The twenty operations below are the full knowledge-base surface, but four round trips cover the document lifecycle most integrations actually run: upload a document, moderate it once the review queue picks it up, search the base to preview what an agent would retrieve, and diff two versions when the ground truth changed. Each sequence shows the body you send and the body the API returns. For the prose walkthrough of the whole lifecycle (create → load → attach → tune → maintain), read Build and Maintain an AI Knowledge Base. You need the knowledge:write scope (owner / admin / developer role) for uploads and moderation, and knowledge:read for search and diffs.

1. Upload a document

Binary files (PDF, DOCX, images — OCR-extracted) go up as multipart/form-data. Send the file bytes plus the name and type fields; the accepted document comes back in processing status because chunking and embedding run asynchronously. Poll GET /knowledge-bases/kb_abc123/documents until the status reaches ready.
202
A 422 on a multipart upload means a missing name/type field or raw JSON carrying binary bytes — binary formats are multipart-only (inline text under the 10 MB cap may go up as a JSON content body instead; see the operation below).

2. Approve or reject a pending document

A document submitted for moderation (for example, a gap-cluster draft) sits pending until a reviewer acts. Approving flips its publish lifecycle to approved and starts deferred vector indexing so its chunks become retrievable; rejecting flips it to rejected and its chunks are never indexed. Optional notes are stored on the document for the submitter. Approve:
200
Reject the same way — a document that was never indexed stays out of agent retrieval either way:
200
Both actions are audit-logged — approval promotes a document to RAG ground-truth, which is an admin-class decision.

3. Search the knowledge base

This is the same retrieval an attached agent’s search_knowledge tool runs, and the response shape exists so you can preview what an agent would ground on before a customer asks. Results are relevance-ranked chunks; when a per-base search config is active, recency, source weighting, and category filters apply before the list is truncated to limit (default 5).
200
An empty results array means no chunk cleared the raw similarity floor — check whether the document you expect is uploaded, approved, and indexed.

4. Diff two document versions

Every re-upload retains the prior copy as an immutable snapshot, so you can always ask what changed. GET /knowledge-bases/kb_abc123/documents/doc_9a1c3e5b7d/versions/diff takes from and to 1-based version numbers and returns added / removed / unchanged line counts plus unified-style hunk lines (+ added, - removed, context). truncated: true means the inputs were too large for a line-level diff. A 422 here means one of those versions isn’t in the retained lineage. Roll back with POST .../rollback and a body like { "version": 1 } once the hunks confirm the regression.
200

5. Worked sequences — advanced lifecycle

Beyond upload and read-back, most AI-agent deployments run the full editorial loop: register an external source connector with POST /api/v1/knowledge-bases/{id}/connectors, kick off its initial sync with POST .../sync, watch drift and staleness, moderate the AI assistant’s proposed documents, roll a published version back after reading the lineage, and delete the documents the team has retired. The samples below keep the same identifiers end-to-end; pause on scheduled syncs by patching a connector with enabled: false.

5.1 Create a connector and start its initial sync

Register a connector that pulls one knowledge base’s documents from an external source. The body names the provider (one of notion, confluence, google_drive, sharepoint, zendesk) plus an optional scope, sync_schedule (default daily), and auto_refresh_on_drift. The returned id stays the handle for every later call.
201
Start the first pull right away instead of waiting for the schedule. A sync that is accepted but has not yet been picked up by the drain worker reports "status": "queued" (some builds surface the same transition as "syncing"); once a worker claims the row, the same endpoint reports "status": "running" as below. The response is 202 because the sync runs asynchronously; poll GET /api/v1/knowledge-bases/{id}/connectors for the connector’s last-sync status as it moves through queued → syncing → running.
202

5.2 Read the connector drift report and staleness

Once a sync has pulled, the connector drain worker hashes the live source and compares it against the cached content your agents ground on. Read the drift scorecard to decide whether to re-sync or to switch auto_refresh_on_drift on. Until the worker has checked a connector at least once, detection_active is false — the 0-drifted totals are not yet a passing signal.
200
Staleness is the document-side companion: it buckets each document into fresh, stale, or critical against your org’s threshold (90 days by default; override per call with ?default_threshold_days= or per document via its metadata) so an operator’s review queue catches the files an agent still quotes as current.
200
Both endpoints are read-only and deliberately avoid audit-log writes, so polling them from a dashboard or a scheduled job stays cheap.

5.3 Approve or reject the assistant’s proposed document

This moderation path runs in addition to the plain upload flow when your knowledge base enables require_publish_approval, or when an AI assistant (for example, a gap-cluster draft) proposes a document — either way the file arrives with status: pending and never enters retrieval until a reviewer acts. Approving flips the document to approved and starts the deferred vector indexing; rejecting flips it to rejected and its chunks are never indexed. Optional notes are stored on the document so the submitter gets actionable feedback. Approve:
200
Reject the same way, or fix and re-upload before approving — a document that was never indexed stays out of agent retrieval either way:
200
Only documents pending review accept either decision — moderation status approved (or missing) returns 409 CONFLICT, and a publish-scan rejected document must be fixed and re-uploaded before it can be approved. Both actions are audit-logged.

5.4 Roll back a published version

Read the version lineage first, then the diff that tells you what the head changed, and roll back the published version if the retrieval set needs a previous copy. GET .../versions lists the immutable lineage — current head plus retained snapshots — without the heavy content blobs.
200
Read the diff for the two versions you care about. A version outside the retained lineage returns 404; a version whose content was too large to retain returns 422 — rollback works only against retained snapshots.
200
Then roll the document back. Non-destructive: the current head moves into the retained history first, so the operation is fully reversible.
202

5.5 Search the knowledge base

The POST .../search hook is the same retrieval an attached AI agent’s search_knowledge tool runs, and the response shape exists so you can preview what an agent would ground on before a customer asks. The body is query (required, ≤ 1000 chars) plus optional limit (default 5, max 20); when a per-base search config is active, recency, source weighting, and category filters apply before the list is truncated. An empty results array means no chunk cleared the raw similarity floor — check whether the document you expect is uploaded, approved, and indexed.
200

5.6 Delete a document and re-approve publication

A document stuck in moderation, or one the team retires, goes away in one call; anything that carries a public help-center article keeps its status through the same record — flip is_public on the publication endpoint once status is ready. Deleting returns 204 with no body.
204
Then re-publish the surviving document the public help center should keep. The body is { is_public: boolean, slug?, summary? }; flipping public requires the document’s ingestion be done (status: ready), and the slug is unique across every published article in your workspace — a slug collision returns 409 CONFLICT.
200
A document deleted after approval had its chunks removed from the vector index — a re-upload restarts the moderation queue from pending.

SDK surface bridge — Create a knowledge base and add its first source entry — the no-exec/callable shape the agent-runtime retrieval layer consumes.

These three tabs mirror SDK status and coverage. Python fronts client.request, Go fronts client.Request, and TS fronts fetch-TS — each with the sandbox key.

Create a knowledge base

Add a source entry