update_document
Modify and update content or metadata of an existing document in the Chroma vector database using a specified document ID.
Instructions
Update an existing document in the Chroma vector database
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | ||
| document_id | Yes | ||
| metadata | No |
Implementation Reference
- src/chroma/server.py:450-495 (handler)The main handler function that executes the update_document tool. It validates inputs, checks if the document exists, processes metadata, calls collection.update(), and returns success message. Wrapped with retry decorator.async def handle_update_document(arguments: dict) -> list[types.TextContent]: """Handle document update with retry logic""" doc_id = arguments.get("document_id") content = arguments.get("content") metadata = arguments.get("metadata") if not doc_id or not content: raise DocumentOperationError("Missing document_id or content") logger.info(f"Updating document: {doc_id}") try: # Check if document exists existing = collection.get(ids=[doc_id]) if not existing or not existing.get('ids'): raise DocumentOperationError(f"Document not found [id={doc_id}]") # Update document if metadata: # Keep numeric values in metadata processed_metadata = { k: v if isinstance(v, (int, float)) else str(v) for k, v in metadata.items() } collection.update( ids=[doc_id], documents=[content], metadatas=[processed_metadata] ) else: collection.update( ids=[doc_id], documents=[content] ) logger.info(f"Successfully updated document: {doc_id}") return [ types.TextContent( type="text", text=f"Updated document '{doc_id}' successfully" ) ] except Exception as e: raise DocumentOperationError(str(e))
- src/chroma/server.py:271-282 (schema)Input schema definition for the update_document tool, defining parameters: document_id (required string), content (required string), metadata (optional object). Used in tool registration.inputSchema={ "type": "object", "properties": { "document_id": {"type": "string"}, "content": {"type": "string"}, "metadata": { "type": "object", "additionalProperties": True } }, "required": ["document_id", "content"] }
- src/chroma/server.py:335-336 (registration)Tool dispatch registration in the @server.call_tool() handler, routing 'update_document' calls to handle_update_document.elif name == "update_document": return await handle_update_document(arguments)
- src/chroma/server.py:268-282 (registration)Tool registration in @server.list_tools(), defining name, description, and inputSchema for update_document.types.Tool( name="update_document", description="Update an existing document in the Chroma vector database", inputSchema={ "type": "object", "properties": { "document_id": {"type": "string"}, "content": {"type": "string"}, "metadata": { "type": "object", "additionalProperties": True } }, "required": ["document_id", "content"] }
- src/chroma/server.py:156-164 (schema)Additional schema in server.command_options for update_document input validation."update_document": { "type": "object", "properties": { "document_id": {"type": "string"}, "content": {"type": "string"}, "metadata": {"type": "object", "additionalProperties": True} }, "required": ["document_id", "content"] },