Updating Vectors
1. Updating Vector Values
Note: An upsert with same ID also replaces values;
update() only changes the specified fields.2. Updating Vector Metadata
| 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
| Behavior | Detail |
|---|---|
| Wrong namespace | No-op (no error) |
| Default | "" |
5. Performing Partial Metadata Updates
| 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 |
6. Replacing Full Metadata
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 |
10. Optimizing Update Performance
| 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 |