Skip to main content
Used to add new vectors or update an existing vector.
You can only upsert vectors with same dimension count(size) as your index.

Arguments

There are two ways to use the upsert method. You can either create the vectors on your own and pass them directly. Or you can pass the data and create the embeddings using Upstash Embedding. The possible payloads are:
VectorPayload
Vector | Vector[]
required
Namespace
{ namespace?: string }
Namespace to upsert to. If not set, default namespace is used.
OR
DataPayload
Data | Data[]
required
Namespace
{ namespace?: string }
Namespace to upsert to. If not set, default namespace is used.

Response

'Success' on successful operation.
await index.upsert({
  id: "1234",
  vector: [0.1, 0.2, 0.3, 0.4, 0.5],
  metadata: {
    title: "Lord of The Rings",
    genre: "drama",
    category: "classic",
  },
});
await index.upsert([
  {
    id: "6789",
    vector: [0.6, 0.7, 0.8, 0.9, 0.9],
  },
  {
    id: "1234",
    vector: [0.1, 0.2, 0.3, 0.4, 0.5],
    metadata: {
      title: "Lord of The Rings",
      genre: "drama",
      category: "classic",
    },
  },
]);
await index.upsert([
  {
    id: "6789",
    vector: [0.6, 0.7, 0.8, 0.9, 0.9],
  },
], { namespace: "my-namespace" });
await index.upsert({
	id: "1234",
	vector: [0.1, 0.2, 0.3, 0.4, 0.5]
	metadata: {
		title: "Redis"
	}
})

await index.update({
	id: "1234",
	metadata: {
		title: "QStash"
	}
})
await index.upsert({
  id: "1234",
  data: "'The Lord of the Rings' follows Frodo Baggins and his allies on a quest to destroy a powerful ring and save Middle-earth from the dark lord Sauron.",
  metadata: {
    title: "Lord of The Rings",
    genre: "drama",
    category: "classic",
  },
});
await index.upsert([
  {
    id: "6789",
    data: "'Harry Potter' follows the journey of a young wizard, Harry Potter, as he attends Hogwarts School of Witchcraft and Wizardry, forms deep friendships, and confronts the dark wizard Voldemort, who seeks immortality and domination over the magical world.",
  },
  {
    id: "1234",
    data: "'The Lord of the Rings' follows Frodo Baggins and his allies on a quest to destroy a powerful ring and save Middle-earth from the dark lord Sauron.",
    metadata: {
      title: "Lord of The Rings",
      genre: "drama",
      category: "classic",
    },
  },
]);
await index.upsert({
	id: "1234",
	data: "Upstash product"
	metadata: {
		title: "Redis"
	}
})

await index.upsert({
	id: "1234",
	metadata: {
		title: "QStash"
	}
})