Skip to main content

Knowledge Bases API

Knowledge Bases endpoints exposed by the Devotel CPaaS API Base path: /api/v1/knowledge-bases Endpoint count: 3

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.
Node.js
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:
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.
200
To restore an earlier version, POST /knowledge-bases/kb_abc123/documents/doc_9a1c3e5b7d/rollback with { "version": 1 } — non-destructive, since the current head is snapshotted first.

Get knowledge-base search config

GET /api/v1/knowledge-bases/{id}/search-config
Read a knowledge base’s retrieval re-rank / relevance-boost config — recency boost, per-source weights, category include/exclude, and the minimum-score threshold that govern which chunks ground every agent answer for this KB. A KB that has never been tuned reads back as the neutral default (every field a no-op, identical to legacy raw-similarity ordering). Read-only; requires the knowledge:read scope.
string
required
Knowledge base ID (kb_…).
string (enum: true|false)
Sandbox opt-in for Clerk-session-authenticated requests. Set to true to route the call through the test-mode pipeline: no real provider delivery, no credits deducted, response meta.test_mode: true. Ignored for live API keys (dv_live_sk_*) — server-to-server clients must use a test-prefixed key (dv_test_sk_*) to exercise sandbox. Test-prefixed keys unconditionally enable sandbox regardless of this header.

Retry document indexing

POST /api/v1/knowledge-bases/{id}/documents/{docId}/retry
Re-queue a failed knowledge-base document for indexing. Use when a document upload reported an error indexing status and you fixed the underlying cause — the document’s chunks are re-extracted and re-indexed so the AI agent can retrieve them again. The retry is asynchronous: the endpoint returns 202 immediately with an empty body, and the document’s status transitions through pending to indexed (or back to error if it fails again) — poll GET /knowledge-bases/:id/documents for the outcome. Only failed documents are meaningfully retried. Requires an admin-class role and the knowledge:write scope; the call is audit-logged.
string
required
Knowledge base id, as returned by GET /knowledge-bases.
string
required
Document id within that knowledge base, as returned by GET /knowledge-bases/:id/documents.
string
Stripe-style idempotency token. Pass a stable, client-generated value (1-255 chars) to dedupe retries on transient timeouts. The same key+credential+path replays the original response for 24h on 2xx (5min on 4xx, 30s on 5xx). Returns 409 if a concurrent request with the same key is already in flight; replayed responses include the Idempotency-Replay: true response header.
string (enum: true|false)
Sandbox opt-in for Clerk-session-authenticated requests. Set to true to route the call through the test-mode pipeline: no real provider delivery, no credits deducted, response meta.test_mode: true. Ignored for live API keys (dv_live_sk_*) — server-to-server clients must use a test-prefixed key (dv_test_sk_*) to exercise sandbox. Test-prefixed keys unconditionally enable sandbox regardless of this header.

Update knowledge-base search config

PUT /api/v1/knowledge-bases/{id}/search-config
Replace a knowledge base’s retrieval re-rank / relevance-boost config. Every field has a no-op default, so a PUT of {} resets the KB to legacy raw-similarity ordering and an omitted knob never silently changes the others. Values are range-clamped server-side. Returns the normalised config. Requires the knowledge:write scope (admin / owner / developer).
string
required
Knowledge base ID (kb_…).
string
Stripe-style idempotency token. Pass a stable, client-generated value (1-255 chars) to dedupe retries on transient timeouts. The same key+credential+path replays the original response for 24h on 2xx (5min on 4xx, 30s on 5xx). Returns 409 if a concurrent request with the same key is already in flight; replayed responses include the Idempotency-Replay: true response header.
string (enum: true|false)
Sandbox opt-in for Clerk-session-authenticated requests. Set to true to route the call through the test-mode pipeline: no real provider delivery, no credits deducted, response meta.test_mode: true. Ignored for live API keys (dv_live_sk_*) — server-to-server clients must use a test-prefixed key (dv_test_sk_*) to exercise sandbox. Test-prefixed keys unconditionally enable sandbox regardless of this header.
any
Minimum raw vector similarity (0..1) a chunk must clear to reach the agent. 0 = no floor (default).
any
Recency multiplier strength (0..5). 0 = off (default); fresher docs get up to ×(1 + boost).
any
Half-life in days of the recency decay (1..3650). Default 30.
object
Map of source label → score multiplier (0..20, keys matched case-insensitively). Default .
string[]
Allow-list of categories; empty = allow all (default).
string[]
Deny-list of categories. Default [].