Create and manage knowledge bases, add sources, and connect them to chatbots.
Overview
A Knowledge Base (KB) is a collection of text sources that Sarufi uses to answer questions via retrieval-augmented generation (RAG). Sources can be plain text snippets or URLs that Sarufi will crawl.
Once created, a KB is attached to one or more chatbots. When a user asks a question the chatbot's flow doesn't explicitly handle, the KB is queried for a relevant answer.
List Knowledge Bases
Returns all KBs in the workspace.
http
GET /api/dev/v1/knowledge-basesAuthorization: Bearer <api-key>GET /api/dev/v1/knowledge-basesAuthorization: Bearer <api-key>
bash
curl -X GET https://developers.sarufi.io/api/dev/v1/knowledge-bases \ -H "Authorization: Bearer <your-api-key>"curl -X GET https://developers.sarufi.io/api/dev/v1/knowledge-bases \ -H "Authorization: Bearer <your-api-key>"
POST /api/dev/v1/knowledge-bases/{kb_id}/sources/textAuthorization: Bearer <api-key>Content-Type: application/jsonPOST /api/dev/v1/knowledge-bases/{kb_id}/sources/textAuthorization: Bearer <api-key>Content-Type: application/json
Body
titlestringrequired
Document title used in citations.
contentstringrequired
The full text content to index. Markdown is supported.
bash
curl -X POST https://developers.sarufi.io/api/dev/v1/knowledge-bases/<kb-id>/sources/text \ -H "Authorization: Bearer <your-api-key>" \ -H "Content-Type: application/json" \ -d '{ "title": "Return Policy", "content": "We accept returns within 30 days of purchase. Items must be in original condition..." }'curl -X POST https://developers.sarufi.io/api/dev/v1/knowledge-bases/<kb-id>/sources/text \ -H "Authorization: Bearer <your-api-key>" \ -H "Content-Type: application/json" \ -d '{ "title": "Return Policy", "content": "We accept returns within 30 days of purchase. Items must be in original condition..." }'
python
import requestsresponse = requests.post( "https://developers.sarufi.io/api/dev/v1/knowledge-bases/<kb-id>/sources/text", headers={"Authorization": "Bearer <your-api-key>"}, json={ "title": "Return Policy", "content": "We accept returns within 30 days of purchase. Items must be in original condition...", },)print(response.json())import requestsresponse = requests.post( "https://developers.sarufi.io/api/dev/v1/knowledge-bases/<kb-id>/sources/text", headers={"Authorization": "Bearer <your-api-key>"}, json={ "title": "Return Policy", "content": "We accept returns within 30 days of purchase. Items must be in original condition...", },)print(response.json())
javascript
const response = await fetch("https://developers.sarufi.io/api/dev/v1/knowledge-bases/<kb-id>/sources/text", { method: "POST", headers: { "Authorization": "Bearer <your-api-key>", "Content-Type": "application/json", }, body: JSON.stringify({ title: "Return Policy", content: "We accept returns within 30 days of purchase. Items must be in original condition...", }),});const data = await response.json();const response = await fetch("https://developers.sarufi.io/api/dev/v1/knowledge-bases/<kb-id>/sources/text", { method: "POST", headers: { "Authorization": "Bearer <your-api-key>", "Content-Type": "application/json", }, body: JSON.stringify({ title: "Return Policy", content: "We accept returns within 30 days of purchase. Items must be in original condition...", }),});const data = await response.json();
After adding a source its status is processing. Indexing usually completes within a few seconds. Poll the list sources endpoint or check status until it reads ready.
Add Web Source
Crawls a URL and indexes its content.
http
POST /api/dev/v1/knowledge-bases/{kb_id}/sources/webAuthorization: Bearer <api-key>Content-Type: application/jsonPOST /api/dev/v1/knowledge-bases/{kb_id}/sources/webAuthorization: Bearer <api-key>Content-Type: application/json
Body
urlstringrequired
Public URL to crawl. Must be accessible without authentication.
titlestringoptional
Override title. If omitted, the page's <title> tag is used.