Deleting Vectors
1. Deleting Vectors by ID
| Param | Description |
|---|---|
ids | List of IDs to delete (up to 1000) |
namespace | Target namespace (default "") |
filter | Metadata filter (pod only) |
delete_all | Wipe namespace |
2. Deleting by Metadata Filter
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
| Effect | Detail |
|---|---|
| Removes all vectors | Namespace remains (empty) |
| Irreversible | No undo |
4. Deleting Entire Namespace
| Method | Behavior |
|---|---|
delete_namespace | Removes namespace entirely (serverless) |
delete(delete_all=True) | Empties namespace |
5. Batch Deleting Vectors
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
| Error | Action |
|---|---|
| 404 Index missing | Confirm index name |
| 400 Empty IDs | Add at least one ID or use delete_all |
| 429 | Backoff 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}})
| Approach | Tradeoff |
|---|---|
| Soft delete | Recoverable, but still stored/billed |
| Hard delete | Immediate 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
| Operation | Speed |
|---|---|
| Delete by ID (1000) | ~50–200 ms |
| Delete by filter | O(matches); slower |
delete_all | Near-instant |
| Eventual consistency | 1–2 s typical |