Skip to main content

Worked knowledge-bases samples

The endpoint list below documents every operation’s parameters; this overlay walks a knowledge base the way an AI-agent integration actually uses it: list the knowledge bases → read their documents → upload one document → handle a stale or rejected-upload error. Success envelopes are { data, meta }, error envelopes { error, meta } — see How to read a worked sample. Run samples with a sandbox (dv_test_sk_*) key; documents the pipeline cannot validate (error indexing status) never enter the agent’s retrieval set, and you can re-queue them via the retry endpoint (see Knowledge bases). Every response carries meta.request_id and meta.timestamp. Quote the request id when you report a failing upload or a drifted document status.

1. List knowledge bases

GET /api/v1/knowledge-bases returns your workspace’s knowledge-base records — id, name, description, optional config, refresh cadence — with pagination. Use this to populate an AI-agent threading UI or pick the kb to which a document will be uploaded.
200
Field notes a reader will hit on first integration:
  • refresh_schedule is manual (default) or one of the recurring cadence values the create endpoint accepts — the non-manual values drive recurring re-scrape of URL/RSS/Notion sources.
  • document_count is a read cache; update it with the list- read and use the documents endpoint below for per-file truth.

2. Read a knowledge base’s documents

GET /api/v1/knowledge-bases/{id}/documents returns the document ledger for one knowledge base — the rows an operator sees on the dashboard — and reports pre-ingest status for each file (pending, indexed, error, failed). A rejected upload tells you the analysis and moderation pipeline flagged it so you can act on the offending chunk.
200

3. Upload one document

POST /api/v1/knowledge-bases/{id}/documents ingests a text/markdown document into the knowledge base. The body is the uploadDocumentSchema — name, type (one of the allowed text-code/image formats via vision OCR), and content up to the router’s 10 MB text-upload cap. Files larger than that need the multipart endpoint the dashboard uses; an image upload flows through OCR transcription and chains into the same retrieval set.
200

4. Errors

Errors follow the { error, meta } envelope. The failure every uploader hits: 422 — validation. A name past 200 characters, unsupported type, or a body over the text-upload cap:
422

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 — the response is 202 because the sync runs asynchronously; poll GET /api/v1/knowledge-bases/{id}/connectors for the connector’s last-sync status.
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.

Moderation & sync round-trips

The samples above walk one document through upload and retrieval; this section walks the round trips a review pipeline automates: decide a pending document, roll a published version back when an eval regresses, queue refreshes and syncs as jobs, and read the drift and retrieval previews that tell you why. Every body keeps the { data, meta } envelope (errors keep { error, meta }), and each response echoes enough state that your pipeline does not need a follow-up read to know what changed.

1. Approve a pending document

Send the reviewer’s rationale in notes; the 200 echoes the decision and the document’s status transition out of pending:
200
A document that already carries a decision does not accept a second one. Re-posting approve (or reject) against it returns 409:
409

2. Reject a pending document

The reject round trip mirrors approve: the same notes body, the same 409 once decided, and a 200 that echoes the transition to rejected so the submitter sees the rationale on the document:
200

3. Roll back with version pointers

The rollback 202 names the restore explicitly: from_version is the retained snapshot you restore, to_version the head it replaces, and version the new head the restore creates. The replaced head is snapshotted into history first, so rolling forward again uses the same call.
202

4. Refresh and sync enqueue jobs

POST .../refresh and POST .../connectors/{connectorId}/sync both answer 202 with a job handle rather than blocking on the pull. Keep the job_id; the follow-up status read below echoes it.
202
202
Follow up with GET /api/v1/knowledge-bases/{id}: the knowledge-base record carries the job’s terminal state, and last_refresh_at only moves when the pull succeeds. A sync job settles the same way on the connector record (GET .../connectors), where last_synced_at advances on success.
200

5. Drift report entries per connector

The drift report’s per-connector entries list exactly which documents diverged since the last successful sync: added, removed, and changed carry document ids, and detected_at names the check that first saw the divergence. An in_sync connector returns empty arrays and a null detected_at.
200

6. Search returns scored hits with citation spans

Each hit carries its similarity score plus citation_spans: the character offsets inside content the retriever actually matched, so you can underline the grounded passage in your own UI before a customer ever asks.
200
An empty results array means no chunk cleared the similarity floor; check that the document you expect is uploaded, approved, and indexed before debugging the query.

7. Poll a reindex job until it settles

The refresh and sync kick-offs above answer 202 with a job_id; the poll then reads the owning record — GET /api/v1/knowledge-bases/{id} for a refresh, GET .../connectors for a sync. The knowledge-base record carries the job’s terminal state exactly as the Orby endpoints page’s Trigger an Orby knowledge-base reindex does for the operator docs index: the trigger answers scheduled, and the follow-up status read reports the run’s terminal state. Same status vocabulary — queued → succeeded with a finished timestamp — so one polling helper serves both surfaces:
200
last_refresh_at only moves when the pull succeeds; a job that ends failed leaves it at the previous value and puts the reason on last_refresh_job.error, mirroring how the Orby reindex read reports a failed run.

Per-operation response envelopes

The numbered sections above narrate the loops; this section gives every operation on this page its own response body, in page order, so each operation’s reference entry and its worked sample show the same envelope. Identifiers stay the ones used throughout this overlay — kb_8fb2d1b7c00c4ec9, doc_8fb2d1b7c00c4ec9, doc_9e8d7c6b5a4f3021, doc_3c9d0e2f4b5e8a1f, kbc_4b5e8a1f3c9d0e2f — and statuses stay pending → approved / rejected, processing → indexed / failed, jobs queued → succeeded. The operator-side copilot indexes the product docs the same way your agents index these bases: the Orby endpoints page’s Trigger an Orby knowledge-base reindex and its index-status read use the identical trigger-then-poll contract: the kick-off acknowledges the queued run, and the follow-up read carries the terminal status plus the finished timestamp. Where that page names operator-docs chunks, this page names your tenant’s knowledge bases; the envelopes below keep the same field names and status vocabulary so a pipeline written against one ports to the other.

GET /api/v1/knowledge-bases

200

GET /api/v1/knowledge-bases/{id}

200
A knowledge base id from another workspace is invisible to yours and answers 404, the same envelope a deleted base returns:
404

GET /api/v1/knowledge-bases/{id}/connector-drift-report

200

GET /api/v1/knowledge-bases/{id}/connectors

200

GET /api/v1/knowledge-bases/{id}/documents

200

GET /api/v1/knowledge-bases/{id}/documents/{docId}/versions

200

GET /api/v1/knowledge-bases/{id}/documents/{docId}/versions/diff

200

GET /api/v1/knowledge-bases/{id}/staleness

200

POST /api/v1/knowledge-bases

200

POST /api/v1/knowledge-bases/{id}/connectors

200

POST /api/v1/knowledge-bases/{id}/connectors/{connectorId}/sync

200
Poll the connector list above until the connector’s status settles and last_synced_at advances — the same trigger-then-poll shape the Orby endpoints page shows for the operator docs reindex.

POST /api/v1/knowledge-bases/{id}/documents

200
The ingest pipeline accepts the text, code, and image formats the upload schema lists; anything else is rejected before indexing:
422

POST /api/v1/knowledge-bases/{id}/documents/{docId}/approve

200

POST /api/v1/knowledge-bases/{id}/documents/{docId}/reject

200

POST /api/v1/knowledge-bases/{id}/documents/{docId}/rollback

200

POST /api/v1/knowledge-bases/{id}/refresh

200

POST /api/v1/knowledge-bases/{id}/search

200

PUT /api/v1/knowledge-bases/{id}

200

PATCH /api/v1/knowledge-bases/{id}/connectors/{connectorId}

200
Setting enabled: false pauses scheduled syncs; the connector keeps its lineage so re-enabling resumes from the last successful pull.

PATCH /api/v1/knowledge-bases/{id}/documents/{docId}/publication

200

Document status transitions

A document moves pending → processing → indexed when the analysis, moderation, and vector-indexing stages all pass; a stage that fails leaves the document at failed with the reason on the row, and the document stays out of retrieval until it is re-uploaded. The transitions read (GET /api/v1/knowledge-bases//documents, no backticks needed here — this section narrates rather than paints):
200
A moderation verdict lands the same way: approve moves a pending document into the indexing queue (processing, then indexed), reject moves it to rejected, and both echo the decision in moderation as shown on the approve and reject operations above.