Update Documents
Use update() to modify existing documents (Doc).
Only the scalar fields and vector embeddings you include will be updated; all other content remains unchanged.
The method accepts either a single Doc object or a list of Doc objects.
Document Doc
Each Doc passed to update() must:
- Specify an
idthat already exists in the collection (the operation will fail if the document is not found) - Include only the fields and vectors you intend to update, formatted according to the collection's schema:
- Scalar fields go in the
fieldsdictionary (field names as keys) - Vector embeddings go in the
vectorsdictionary (vector names as keys)
- Scalar fields go in the
- Omit any scalar fields or vectors you do not want to change — they will be left untouched.
Update a Single Document
Assume you already have a collection with the following schema:
- Scalar fields:
book_title(string)category(array of strings)publish_year(32-bit integer)
- Vector embeddings:
dense_embedding: a 768-dimensional dense vectorsparse_embedding: a sparse vector
To update an existing document, provide its id and only the fields or vectors you want to change:
import zvec
doc = zvec.Doc(
id="book_1", # ← must already exist in the collection
vectors={
"sparse_embedding": { # ← replaces entire sparse vector
35: 0.25,
237: 0.1,
369: 0.44,
},
},
fields={
"category": [ # ← replaces current category list
"Romance",
"Classic Literature",
"American Civil War",
],
},
# Note: `book_title`, `publish_year`, and `dense_embedding` are omitted → they stay as-is
)
# Update the document
result = collection.update(doc)
print(result) # {"code": 0} means successThe update() method returns a single Status object for one document.
{"code": 0}indicates success.- Non-zero codes indicate failure.
Successfully updated documents are immediately available for querying 🚀.
Update a Batch of Documents
To update multiple documents at once, pass a list of Doc objects to update().
Each Doc is processed independently, and the method returns a list of Status objects — one per document.
import zvec
results = collection.update(
[
zvec.Doc(
id="book_1",
vectors={
"sparse_embedding": {35: 0.25, 237: 0.1, 369: 0.44},
},
fields={
"category": ["Romance", "Classic Literature", "American Civil War"],
},
),
zvec.Doc(
id="book_2",
fields={
"book_title": "The Great Gatsby",
},
),
zvec.Doc(
id="book_3",
fields={
"book_title": "A Tale of Two Cities",
"publish_year": 1859,
},
),
]
)
print(results) # [{"code":0}, {"code":0}, {"code":0}]A failure in one document (e.g., the id doesn't exist ) does not stop the others from being updated.
🔍 Always check each Status in the result list.