Add documents to a knowledge base
Add documents to an existing knowledge base.
Add documents to an existing knowledge base.
Send multipart/form-data with one or more files parts. The same
limits and the same slow, synchronous ingest as
POST /v2/knowledge-bases apply: 10 files, 25MB each, 50MB per request,
PDF/PNG/JPG/JPEG only, up to 180 seconds.
A knowledge base that does not exist in your organisation answers 404 —
create it with POST /v2/knowledge-bases first. Uploading a file that is
already present adds a second copy of its chunks rather than replacing them,
and there is no way to remove them, so check the documents list before
re-uploading after a timeout.
Content-Length is required, and a second concurrent upload from the same
organisation answers 429 with Retry-After.
Rate limit: 20 requests per minute per organization (bucket knowledge.upload). Exceeding it returns 429 with Retry-After; the X-RateLimit-* response headers report your remaining allowance on every call.
v2/knowledge-bases/{collection}/documentsAuthorization
AuthorizationRequiredBearer <token>
Your Graine API key. Create one in the dashboard under Developers, or via POST /v2/api-keys. Send it as Authorization: Bearer <key>.
In: header
Request Body
multipart/form-dataRequiredfilesRequiredarray<file>
The documents. Repeat the field once per file: PDF, PNG, JPG or JPEG, at most 10 files, 25MB each, 50MB per request.
Path Parameters
collectionRequiredCollection
The knowledge base name.
Query Parameters
organization_idOrganization Id
Must match the organisation the API key belongs to.
Response Body
201
What was indexed into the knowledge base.
collectionRequiredCollection
The knowledge base the documents were added to.
retrieval_idRequiredRetrieval Id
The identifier to give an agent's rag_config.
files_acceptedRequiredFiles Accepted
File names that were ingested.
chunks_indexedRequiredChunks Indexed
Text chunks created. Zero means nothing was extracted.
metadata_recordedRequiredMetadata Recorded
False when the documents were indexed but their metadata record failed to write: retrieval works, listings will not show them.
warningsRequiredWarnings
Non-fatal problems with this upload. Usually empty.
400
1000 — malformed input (bad knowledge base name, unreadable or empty file).
errorRequiredError
Stable integer code from the /v2 error table. Branch on this.
messageRequiredMessage
One human-readable sentence. Wording may change; the code will not.
401
1100 — missing, unknown or inactive API key. 1101 — a browser session token was presented.
errorRequiredError
Stable integer code from the /v2 error table. Branch on this.
messageRequiredMessage
One human-readable sentence. Wording may change; the code will not.
403
1102 — the key is valid but lacks the scope this endpoint requires, or names another organisation. GET /v2/scopes reports which scopes the key holds.
errorRequiredError
Stable integer code from the /v2 error table. Branch on this.
messageRequiredMessage
One human-readable sentence. Wording may change; the code will not.
404
1200 — no such knowledge base in this organisation. Cross-tenant reads answer 404, never 403.
errorRequiredError
Stable integer code from the /v2 error table. Branch on this.
messageRequiredMessage
One human-readable sentence. Wording may change; the code will not.
409
1201 — that knowledge base name is not available, or it already exists.
errorRequiredError
Stable integer code from the /v2 error table. Branch on this.
messageRequiredMessage
One human-readable sentence. Wording may change; the code will not.
411
1000 — an upload arrived without Content-Length. Chunked uploads are not accepted.
errorRequiredError
Stable integer code from the /v2 error table. Branch on this.
messageRequiredMessage
One human-readable sentence. Wording may change; the code will not.
413
1000 — the upload exceeds the per-file or per-request size limit.
errorRequiredError
Stable integer code from the /v2 error table. Branch on this.
messageRequiredMessage
One human-readable sentence. Wording may change; the code will not.
415
1000 — a file is not a PDF, PNG, JPG or JPEG.
errorRequiredError
Stable integer code from the /v2 error table. Branch on this.
messageRequiredMessage
One human-readable sentence. Wording may change; the code will not.
422
1001 — the body or query failed validation; the message names the first offending field.
errorRequiredinteger
Stable integer code from the error table. Branch on this, not on the message.
messageRequiredstring
One human-readable sentence. Wording may change; the code will not.
429
1300 — per-organisation rate limit exceeded. Carries Retry-After.
errorRequiredError
Stable integer code from the /v2 error table. Branch on this.
messageRequiredMessage
One human-readable sentence. Wording may change; the code will not.
503
1501 — the knowledge service is unreachable or returned a 5xx.
errorRequiredError
Stable integer code from the /v2 error table. Branch on this.
messageRequiredMessage
One human-readable sentence. Wording may change; the code will not.
504
1502 — the knowledge service did not respond in time. A slow ingest may still complete.
errorRequiredError
Stable integer code from the /v2 error table. Branch on this.
messageRequiredMessage
One human-readable sentence. Wording may change; the code will not.
What was indexed into the knowledge base.

