Adds new vectors to the encrypted index or updates existing vectors if they have the same ID. This operation supports two distinct calling patterns for maximum flexibility.
async upsert({ items?: VectorItem[], // Pattern 1: Provide items array ids?: string[], // Pattern 2: Provide ids and vectors together vectors?: number[][], // Pattern 2: Provide ids and vectors together metadata?: (Record<string, unknown> | null)[], // Pattern 2: Optional metadata per vector contents?: (string | null)[] // Pattern 2: Optional contents per vector}): Promise<UpsertResponse>// Note: Must provide either 'items' OR both 'ids' and 'vectors'
Each VectorItem must contain an id and vector, with optional fields:
Field
Type
Required
Description
id
string
Yes
Unique identifier for the vector item
vector
number[]
Yes*
The vector representation. *Required unless contents is provided (for auto-embedding via embedding model)
contents
string | Buffer
Optional
Content associated with the vector (accepts both strings and bytes, encoded to bytes and encrypted before storage)
metadata
object
Optional
Additional structured data associated with the vector
The contents field accepts both strings and Buffers. All contents are encoded to bytes and encrypted before storage, and will be returned as decoded UTF-8 strings when retrieved with get().
Promise<UpsertResponse>: A Promise that resolves to a response object containing the operation status, message, and count of upserted vectors. See the UpsertResponse type for more details.
For large batches, pack vectors into a single Float32Array and pass it as vectors. The SDK detects the typed array and uses an optimized binary transfer (no per-vector JSON encoding), which substantially reduces wire size and CPU on both ends.
const dim = 384;const ids = ['vec1', 'vec2', 'vec3'];// Flat, contiguous buffer — vectors laid out back-to-backconst flat = new Float32Array(ids.length * dim);for (let i = 0; i < ids.length; i++) { for (let j = 0; j < dim; j++) { flat[i * dim + j] = Math.random(); }}const result = await index.upsert({ ids, vectors: flat });console.log(`Upserted ${result.upsertedCount} vectors via binary transfer`);
Use Float32Array whenever you already have vectors in a typed buffer (e.g. from a model output, an ArrayBuffer over a socket, or an embedding library that exposes Float32Array directly). Avoid the cost of converting back to number[][].