|
@@ -96,7 +96,7 @@ Arbitrary JSON CRUD under a `kind=json` collection.
|
|
|
|
|
|
|
|
**Conditional writes: `?if_version=N`** on PUT and PATCH. The write applies only if the document is still at version `N`; otherwise **409** `version_conflict` with `error.details.expected_version` and, when it can be read, `error.details.current_version`. Read `_version` from a GET or from a `?filter=` listing, write with `?if_version=` that value, and retry from a fresh read on 409. `N` must be a positive integer (**422** `validation` otherwise; versions start at 1, so `if_version=0` is not "must not exist"). A conditional write never creates: `?if_version=` on an absent document is **404**, on PUT as well as PATCH. On PATCH it cannot be combined with `?ttl_seconds=` (**422** `conditional_unsupported`): the version-checked write has no expiry field, and silently dropping one of the two would be worse than refusing. It IS available on a `kind=vector` collection - a conditional PATCH is a server-side MERGE and preserves the stored embedding (measured). What is refused there is a whole-document **replace**: see `PUT` below.
|
|
**Conditional writes: `?if_version=N`** on PUT and PATCH. The write applies only if the document is still at version `N`; otherwise **409** `version_conflict` with `error.details.expected_version` and, when it can be read, `error.details.current_version`. Read `_version` from a GET or from a `?filter=` listing, write with `?if_version=` that value, and retry from a fresh read on 409. `N` must be a positive integer (**422** `validation` otherwise; versions start at 1, so `if_version=0` is not "must not exist"). A conditional write never creates: `?if_version=` on an absent document is **404**, on PUT as well as PATCH. On PATCH it cannot be combined with `?ttl_seconds=` (**422** `conditional_unsupported`): the version-checked write has no expiry field, and silently dropping one of the two would be worse than refusing. It IS available on a `kind=vector` collection - a conditional PATCH is a server-side MERGE and preserves the stored embedding (measured). What is refused there is a whole-document **replace**: see `PUT` below.
|
|
|
- `POST /api/v1/projects/{project}/collections/{name}/documents/{id}/increment` `{field: n, ...}` (or `{data:{...}}`) - **Atomic increment.** Adds each number to the named field in ONE locked server-side read-modify-write, so concurrent increments cannot lose each other. Dotted keys address nested fields (`counts.sent`). Returns **200** `{id, values}` where `values` holds the NEW value of every field you named. An absent or null field counts as 0. Integer + integer stays an integer (overflow is refused); anything else becomes a double. A field holding a non-number is **422** `validation` and **nothing at all is applied** - the whole set applies or none of it does. Needs the `update` grant (it is a write, so a read-only scope gets **403**); it is a separate route rather than a flag on PATCH because `{"calls":1}` means "set calls to 1" on PATCH and "add 1 to calls" here.
|
|
- `POST /api/v1/projects/{project}/collections/{name}/documents/{id}/increment` `{field: n, ...}` (or `{data:{...}}`) - **Atomic increment.** Adds each number to the named field in ONE locked server-side read-modify-write, so concurrent increments cannot lose each other. Dotted keys address nested fields (`counts.sent`). Returns **200** `{id, values}` where `values` holds the NEW value of every field you named. An absent or null field counts as 0. Integer + integer stays an integer (overflow is refused); anything else becomes a double. A field holding a non-number is **422** `validation` and **nothing at all is applied** - the whole set applies or none of it does. Needs the `update` grant (it is a write, so a read-only scope gets **403**); it is a separate route rather than a flag on PATCH because `{"calls":1}` means "set calls to 1" on PATCH and "add 1 to calls" here.
|
|
|
-- `GET /api/v1/projects/{project}/collections/{name}/export` - **Streaming backup, including stored vectors.** Answers **NDJSON** (`application/x-ndjson`): one JSON object per line, so the LINE is the unit of recovery and a truncated download loses the last row rather than the file. First line `{type:'header', collection, snapshot_at, vector_dimension, vector_dtype, rows_at_snapshot, batch_rows_cap, max_stream_seconds, include_vectors, vector_format}` (`snapshot_at` is server epoch seconds - "as of when" is the first question anyone asks of a backup, and a filesystem mtime does not survive a copy); then `{type:'row', id, document, vector_state, vector|vector_b64}` per document - **the vector field is named `vector` (a JSON array) with `vector_format=array`, and `vector_b64` (base64 of float32-little-endian) with `vector_format=base64`.** Handle BOTH names: a consumer who read only `vector` and exported as base64 saw a row reporting `vector_state: present` with no `vector` key, which looks exactly like the data loss `vector_state` exists to report; then `{type:'trailer', rows_sent, last_id, complete, content_sha256}`. **`content_sha256` is over each row's id and its RAW VECTOR BYTES, not over the emitted text**, so it is IDENTICAL whichever `vector_format` you asked for - you can export as base64, restore, re-export as an array and still compare digests. It is omitted rather than empty if it could not be computed.
|
|
|
|
|
|
|
+- `GET /api/v1/projects/{project}/collections/{name}/export` - **Streaming backup, including stored vectors.** Answers **NDJSON** (`application/x-ndjson`): one JSON object per line, so the LINE is the unit of recovery and a truncated download loses the last row rather than the file. First line `{type:'header', collection, snapshot_at, vector_dimension, vector_dtype, rows_at_snapshot, batch_rows_cap, max_stream_seconds, include_vectors, vector_format}` (`snapshot_at` is server epoch seconds - "as of when" is the first question anyone asks of a backup, and a filesystem mtime does not survive a copy); then `{type:'row', id, document, vector_state, vector|vector_b64}` per document - **the vector field is named `vector` (a JSON array) with `vector_format=array`, and `vector_b64` (base64 of float32-little-endian) with `vector_format=base64`.** Handle BOTH names: a consumer who read only `vector` and exported as base64 saw a row reporting `vector_state: present` with no `vector` key, which looks exactly like the data loss `vector_state` exists to report; then `{type:'trailer', rows_sent, last_id, complete, content_sha256}`. **`content_sha256` is over each row's id and its RAW VECTOR BYTES, not over the emitted text**, so it is IDENTICAL whichever `vector_format` you asked for - you can export as base64, restore, re-export as an array and still compare digests. It is omitted rather than empty if it could not be computed. **`format` is NOT the parameter name and is now refused** - it used to be ignored, so `?format=base64` silently produced the ARRAY export, which for 12448 rows at dim 4096 is roughly three times the bytes and looks like it worked. The name is `vector_format`.
|
|
|
**The exact construction, so you can recompute it rather than only echo it.** ONE rolling SHA-256 over every row in stream order, feeding exactly:
|
|
**The exact construction, so you can recompute it rather than only echo it.** ONE rolling SHA-256 over every row in stream order, feeding exactly:
|
|
|
`id` (UTF-8 bytes, not length-prefixed) || `0x1F` || the vector as float32 little-endian (ZERO bytes when the row has no vector) || `0x1E`
|
|
`id` (UTF-8 bytes, not length-prefixed) || `0x1F` || the vector as float32 little-endian (ZERO bytes when the row has no vector) || `0x1E`
|
|
|
The two separators are load-bearing: without them `"ab"+"c"` and `"a"+"bc"` would hash alike. It is NOT a hash per row combined afterwards, and it is NOT over the vector alone.
|
|
The two separators are load-bearing: without them `"ab"+"c"` and `"a"+"bc"` would hash alike. It is NOT a hash per row combined afterwards, and it is NOT over the vector alone.
|
|
@@ -129,6 +129,14 @@ Example: `?filter=age:gte:30&filter=name:eq:Alice`.
|
|
|
|
|
|
|
|
Additional query params: `limit` (default 20), `offset` (default 0), `sort` (field name), `desc` (bool).
|
|
Additional query params: `limit` (default 20), `offset` (default 0), `sort` (field name), `desc` (bool).
|
|
|
|
|
|
|
|
|
|
+**EVERY LISTING ROUTE NOW REFUSES A PARAMETER IT CANNOT HONOUR (422 `unknown_option`), AND THE RULE IS DERIVABLE RATHER THAN A LIST OF NAMES.** If a route implements a parameter it accepts it; if it does not, it says so instead of answering 200 with the parameter ignored. So `limit`, `offset`, `sort` and `desc` are correct HERE, because this route implements all four - and the same names are refused on routes that do not. The error names what you sent, lists what the route accepts, and carries `details.unsupported` (the names) plus `details.instead` (a map to the right name on THIS route, when there is one).
|
|
|
|
|
+
|
|
|
|
|
+Two things worth knowing before you adapt:
|
|
|
|
|
+- **An INCIDENTAL parameter is still ignored, deliberately.** A cache-buster, a proxy's addition, `_=<timestamp>`, `utm_*` - none of those ask for behaviour, so refusing them would be a regression rather than a fix. What is refused is the set a caller plausibly sends EXPECTING AN EFFECT.
|
|
|
|
|
+- **The names refused on each route are mostly OUR OWN other routes' spellings**, because that is where the real confusion comes from: `/documents` takes `sort`+`desc=true`, the index-values route takes `order=desc`, `/collections` searches with `q` while `/documents` filters with `filter`, and the export takes `vector_format` where `format` is the obvious guess. Each route therefore refuses the sibling spellings and `details.instead` names the local one.
|
|
|
|
|
+
|
|
|
|
|
+Per route: `/documents` accepts `filter`, `limit`, `offset`, `sort`, `desc`. `/collections` accepts `q`, `sort`, `desc` and is **not paginated**. `/files` accepts `limit`, `offset` only (fixed newest-first order, no search). The export accepts `include_vectors`, `vector_format`, `after_id`, `batch_rows` and **cannot export a subset**. A function's `/logs` accepts `limit` only - there is **no** `status` filter, so a request for just the failures would otherwise have returned runs of every outcome. `/schema/suggest` accepts `sample_limit` only.
|
|
|
|
|
+
|
|
|
## Collection schema (needs database 2.16.0+)
|
|
## Collection schema (needs database 2.16.0+)
|
|
|
|
|
|
|
|
An OPTIONAL per-collection JSON Schema, validated on every write. All four routes answer **501** `server_unsupported` against an older database - not 503, because no amount of retrying upgrades a database, and not 422, because the request is valid and there is nothing in the body to fix. Read `has_schema` on the collection GET to know whether one is set; it is OMITTED there when the database is too old, so absent means "cannot be determined", never "no schema".
|
|
An OPTIONAL per-collection JSON Schema, validated on every write. All four routes answer **501** `server_unsupported` against an older database - not 503, because no amount of retrying upgrades a database, and not 422, because the request is valid and there is nothing in the body to fix. Read `has_schema` on the collection GET to know whether one is set; it is OMITTED there when the database is too old, so absent means "cannot be determined", never "no schema".
|
|
@@ -237,7 +245,8 @@ Small named binary assets per project, so everything customer-specific (a logo,
|
|
|
- `PUT /api/v1/projects/{project}/files/{name}` - Store the **raw request body** under `name`, taking the content type from the `Content-Type` header (default `application/octet-stream`). Not base64 and not a JSON wrapper: a file is bytes. **201** for a new name, **200** for a replacement, and a replacement makes the old bytes unreadable. Answers `{name, content_type, size, checksum, created_at}`. An empty body is **422**; over the size cap is **422** `file_too_large` (default **2 MiB**, `max_file_bytes` in the global settings).
|
|
- `PUT /api/v1/projects/{project}/files/{name}` - Store the **raw request body** under `name`, taking the content type from the `Content-Type` header (default `application/octet-stream`). Not base64 and not a JSON wrapper: a file is bytes. **201** for a new name, **200** for a replacement, and a replacement makes the old bytes unreadable. Answers `{name, content_type, size, checksum, created_at}`. An empty body is **422**; over the size cap is **422** `file_too_large` (default **2 MiB**, `max_file_bytes` in the global settings).
|
|
|
- `GET /api/v1/projects/{project}/files/{name}` - The bytes, with the stored content type, plus `X-File-Checksum` and a `Content-Disposition` naming the file. **404** when there is no such file.
|
|
- `GET /api/v1/projects/{project}/files/{name}` - The bytes, with the stored content type, plus `X-File-Checksum` and a `Content-Disposition` naming the file. **404** when there is no such file.
|
|
|
- `GET /api/v1/projects/{project}/files/{name}/info` - Metadata only, without moving the bytes.
|
|
- `GET /api/v1/projects/{project}/files/{name}/info` - Metadata only, without moving the bytes.
|
|
|
-- `GET /api/v1/projects/{project}/files` - `{files:[{name, content_type, size, checksum, created_at}]}`, newest first. `limit` (1-1000, default 100, clamped rather than refused) and `offset`.
|
|
|
|
|
|
|
+- `GET /api/v1/projects/{project}/files` - `{files:[{name, content_type, size, checksum, created_at}], has_more, total}`, newest first. `limit` (1-1000, default 100, clamped rather than refused) and `offset`.
|
|
|
|
|
+ **`has_more` and `total` are ALWAYS present**, true or false, so an absent `has_more` means exactly one thing - a server older than this release - and never "that was everything". They come from the database and were previously discarded, which left a full page and the last page looking identical. `sort`, `order`, `q` and the rest are **refused 422**: the order is fixed and there is no search, so fetch a known file at `/files/{name}` instead. Note the newest-first order is applied WITHIN a page, so it is not a stable global ordering to page through.
|
|
|
- `DELETE /api/v1/projects/{project}/files/{name}` - **404** when absent. Safe against content dedup: identical bytes stored under two names share storage and are reference-counted, so deleting one name leaves the other readable.
|
|
- `DELETE /api/v1/projects/{project}/files/{name}` - **404** when absent. Safe against content dedup: identical bytes stored under two names share storage and are reference-counted, so deleting one name leaves the other readable.
|
|
|
- **A file name is an identifier, not a label.** Letters, digits, `.`, `-` and `_`, at most 128 characters, no leading `.`, no `..`, no path separator and no `:`. A bad name is **422** with the reason, never 404 - the name is unusable rather than missing, and a caller told "not found" would retry a name that can never work.
|
|
- **A file name is an identifier, not a label.** Letters, digits, `.`, `-` and `_`, at most 128 characters, no leading `.`, no `..`, no path separator and no `:`. A bad name is **422** with the reason, never 404 - the name is unusable rather than missing, and a caller told "not found" would retry a name that can never work.
|
|
|
- **Deleting a project deletes its files**, so a recycled project name does not inherit the previous tenant's assets.
|
|
- **Deleting a project deletes its files**, so a recycled project name does not inherit the previous tenant's assets.
|