Upload documents for context-aware conversations
Get your documents into the knowledge bank and confirm the avatar can actually find them.
This guide covers the practical side of loading documents: what is accepted, how to confirm extraction worked, and how to check retrieval before a user does it for you.
For how retrieval fits into a conversation, see Knowledge bank.
Every request needs your API key. Set it once:
export GOLDENENGINE_API_KEY="<YOUR_API_KEY>"
What is accepted
| Constraint | Value |
|---|---|
| Formats | PDF and DOCX |
| Maximum size | 50 MB per file |
| Files per request | 1 with file; up to 5 with the batch endpoints below |
Other formats are rejected at upload. Convert Markdown, HTML, or plain text to PDF first — export from whatever tool owns the content rather than hand-converting, so headings survive.
The check looks at both the extension and the file part's content type. If a content type is
sent it must be application/pdf or
application/vnd.openxmlformats-officedocument.wordprocessingml.document; a generic
application/octet-stream gets a 400 reading Unsupported file content type. That is what
a Node.js Blob without a type sends, and what cURL sends for a .docx unless you name the
type — the samples below set it explicitly.
Upload
Two endpoints, depending on which avatars should see the document. For how that scoping works, see Which avatars see a document.
Attach to one avatar as you upload — only that avatar will use it:
- cURL
- Python
- Node.js
curl -s "https://backend.goldenengine.ai/v1/avatars/$AVATAR_ID/knowledge" \
-H "X-Api-Key: $GOLDENENGINE_API_KEY" \
import os
import requests
BASE = "https://backend.goldenengine.ai"
HEADERS = {"X-Api-Key": os.environ["GOLDENENGINE_API_KEY"]}
with open("handbook.pdf", "rb") as document:
requests.post(
f"{BASE}/v1/avatars/{avatar_id}/knowledge",
headers=HEADERS,
files={"file": document},
)
import { readFile } from "node:fs/promises";
const BASE = "https://backend.goldenengine.ai";
const headers = { "X-Api-Key": process.env.GOLDENENGINE_API_KEY };
const form = new FormData();
form.set(
"file",
new Blob([await readFile("handbook.pdf")], { type: "application/pdf" }),
"handbook.pdf",
);
await fetch(`${BASE}/v1/avatars/${avatarId}/knowledge`, {
method: "POST",
headers,
body: form,
});
Upload to the account bank — no avatar uses it yet. Check the extraction, then attach it to the avatar it is for:
- cURL
- Python
- Node.js
curl -s "https://backend.goldenengine.ai/v1/knowledge-bank/upload" \
-H "X-Api-Key: $GOLDENENGINE_API_KEY" \
with open("handbook.pdf", "rb") as document:
item = requests.post(
f"{BASE}/v1/knowledge-bank/upload",
headers=HEADERS,
files={"file": document},
).json()
const form2 = new FormData();
form2.set(
"file",
new Blob([await readFile("handbook.pdf")], { type: "application/pdf" }),
"handbook.pdf",
);
const item = await (
await fetch(`${BASE}/v1/knowledge-bank/upload`, {
method: "POST",
headers,
body: form2,
})
).json();
Upload several at once
Both upload endpoints have a batch form that takes up to five files in one request. Send
them as repeated files fields — plural, unlike the single-file file — and the same
format and size limits apply to each one.
| Rule | Value |
|---|---|
| Files per request | 1 to 5 |
| Any file invalid (type or extension, empty, over 50 MB) or the wrong count | The whole request fails with 400, and nothing is uploaded or queued |
| All files queued | 201 |
| Some files not queued | 207, with the failures listed per file |
- cURL
- Python
- Node.js
curl -s "https://backend.goldenengine.ai/v1/avatars/$AVATAR_ID/knowledge/batch" \
-H "X-Api-Key: $GOLDENENGINE_API_KEY" \
with open("policy.pdf", "rb") as policy, open("manual.docx", "rb") as manual:
batch = requests.post(
f"{BASE}/v1/avatars/{avatar_id}/knowledge/batch",
headers=HEADERS,
files=[("files", policy), ("files", manual)],
).json()
const DOCX =
"application/vnd.openxmlformats-officedocument.wordprocessingml.document";
const form3 = new FormData();
form3.append(
"files",
new Blob([await readFile("policy.pdf")], { type: "application/pdf" }),
"policy.pdf",
);
form3.append(
"files",
new Blob([await readFile("manual.docx")], { type: DOCX }),
"manual.docx",
);
const batch = await (
await fetch(`${BASE}/v1/avatars/${avatarId}/knowledge/batch`, {
method: "POST",
headers,
body: form3,
})
).json();
To upload to the account bank instead, send the same form to /v1/knowledge-bank/upload/batch.
The response carries one entry per file, in the order you sent them:
{
"results": [
{
"index": 0,
"filename": "policy.pdf",
"item": {
"id": "b71f...",
"filename": "policy.pdf",
"file_type": "pdf",
"file_size_bytes": 482113,
"status": "uploaded",
"chunk_count": null,
"total_tokens": null
},
"error": null
},
{
"index": 1,
"filename": "manual.docx",
"item": null,
"error": { "code": "upload_failed", "message": "Could not store document" }
}
],
"submitted": 2,
"queued": 1,
"failed": 1
}
| Field | Meaning |
|---|---|
item | The stored document, with the same id and status a single upload returns. Poll it as below |
error | Why this file was not queued — code and message, shaped like the error envelope. Null when the file was queued |
submitted, queued, failed | Counts across the batch. failed above zero is what makes the status 207 |
Two error codes appear per file:
code | Meaning | item |
|---|---|---|
upload_failed | The file could not be stored | null |
queue_unavailable | The file was stored but extraction could not be queued | Set, with status: "failed" and the reason in error_message |
Either way, upload that file again.
Attach a bank document to an avatar
A document in the account bank is used by no avatar until you attach it. Attach it to the avatar that should answer from it:
- cURL
- Python
- Node.js
curl -s -X POST "https://backend.goldenengine.ai/v1/avatars/$AVATAR_ID/knowledge/attach" \
-H "X-Api-Key: $GOLDENENGINE_API_KEY" \
-H "Content-Type: application/json" \
-d "{\"knowledge_base_id\": \"$ITEM_ID\"}"
attached = requests.post(
f"{BASE}/v1/avatars/{avatar_id}/knowledge/attach",
headers=HEADERS,
json={"knowledge_base_id": item_id},
).json()
const attached = await (
await fetch(`${BASE}/v1/avatars/${avatarId}/knowledge/attach`, {
method: "POST",
headers: { ...headers, "Content-Type": "application/json" },
body: JSON.stringify({ knowledge_base_id: itemId }),
})
).json();
The document must have finished extracting first — attaching one that is still processing
fails with 409, and so does attaching one that already belongs to another of your avatars.
Attaching to one of your avatars moves the document out of the bank rather than copying it,
which is why the one-avatar limit above applies. Attaching to a stock avatar leaves it in the
bank, so one bank document can be attached to several stock avatars.
PATCH /v1/avatars/{avatar_id} with knowledge_base_ids is the other way to manage
attachments. It replaces the avatar's full set: documents you leave out go back to the account
bank, where no avatar uses them, and documents you list move to this avatar. It skips both 409 checks — it will move a
document that is still processing, or take one from another avatar, silently — so check
status and where each document is attached before using it.
Confirm extraction
Uploading is not the same as being searchable. Extraction runs asynchronously:
uploaded → processing → completed
↘ failed
Documents in the account bank are listed by GET /v1/knowledge-bank:
- cURL
- Python
- Node.js
curl -s "https://backend.goldenengine.ai/v1/knowledge-bank" \
-H "X-Api-Key: $GOLDENENGINE_API_KEY"
items = requests.get(f"{BASE}/v1/knowledge-bank", headers=HEADERS).json()
for item in items:
print(item["filename"], item["status"], item.get("chunk_count"))
const items = await (await fetch(`${BASE}/v1/knowledge-bank`, { headers })).json();
for (const item of items) {
console.log(item.filename, item.status, item.chunk_count);
}
That list leaves out anything attached to an avatar, and GET /v1/knowledge-bank/{item_id}
returns 404 for those. Check an avatar's documents with
GET /v1/avatars/{avatar_id}/knowledge, which returns the same fields:
- cURL
- Python
- Node.js
curl -s "https://backend.goldenengine.ai/v1/avatars/$AVATAR_ID/knowledge" \
-H "X-Api-Key: $GOLDENENGINE_API_KEY"
attached = requests.get(
f"{BASE}/v1/avatars/{avatar_id}/knowledge", headers=HEADERS
).json()
for item in attached:
print(item["filename"], item["status"], item.get("chunk_count"))
const attached = await (
await fetch(`${BASE}/v1/avatars/${avatarId}/knowledge`, { headers })
).json();
for (const item of attached) {
console.log(item.filename, item.status, item.chunk_count);
}
A rough sanity check: a text-heavy page produces a few hundred tokens. If a 40-page document reports a few hundred tokens in total, something went wrong in extraction.
Test retrieval
POST /v1/knowledge-bank/search runs a similarity search over the account bank, so you can
check that a document's text is in the index before putting it in front of anyone:
- cURL
- Python
- Node.js
curl -s "https://backend.goldenengine.ai/v1/knowledge-bank/search" \
-H "X-Api-Key: $GOLDENENGINE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"query": "what is the return window", "limit": 5}'
hits = requests.post(
f"{BASE}/v1/knowledge-bank/search",
headers=HEADERS,
json={"query": "what is the return window", "limit": 5},
).json()
const hits = await (
await fetch(`${BASE}/v1/knowledge-bank/search`, {
method: "POST",
headers: { ...headers, "Content-Type": "application/json" },
body: JSON.stringify({ query: "what is the return window", limit: 5 }),
})
).json();
limit defaults to 5 and caps at 20.
Two limits on what this tells you. It searches only documents in the account bank — so test a document here before you attach it to one of your avatars, or ask the avatar directly once it is attached. And it is not the avatar's own search: it returns the nearest chunks as they are, while the avatar's search drops weak matches, removes duplicate passages, and falls back to a keyword match when nothing matches by meaning. Treat good results as proof the text was extracted, not as a promise of what the avatar will retrieve.
Build a short list of real user questions and run all of them. This separates two failures that look identical in conversation:
| Symptom | Cause | Fix |
|---|---|---|
| Search returns nothing relevant | Documents missing, empty, or wrong | Fix the documents |
| Search is good, avatar still vague | Model is not calling the tool, or the prompt overrides it | Fix the system prompt |
Structure documents for retrieval
Documents are chunked, and chunks are matched individually — so each chunk needs to make sense on its own.
Use real headings. They give chunks boundaries that follow meaning rather than page breaks.
Keep answers near their questions. A policy stated on page 3 and its exceptions on page 40 may retrieve separately, and an answer built from one without the other is wrong.
Prefer several focused documents over one large one. A 300-page manual retrieves worse than a dozen topic-scoped files, and it is far easier to tell which file is stale.
Drop the boilerplate. Cover pages, revision histories, and legal footers compete with real content for retrieval slots.
Keeping documents current
- cURL
- Python
- Node.js
# Remove a stale document from the account bank
curl -s -X DELETE "https://backend.goldenengine.ai/v1/knowledge-bank/$ITEM_ID" \
-H "X-Api-Key: $GOLDENENGINE_API_KEY"
# Remove a stale document attached to an avatar (deletes the document and its file)
curl -s -X DELETE "https://backend.goldenengine.ai/v1/avatars/$AVATAR_ID/knowledge/$KNOWLEDGE_ID" \
-H "X-Api-Key: $GOLDENENGINE_API_KEY"
# Remove a stale document from the account bank
requests.delete(f"{BASE}/v1/knowledge-bank/{item_id}", headers=HEADERS)
# Remove a stale document attached to an avatar (deletes the document and its file)
requests.delete(
f"{BASE}/v1/avatars/{avatar_id}/knowledge/{knowledge_id}", headers=HEADERS
)
// Remove a stale document from the account bank
await fetch(`${BASE}/v1/knowledge-bank/${itemId}`, { method: "DELETE", headers });
// Remove a stale document attached to an avatar (deletes the document and its file)
await fetch(`${BASE}/v1/avatars/${avatarId}/knowledge/${knowledgeId}`, {
method: "DELETE",
headers,
});
Use the endpoint that matches where the document is: /v1/knowledge-bank/{item_id} returns
404 for a document attached to an avatar. Neither call detaches without deleting — for that,
PATCH the avatar's knowledge_base_ids as described above.
There is no versioning — updating means deleting the old document and uploading the new one. Deleting first avoids a window where both versions are searchable and the avatar answers from the wrong one.