Repository navigation
fix: distinguish empty document content IDs - #13235
daleselaji-dev wants to merge 1 commit into
Conversation
|
@daleselaji-dev is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
|
|
|
Hi @daleselaji-dev, thanks a lot for your contribution! 🙏 We noticed that the Contributor License Agreement (CLA) check ( To get your PR reviewed, please sign the CLA via the link in the |
|
Thanks for the PR! We've decided not to change this behavior since it would change the auto-generated IDs of existing documents with empty content. See #13234 for details. Closing. |
Problem
Document(content="")andDocument(content=None)currently receive the same automatic ID. This can raise a misleading duplicate error for a same-batch write and can silently violate ID uniqueness across separate writes.Root Cause
Document._create_id()normalizesself.contentwithself.content or None, collapsing the valid empty string intoNonebefore hashing.Solution
Hash the validated content value directly so an empty string remains distinct from
None.Changes
Nonecontent produce different IDs.Testing
PYTHONUTF8=1 PYTHONIOENCODING=utf-8 uvx hatch run test:unit test/dataclasses/test_document.py— 38 passed.PYTHONUTF8=1 PYTHONIOENCODING=utf-8 uvx hatch run test:unit test/document_stores/test_in_memory.py— 370 passed, 8 skipped.PYTHONUTF8=1 PYTHONIOENCODING=utf-8 uvx hatch run fmt-check haystack/dataclasses/document.py test/dataclasses/test_document.py— passed.PYTHONUTF8=1 PYTHONIOENCODING=utf-8 uvx hatch run test:types haystack/dataclasses/document.py test/dataclasses/test_document.py— passed.git diff --check— passed.Compatibility/Risk
Automatic IDs for documents whose content is exactly
""will change. IDs forNonecontent and other content values remain unchanged. Persisted stores containing empty-string documents may need an ID migration or re-write.Notes for Reviewer
The implementation intentionally changes only the falsey-content normalization in
_create_id; metadata and other ID inputs retain their existing serialization behavior. The change was verified on the currentmainsnapshot and includes AI-assisted development disclosure per the repository contribution guide.Linked Issue
Fixes #13234