/vectors/{collection}/upsertUpsert Vectors
Upsert vectors. (Data, Queries & Vectors) POST /@:projectSlug/vectors/{collection}/upsert.
| collection * | path | The derived collection's name. It starts with |
| projectSlug * | path | The project's slug: the path segment after It is unique within the org. |
| rows * | object[] | The chunks to write, 1 to 1,000 per request, all with the same vector dimension. |
| id | string | The chunk's id. An existing id is overwritten (every column replaced). Omitted: a new |
| vector * | number[] | The pre-computed embedding. Every row in the request, and every row already in the collection, must have the same dimension: the first upsert fixes it. |
| _source * | object | Where the chunk came from. Stored as sent and returned by search; filter on it with |
| handle * | string | An opaque handle for the source document the chunk came from. |
| chunkIndex * | integer | The chunk's position within its source, from 0. |
| text | string | The chunk's source text, returned by search. On a per-subject collection it is encrypted at rest under the subject's key. Never filterable. |
| metadata | object | Your own filter keys for the chunk, stored as a JSON object (default Keys are yours; values may be any JSON value. Only keys made of letters, digits and A There is no per-key or per-object limit beyond the 2 MiB request size; don't put source text here (use |
| subjectIds | string[] | The end user ( Required on a per-subject collection (400 An end user calling for themselves must name themselves. |
| HTTP | K9O Code | Description |
|---|---|---|
| 200 | Success | |
| 400 | K9O_INVALID_FIELD_VALUE | The project identifier in the request path is not valid. |
| 400 | K9O_INVALID_VECTOR_DIMENSION | All vectors in a single upsert batch must share the same dimension as the first row. |
| 400 | K9O_VECTOR_SUBJECT_ATTRIBUTION_FORBIDDEN | This collection is declared residencyClass='shared' (no data subject), so rows must not carry subjectIds; remove them or declare the collection per-subject. |
| 400 | K9O_VECTOR_SUBJECT_ATTRIBUTION_REQUIRED | Each vector row must carry subjectIds identifying the content-subject the chunk derives from, so it can later be sealed and erased. |
| 403 | K9O_RESERVED_COLUMN_WRITE_PROHIBITED | Vector upserts are only allowed into an extension's own '_'-prefixed derived collection; this collection name is not one. |
| 403 | K9O_IAM_POLICY_DENIED | The caller's project role can read vector data but not change it (reason read_only_role): only admin, editor, member and author roles write, as for storage objects. |
| 409 | K9O_BYOK_REGION_MISMATCH | A chunk belongs to a data subject, and the project's customer-managed key does not cover the region it is written in. Nothing was written, and the chunk text is never sealed under a platform key. |
| 503 | K9O_KEY_SERVICE_UNAVAILABLE | The keyed content hash for the chunks couldn't be computed, so nothing was written (context.reason content_hash_unavailable). Retry shortly. |
| data * | object | What the upsert wrote. |
| upserted * | integer | How many chunks were written (inserted or overwritten): the number of rows sent. |
| rows * | object[] | One entry per row sent, in the order sent. |
| id * | string | The chunk's id: the one sent, or the |
| contentHash * | any | A keyed hash of the chunk's It is the same for the same text in the same collection, so a caller can skip re-embedding a chunk whose hash is unchanged, and it can't be compared across collections or projects. Null when the chunk has no Filterable as |
| One of: string | ||
| or: null | ||
| collection * | string | The derived collection written. It is created on the first upsert. |
| meta * | any | Request metadata: request id, trace id, timing and cost. |
// const k9o = new K9o({ orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…' })
const { data } = await k9o.vectors.upsert('<collection>', {})Showing example in TypeScript
{
"rows": [
{
"id": "string",
"vector": [
0
],
"_source": {
"handle": "string",
"chunkIndex": 0
},
"text": "string",
"subjectIds": [
"string"
]
}
]
}{
"data": {
"upserted": 0,
"rows": [
{
"id": "string",
"contentHash": "string"
}
],
"collection": "string"
}
}