Knowledge Bases API
Knowledge bases store documents that ground AI replies. Backed by Qdrant; uploaded files are chunked, embedded, and indexed.
Endpoints
| Method | Path | Description |
|---|---|---|
| GET | `/api/v1/knowledge-bases` | List |
| POST | `/api/v1/knowledge-bases` | Create |
| GET | `/api/v1/knowledge-bases/:id` | Get |
| PATCH | `/api/v1/knowledge-bases/:id` | Update |
| DELETE | `/api/v1/knowledge-bases/:id` | Delete |
| POST | `/api/v1/knowledge-bases/:id/upload` | Upload a document (multipart/form-data) |
| POST | `/api/v1/knowledge-bases/:id/test` | Test query (returns answer + sources) |
| GET | `/api/v1/knowledge-bases/:id/stats` | Document / chunk / token counts |
Upload Flow
curl -X POST https://api.anvilhk.com/api/v1/knowledge-bases/kb_01H.../upload \
-H "Authorization: Bearer $ANVIL_KEY" \
-H "X-Tenant-ID: $TENANT" \
-F "file=@product-faq.pdf"Returns { documentId, chunks }. Embedding is async; poll /stats until tokens increases.
Test Query
curl -X POST https://api.anvilhk.com/api/v1/knowledge-bases/kb_01H.../test \
-H "Authorization: Bearer $ANVIL_KEY" \
-H "X-Tenant-ID: $TENANT" \
-H "Content-Type: application/json" \
-d '{ "question": "What is your MOQ?" }'Every response uses the standard envelope:
{
"success": true,
"data": { /* resource or array */ },
"meta": { "total": 100, "cursor": "...", "hasMore": true },
"error": { "code": "ERROR_CODE", "message": "Human readable" }
}error is omitted on success; meta is omitted when not paginating.
Rate Limits
Subject to the standard 200 req/min/tenant authenticated limit. See [Rate Limits](/docs/api-reference/rate-limits) for full details and the per-endpoint overrides.