You can easily delete vectors from our vector database, ensuring your data remains organized and up-to-date.

Our SDK allows you to delete vector data from indexes and/or namespaces.

Delete

Every vector in our database has an ID defined by you. This ID is used to reference the vectors you want to delete.

We’ll use the delete() method to instruct the SDK to delete vectors 1, 2, and 3, as shown below:

use Upstash\Vector\Index;

$index = new Index(
  url: "<UPSTASH_VECTOR_REST_URL>",
  token: "<UPSTASH_VECTOR_REST_TOKEN>",
);

$index->delete(['1', '2', '3']);

Delete using ID prefixes

In the case that you logically group your vectors by a common prefix, you can delete all those vectors at once using the code below:

use Upstash\Vector\Index;
use Upstash\Vector\VectorDeleteByPrefix;

$index = new Index(
  url: "<UPSTASH_VECTOR_REST_URL>",
  token: "<UPSTASH_VECTOR_REST_TOKEN>",
);

$index->delete(new VectorDeleteByPrefix(
  prefix: 'users:',
));

Delete using a metadata filter

If you want to delete vectors based on some query result over the metadata, you can use the VectorDeleteByMetadataFilter class as shown below:

use Upstash\Vector\Index;
use Upstash\Vector\VectorDeleteByMetadataFilter;

$index = new Index(
  url: "<UPSTASH_VECTOR_REST_URL>",
  token: "<UPSTASH_VECTOR_REST_TOKEN>",
);

$index->delete(new VectorDeleteByMetadataFilter(
  filter: 'salary > 1000',
));

You can read more about Namespaces on our docs.