Skip to main content

upsertFromVectors

Inserts or updates vectors from an array of vectors.

upsertFromVectors(
data: {
vectors: number[]
id?: string
metadata?: Record<string, any>
}[]
): Promise<string[]>;

Reference

import { myVectorStore } from "#elements";
export default async function () {
const count = await myVectorStore.upsertFromVectors([
{ vectors: Array(1536).fill(0.5), id: "1", metadata: { key: "value" } },
{ vectors: Array(1536).fill(0.3) },
]);
console.log(`${count} vectors upserted`);
}

Parameters

  • data: An array of objects, each containing a vector, an optional ID, and optional metadata.
    • vectors: The vector.
    • id: (Optional) The ID of the vector. If not provided, a new ID will be generated.
    • metadata: (Optional) The metadata of the vector.

Returns

Promise of an array of IDs of the upserted vectors.

Caveats

  • This method will insert a new vector if the ID does not exist, or update the existing vector if the ID exists.
  • The length of the inserted vector should be ensured to match the Dimensions value set for the VectorStore Element.

Examples