Writing documents
Put, update and delete documents, in batches, with the durability, visibility and retry rules that apply to every write.
A document is {"id", "text", "meta", "vector"}. You write documents to a namespace by id:
writing an id again replaces the whole document. One request can put and delete together, and
it is atomic. This page covers every way to write, and what happens to a write after you send
it.
Put and delete
POST /v1/namespaces/{name}/docs puts (inserts or replaces) documents and deletes ids in one
request: 1 to 10,000 documents and deletes, 64 MB at most.
B=https://api.skimmerdb.com/v1
curl -s $B/namespaces/support/docs -H "Authorization: Bearer $KEY" -d '{
"docs": [
{"id": "t-3", "text": "Webhook timeouts since Tuesday", "meta": {"team": "api", "status": "open"}}
],
"deletes": ["t-2"]
}'
# {"written": 1, "deleted": 1, "version": 3, "stored_bytes": 2817, "created": false}from skimmerdb import SkimmerDB
db = SkimmerDB() # SKIMMERDB_KEY from the environment
ns = db.namespace("support")
r = ns.write(
[{"id": "t-3", "text": "Webhook timeouts since Tuesday", "meta": {"team": "api", "status": "open"}}],
deletes=["t-2"],
)
print(r.written, r.deleted)import { SkimmerDB } from "skimmerdb";
const db = new SkimmerDB(); // SKIMMERDB_KEY from the environment
const ns = db.namespace("support");
const r = await ns.write(
[{ id: "t-3", text: "Webhook timeouts since Tuesday", meta: { team: "api", status: "open" } }],
{ deletes: ["t-2"] },
);
console.log(r.written, r.deleted);- Within one request, deletes apply before puts, so deleting and putting the same id leaves the new document.
textmay be left out when the document has a vector.metais a JSON object of strings, numbers and booleans, up to 16 KB; see Data model for how to shape it.- The answer:
writtenanddeleted(counts),version(the namespace's version after the write),stored_bytes, andcreated(truewhen this write made the namespace).
Update
PATCH /v1/namespaces/{name}/docs changes existing documents without resending them whole:
text is replaced if given, meta is merged key by key, and a null value removes a key. A
vector is kept unless the patch gives a new one.
curl -s -X PATCH $B/namespaces/support/docs -H "Authorization: Bearer $KEY" \
-d '{"docs": [{"id": "t-1", "meta": {"status": "closed", "priority": null}}]}'ns.update([{"id": "t-1", "meta": {"status": "closed", "priority": None}}])await ns.update([{ id: "t-1", meta: { status: "closed", priority: null } }]);Updating a namespace that doesn't exist is a 404 (only puts create namespaces).
Delete
By id, with POST /v1/namespaces/{name}/delete:
curl -s $B/namespaces/support/delete -H "Authorization: Bearer $KEY" -d '{"ids": ["t-3"]}'ns.delete(["t-3"])await ns.delete(["t-3"]);To delete everything, drop the namespace: DELETE /v1/namespaces/{name} (ns.drop()). Its
documents are deleted from storage right after.
Read one document
GET /v1/namespaces/{name}/docs/{id} returns the whole document: id, text, meta,
written_at, and the vector if it has one. Ids may hold slashes:
GET .../docs/agent-1/run-42/step-3.
curl -s $B/namespaces/support/docs/t-1 -H "Authorization: Bearer $KEY"
# {"id": "t-1", "text": "...", "meta": {...}, "written_at": "..."}doc = ns.get("t-1")const doc = await ns.get("t-1");Creating namespaces
The first write to a name that doesn't exist makes the namespace and answers
"created": true, so a mistyped name shows. If the documents have vectors, the namespace gets
vectors of the first vector's length, with the cosine metric; otherwise it's text only.
To choose the vector settings yourself (for example the euclidean metric), create it first:
curl -s $B/namespaces -H "Authorization: Bearer $KEY" \
-d '{"name": "notes", "vector": {"dims": 768, "metric": "euclidean"}}'notes = db.create_namespace("notes", dims=768, metric="euclidean", exist_ok=True)const notes = await db.createNamespace("notes", { dims: 768, metric: "euclidean", existOk: true });dims (1 to 2,048) and metric (cosine, the default, or euclidean) are fixed for the
namespace's life. See Vector and hybrid search.
Durability and visibility
- Durable when answered. A write is answered once it is stored in object storage. Writes from every tenant on a server are logged together every 250 ms, so a write takes about that long.
- Searchable at once on the server that took it, and on every server within about a second.
"wait": trueanswers only once the write is searchable on that server. Use it when the next step reads what you just wrote (a test, an agent that writes then searches); leave it off otherwise.- Atomic. A request's documents and deletes become visible together or not at all.
More in Durability.
Batching
Many small requests work, since the server groups them every 250 ms anyway, but each one counts against your rate limit (100 requests a second on free, 1,000 on pro). A batch of up to 10,000 documents is one request and one atomic entry.
For files of rows (CSV, NDJSON, Parquet), use import instead: up to 2 GB a request, parsed straight into columns.
Tip Append-only data (events, logs, traces written once) is the cheapest shape to store, compact and query. Updates are fine, but each one writes a new version and the old one waits for compaction.
Versions and conditional writes
Every document has a version: where its current text was written. A read gives it (GET .../docs/{id}), and a write with wait: true returns the new ones under versions. Writing
or deleting the document changes it; nothing else does, compaction included.
To change a document only if nobody else has since you read it, send the version back as
if_version. To create one only if the id is free, send if_absent: true. Conditions on ids
you delete go in if_versions ({"id": "version"}, or null for "must not exist").
V=$(curl -sS $B/namespaces/support/docs/t-1 -H "Authorization: Bearer $KEY" | jq -r .version)
curl -sS $B/namespaces/support/docs -H "Authorization: Bearer $KEY" \
-H "Content-Type: application/json" -d '{"wait": true, "docs": [
{"id": "t-1", "text": "Refund issued for order ACME-1042", "if_version": "'$V'"},
{"id": "t-9", "text": "Follow-up call booked", "if_absent": true}]}'
# 200, and "versions" holds both documents' new versions; a stale V: 409 version_conflictfrom skimmerdb import SkimmerDBError
doc = ns.get("t-1")
try:
ns.write([{"id": "t-1", "text": "Refund issued", "if_version": doc.version}], wait=True)
except SkimmerDBError as e:
if e.status == 409: # code "version_conflict": someone changed it; read again and retry
...const doc = await ns.get("t-1");
try {
await ns.write([{ id: "t-1", text: "Refund issued", if_version: doc.version }], { wait: true });
} catch (e) {
if (e instanceof SkimmerDBError && e.status === 409) {
// version_conflict: someone changed it; read again and retry
}
}- All or nothing. A write is one commit: if any condition fails, none of its documents or
deletes are written. The
409answer lists each one underconflicts(id,expected,current). - Checked in commit order. A write to the same id that arrived first (conditional or not) makes your condition fail even before it's searchable, so a stale version never overwrites a newer document.
- Imports, SQL writes and DuckLake syncs aren't conditional, and a conditional write waits for one that's committing in the same namespace.
Idempotent retries
A write can fail in a way that leaves you unsure whether it was applied: a lost connection, a
timeout, a 503 write_unknown. Plain writes are safe to repeat, since the same ids replace
themselves. A conditional write or a delete you then follow with other writes may not be.
Send an Idempotency-Key header (any unique string up to 255 bytes) and a retry with the same
key and body is done once: later tries get the first answer back.
curl -sS $B/namespaces/support/docs -H "Authorization: Bearer $KEY" \
-H "Content-Type: application/json" -H "Idempotency-Key: ticket-t-1-refund-2" \
-d '{"docs": [{"id": "t-1", "text": "Refund issued"}]}'ns.write([{"id": "t-1", "text": "Refund issued"}], idempotency_key="ticket-t-1-refund-2")await ns.write([{ id: "t-1", text: "Refund issued" }], { idempotencyKey: "ticket-t-1-refund-2" });- Keys belong to your tenant and last 24 hours.
POST .../docs,POST .../deleteandPATCH .../docstake them; MCP'swrite_documentsanddelete_documentstakeidempotency_key. - The same key with a different request:
422 idempotency_mismatch. A retry while the first is still running:409 idempotency_in_progress(retry shortly). - Answers a retry could change (
429,402,5xx) aren't kept, so the retry runs.
Errors and retries
Writes are by id, so resending the same batch is always safe: it replaces what may already be there.
| Answer | Meaning | What to do |
|---|---|---|
429 write_busy | Writes to this namespace are arriving faster than they commit. Nothing was written. | Wait Retry-After seconds (also retry_after in the body), resend the same batch. |
429 rate_limited | Over the tenant's or the key's rate, concurrency or cap. | Wait Retry-After seconds. |
503 unavailable | Object storage failed. Nothing was written. | Retry. |
503 write_unknown | The write may or may not have been applied. | Retry it: the same ids replace whatever is there. |
409 version_conflict | A condition (if_version, if_absent, if_versions) didn't hold. Nothing was written. | Read the documents again, decide, and write with their new versions. |
413 too_large | Over 10,000 documents or 64 MB. | Split the batch. |
422 invalid | Something in the body is wrong (fields says what), e.g. a vector of the wrong length. | Fix the request. |
507 quota_full | The tenant's storage quota is full. | Delete data or upgrade. |
The Python and TypeScript clients retry 429 and 503 answers for you (three times, after
Retry-After or backing off), then raise SkimmerDBError with status, code and the
message. All codes: Errors.