AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

`Chroma.Update_document()` Fails When `Document` Metadata Is Omitted

Calling `update_document()` on a `Chroma` vector store with a `Document` that does not explicitly provide metadata raises a `ValueError` because the empty metadata dictionary is rejected by the Chroma update API. This breaks consistency with `add_documents()`, which accepts documents with empty metadata.

highConfidence 85%Langchain-ChromaAffected V1.1.0

Origin Analysis

The `update_documents()` method in `langchain_chroma/vectorstores.py` forwards the document's `metadata` attribute directly to Chroma's `update()` method without normalizing empty dictionaries. Chroma's update API enforces that metadata must be a non-empty dict, so passing an empty dict (`{}`) triggers a validation error.
1. Create a `Chroma` instance with an embedding function. 2. Add a document with `Document(page_content='Original document')` and an ID using `add_documents()`. 3. Attempt to update the same document with `update_document(document_id='doc_1', document=Document(page_content='Updated document'))`. 4. Observe the `ValueError`.

Fixing Code Block

Edge Case Audit

This workaround introduces a semantic change: documents updated with empty metadata will retain their previous metadata rather than having it cleared. It also uses two separate update calls, which are not atomic; if the second call fails, the document text may be updated but the metadata not, creating an inconsistent state. Users should consider rolling back to a direct single update call once Chroma supports empty metadata dicts. Additionally, future Chroma versions might change the validation behavior, so pinning the Chroma version is advised until a native fix is available.

Ecosystem Topology