Deleting Vectors

1. Deleting Vectors by ID

Example: Delete by IDs

index.delete(ids=["doc1", "doc2"], namespace="docs")
ParamDescription
idsList of IDs to delete (up to 1000)
namespaceTarget namespace (default "")
filterMetadata filter (pod only)
delete_allWipe namespace

2. Deleting by Metadata Filter

Example: Delete by Filter

index.delete(filter={"source": {"$eq": "archive"}}, namespace="docs")
Warning: Filter-based delete is supported on pod indexes only. For serverless, query+collect IDs, then delete by ID.

3. Deleting All Vectors in Namespace

Example: Wipe Namespace

index.delete(delete_all=True, namespace="temp")
EffectDetail
Removes all vectorsNamespace remains (empty)
IrreversibleNo undo

4. Deleting Entire Namespace

Example: Delete Namespace

index.delete_namespace("temp")  # serverless v5+
MethodBehavior
delete_namespaceRemoves namespace entirely (serverless)
delete(delete_all=True)Empties namespace

5. Batch Deleting Vectors

Example: Chunked Delete

for i in range(0, len(ids), 1000):
    index.delete(ids=ids[i:i+1000])

6. Verifying Deletion Success

Example: Verify

index.delete(ids=["d1"])
res = index.fetch(ids=["d1"])
assert "d1" not in res["vectors"]
Note: Deletes are eventually consistent. Wait briefly before verifying or use stats.

7. Handling Delete Failures

ErrorAction
404 Index missingConfirm index name
400 Empty IDsAdd at least one ID or use delete_all
429Backoff and retry

8. Implementing Soft Deletes

Example: Soft Delete via Metadata

index.update(id="d1", set_metadata={"deleted": True})
# Filter out at query time:
res = index.query(vector=qv, top_k=10, filter={"deleted": {"$ne": True}})
ApproachTradeoff
Soft deleteRecoverable, but still stored/billed
Hard deleteImmediate cost reduction, irreversible

9. Scheduling Automated Deletions

Example: TTL Job (Python)

# Cron: nightly
cutoff = int(time.time()) - 30 * 86400
# Query stale, collect IDs, delete in batches
stale = index.query(vector=[0]*1536, top_k=10000,
                    filter={"ts": {"$lt": cutoff}})
ids = [m["id"] for m in stale["matches"]]
index.delete(ids=ids)

10. Understanding Deletion Performance

OperationSpeed
Delete by ID (1000)~50–200 ms
Delete by filterO(matches); slower
delete_allNear-instant
Eventual consistency1–2 s typical