Updating Vectors
1. Updating Vector Values
Example: Update Values
index.update(
id="doc1",
values=[0.11, 0.22, ...], # new dense vector
)
Note: An upsert with same ID also replaces values; update() only changes the specified fields.
index.update(
id="doc1",
set_metadata={"status": "archived", "version": 3},
)
| Param | Behavior |
set_metadata | Merges with existing metadata (partial update) |
| Upsert with metadata | Replaces entire metadata object |
3. Updating Sparse Values
Example: Update Sparse
index.update(
id="doc1",
sparse_values={"indices": [1, 7, 42], "values": [0.5, 0.3, 0.2]},
)
4. Updating in Specific Namespace
Example: Namespaced Update
index.update(id="u1", set_metadata={"plan": "pro"}, namespace="users")
| Behavior | Detail |
| Wrong namespace | No-op (no error) |
| Default | "" |
| Operation | Result |
set_metadata={"k": v} | Adds or overwrites key k |
| Other keys | Preserved unchanged |
| Delete a key | Not supported; re-upsert vector without it |
Example: Full Replace via Upsert
index.upsert(vectors=[{
"id": "doc1",
"values": existing_values,
"metadata": {"status": "final"}, # replaces all metadata
}])
7. Updating Multiple Vectors
Example: Batch Update via Upsert
updates = [
{"id": v["id"], "values": v["values"], "metadata": v["metadata"]}
for v in updated_vectors
]
index.upsert(vectors=updates)
Note: update() only handles one ID at a time. For bulk changes, prefer batched upsert.
8. Validating Update Operations
Example: Verify Update
index.update(id="d1", set_metadata={"v": 2})
got = index.fetch(ids=["d1"])
assert got["vectors"]["d1"]["metadata"]["v"] == 2
9. Handling Update Conflicts
| Scenario | Strategy |
| Concurrent updates | Last write wins; use version field |
| Race with delete | Idempotent: update on missing = no-op |
| Optimistic concurrency | Check version metadata before write |
| Tip | Effect |
| Batch via upsert | 1 call vs N update calls |
| Partial metadata only | Avoid re-uploading values |
| Parallel async | Use thread/worker pool |
| Group by namespace | Better connection reuse |