How to Update and Delete Vectors

Last verified 13 Jul 2026

DigitalOcean Managed OpenSearch for vector search uses the same managed OpenSearch engine available under Managed Databases. It bundles the k-NN, ML Commons, and Neural Search plugins for vector similarity search, hybrid vector and keyword search, and remote embedding models.

OpenSearch stores vector embeddings as fields on documents. To update or delete a vector, update or delete the document that contains the vector field.

Before you update or delete vectors, create a k-NN index, index vectors, and make sure you have set your environment variables and verified the connection.

To manage your indexed vectors, first go to the Vector Databases page and select the cluster you want to use.

Vector Databases overview page listing OpenSearch and PostgreSQL vector database clusters.

Then, go to the Network Access tab, find the trusted source you want to connect to, and then open a terminal session.

Network Access tab showing trusted source entries and an Add Trusted Sources button.

Update a Vector

Use the document indexing API to replace a document, including its vector field. The new embedding array must match the dimension configured for the knn_vector field in the index mapping.

For example, the following request replaces the document with the ID doc-1 in the documents index:

curl -X PUT "$OS/documents/_doc/doc-1" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Updated OpenSearch vector search guide",
    "body": "OpenSearch stores and searches vector embeddings in knn_vector fields.",
    "source": "docs",
    "embedding": [0.0223, -0.0356, 0.0689, "..."]
  }'

This example assumes you already initialized an OpenSearch client named client.

Use Python when your application regenerates embeddings before updating documents:

client.index(
    index="documents",
    id="doc-1",
    body={
        "title": "Updated OpenSearch vector search guide",
        "body": "OpenSearch stores and searches vector embeddings in knn_vector fields.",
        "source": "docs",
        "embedding": embed_one("Updated OpenSearch vector search guide"),
    },
)

In this example, embed_one() represents your application’s embedding function. Replace it with the function or API call you use to generate embeddings.

This replaces the full document. Include every field you want to keep, not only the fields you want to change.

Update Only Metadata

Use _update when you need to change metadata without replacing the vector field. This keeps the existing embedding value.

curl -X POST "$OS/documents/_update/doc-1" \
  -H "Content-Type: application/json" \
  -d '{
    "doc": {
      "source": "docs",
      "updated_at": "2026-05-19T00:00:00Z"
    }
  }'

This example assumes you already initialized an OpenSearch client named client.

client.update(
    index="documents",
    id="doc-1",
    body={
        "doc": {
            "source": "docs",
            "updated_at": "2026-05-19T00:00:00Z",
        }
    },
)

This updates only the fields in doc and keeps the existing embedding value.

Delete a Vector

To delete a vector, delete the document that contains it.

curl -X DELETE "$OS/documents/_doc/doc-1"

This example assumes you already initialized an OpenSearch client named client.

client.delete(
    index="documents",
    id="doc-1",
)

OpenSearch removes the document and its embedding field from the index.

Delete Multiple Documents

Use _delete_by_query when you need to delete multiple documents that match a filter.

curl -X POST "$OS/documents/_delete_by_query" \
  -H "Content-Type: application/json" \
  -d '{
    "query": {
      "term": {
        "source": "old-docs"
      }
    }
  }'

This example assumes you already initialized an OpenSearch client named client.

client.delete_by_query(
    index="documents",
    body={
        "query": {
            "term": {
                "source": "old-docs"
            }
        }
    },
)

Use _delete_by_query carefully. It deletes all matching documents from the index.

Verify Updates and Deletes

After updating or deleting documents, query the document ID to confirm the change.

curl "$OS/documents/_doc/doc-1"

This example assumes you already initialized an OpenSearch client named client.

client.get(
    index="documents",
    id="doc-1",
)

To count documents in the index, run:

curl "$OS/documents/_count"

This example assumes you already initialized an OpenSearch client named client.

client.count(
    index="documents",
)

OpenSearch may not make updates or deletes visible immediately. Visibility depends on the index’s refresh_interval.

After you update or delete vectors, query vectors to confirm your search results behave as expected.

We can't find any results for your search.

Try using different keywords or simplifying your search terms.