chroma-haystack 5.1.0__tar.gz → 5.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/CHANGELOG.md +7 -0
  2. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/PKG-INFO +1 -1
  3. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/src/haystack_integrations/document_stores/chroma/document_store.py +29 -9
  4. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/tests/test_document_store.py +26 -0
  5. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/tests/test_document_store_async.py +13 -0
  6. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/.gitignore +0 -0
  7. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/LICENSE.txt +0 -0
  8. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/README.md +0 -0
  9. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/example/data/usr_01.txt +0 -0
  10. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/example/data/usr_02.txt +0 -0
  11. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/example/data/usr_03.txt +0 -0
  12. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/example/data/usr_04.txt +0 -0
  13. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/example/data/usr_05.txt +0 -0
  14. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/example/data/usr_06.txt +0 -0
  15. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/example/data/usr_07.txt +0 -0
  16. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/example/data/usr_08.txt +0 -0
  17. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/example/data/usr_09.txt +0 -0
  18. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/example/data/usr_10.txt +0 -0
  19. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/example/data/usr_11.txt +0 -0
  20. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/example/data/usr_12.txt +0 -0
  21. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/example/data/usr_20.txt +0 -0
  22. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/example/data/usr_21.txt +0 -0
  23. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/example/data/usr_22.txt +0 -0
  24. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/example/data/usr_23.txt +0 -0
  25. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/example/data/usr_24.txt +0 -0
  26. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/example/data/usr_25.txt +0 -0
  27. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/example/data/usr_26.txt +0 -0
  28. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/example/data/usr_27.txt +0 -0
  29. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/example/data/usr_28.txt +0 -0
  30. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/example/data/usr_29.txt +0 -0
  31. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/example/data/usr_30.txt +0 -0
  32. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/example/data/usr_31.txt +0 -0
  33. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/example/data/usr_32.txt +0 -0
  34. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/example/data/usr_40.txt +0 -0
  35. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/example/data/usr_41.txt +0 -0
  36. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/example/data/usr_42.txt +0 -0
  37. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/example/data/usr_43.txt +0 -0
  38. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/example/data/usr_44.txt +0 -0
  39. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/example/data/usr_45.txt +0 -0
  40. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/example/data/usr_46.txt +0 -0
  41. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/example/data/usr_50.txt +0 -0
  42. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/example/data/usr_51.txt +0 -0
  43. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/example/data/usr_52.txt +0 -0
  44. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/example/data/usr_90.txt +0 -0
  45. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/example/example.py +0 -0
  46. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/pydoc/config_docusaurus.yml +0 -0
  47. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/pyproject.toml +0 -0
  48. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/src/haystack_integrations/components/retrievers/chroma/__init__.py +0 -0
  49. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/src/haystack_integrations/components/retrievers/chroma/retriever.py +0 -0
  50. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/src/haystack_integrations/components/retrievers/py.typed +0 -0
  51. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/src/haystack_integrations/document_stores/chroma/__init__.py +0 -0
  52. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/src/haystack_integrations/document_stores/chroma/errors.py +0 -0
  53. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/src/haystack_integrations/document_stores/chroma/filters.py +0 -0
  54. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/src/haystack_integrations/document_stores/chroma/utils.py +0 -0
  55. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/src/haystack_integrations/document_stores/py.typed +0 -0
  56. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/tests/__init__.py +0 -0
  57. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/tests/conftest.py +0 -0
  58. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/tests/test_filters.py +0 -0
  59. {chroma_haystack-5.1.0 → chroma_haystack-5.1.1}/tests/test_retriever.py +0 -0
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [integrations/chroma-v5.1.0] - 2026-11-11
4
+
5
+ ### 🐛 Bug Fixes
6
+
7
+ - *(chroma)* Distinguish metadata ID filters from document IDs (#4124)
8
+
9
+
3
10
  ## [integrations/chroma-v5.0.0] - 2026-10-16
4
11
 
5
12
  ### ⚙️ CI
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: chroma-haystack
3
- Version: 5.1.0
3
+ Version: 5.1.1
4
4
  Project-URL: Documentation, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/chroma#readme
5
5
  Project-URL: Issues, https://github.com/deepset-ai/haystack-core-integrations/issues
6
6
  Project-URL: Source, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/chroma
@@ -610,13 +610,15 @@ class ChromaDocumentStore:
610
610
  How to handle documents whose `id` already exists in the store:
611
611
  - `NONE` (default): treated as `FAIL`.
612
612
  - `OVERWRITE`: replace the existing document.
613
- - `SKIP`: keep the existing document and skip the new one.
613
+ - `SKIP`: keep the existing document and skip the new one. An `id` repeated within
614
+ `documents` is written once.
614
615
  - `FAIL`: raise `DuplicateDocumentError`.
615
616
 
616
617
  :raises ValueError:
617
618
  When input is not valid.
618
619
  :raises DuplicateDocumentError:
619
- When `policy` is `FAIL` (or `NONE`) and any document `id` already exists.
620
+ When `policy` is `FAIL` (or `NONE`) and any document `id` already exists or is repeated
621
+ within `documents`.
620
622
 
621
623
  :returns:
622
624
  The number of documents written.
@@ -634,7 +636,8 @@ class ChromaDocumentStore:
634
636
  return 0
635
637
 
636
638
  if policy in (DuplicatePolicy.FAIL, DuplicatePolicy.SKIP):
637
- existing_ids = set(self._collection.get(ids=[p["ids"][0] for p in chroma_payloads])["ids"])
639
+ existing = self._collection.get(ids=list(dict.fromkeys(p["ids"][0] for p in chroma_payloads)))
640
+ existing_ids = set(existing["ids"])
638
641
  payloads_to_write = self._apply_duplicate_policy(chroma_payloads, existing_ids, policy)
639
642
  else:
640
643
  payloads_to_write = chroma_payloads
@@ -663,13 +666,15 @@ class ChromaDocumentStore:
663
666
  How to handle documents whose `id` already exists in the store:
664
667
  - `NONE` (default): treated as `FAIL`.
665
668
  - `OVERWRITE`: replace the existing document.
666
- - `SKIP`: keep the existing document and skip the new one.
669
+ - `SKIP`: keep the existing document and skip the new one. An `id` repeated within
670
+ `documents` is written once.
667
671
  - `FAIL`: raise `DuplicateDocumentError`.
668
672
 
669
673
  :raises ValueError:
670
674
  When input is not valid.
671
675
  :raises DuplicateDocumentError:
672
- When `policy` is `FAIL` (or `NONE`) and any document `id` already exists.
676
+ When `policy` is `FAIL` (or `NONE`) and any document `id` already exists or is repeated
677
+ within `documents`.
673
678
 
674
679
  :returns:
675
680
  The number of documents written.
@@ -687,7 +692,7 @@ class ChromaDocumentStore:
687
692
  return 0
688
693
 
689
694
  if policy in (DuplicatePolicy.FAIL, DuplicatePolicy.SKIP):
690
- existing = await self._async_collection.get(ids=[p["ids"][0] for p in chroma_payloads])
695
+ existing = await self._async_collection.get(ids=list(dict.fromkeys(p["ids"][0] for p in chroma_payloads)))
691
696
  existing_ids = set(existing["ids"])
692
697
  payloads_to_write = self._apply_duplicate_policy(chroma_payloads, existing_ids, policy)
693
698
  else:
@@ -707,14 +712,29 @@ class ChromaDocumentStore:
707
712
  existing_ids: set[str],
708
713
  policy: DuplicatePolicy,
709
714
  ) -> list[dict[str, Any]]:
715
+ # an id repeated within the batch counts as a duplicate of its first occurrence
716
+ seen = set(existing_ids)
710
717
  if policy == DuplicatePolicy.FAIL:
711
- duplicates = [p["ids"][0] for p in payloads if p["ids"][0] in existing_ids]
718
+ duplicates = []
719
+ for p in payloads:
720
+ doc_id = p["ids"][0]
721
+ if doc_id in seen:
722
+ duplicates.append(doc_id)
723
+ seen.add(doc_id)
712
724
  if duplicates:
713
- msg = f"Documents with ids {duplicates} already exist in the document store."
725
+ msg = (
726
+ f"Documents with ids {duplicates} already exist in the document store or are repeated in the batch."
727
+ )
714
728
  raise DuplicateDocumentError(msg)
715
729
  return payloads
716
730
  if policy == DuplicatePolicy.SKIP:
717
- return [p for p in payloads if p["ids"][0] not in existing_ids]
731
+ to_write = []
732
+ for p in payloads:
733
+ doc_id = p["ids"][0]
734
+ if doc_id not in seen:
735
+ to_write.append(p)
736
+ seen.add(doc_id)
737
+ return to_write
718
738
  return payloads
719
739
 
720
740
  def delete_documents(self, document_ids: list[str]) -> None:
@@ -10,6 +10,8 @@ from unittest import mock
10
10
  import pytest
11
11
  from chromadb.api.shared_system_client import SharedSystemClient
12
12
  from haystack.dataclasses import ByteStream, Document, SparseEmbedding
13
+ from haystack.document_stores.errors import DuplicateDocumentError
14
+ from haystack.document_stores.types import DuplicatePolicy
13
15
  from haystack.testing.document_store import (
14
16
  TEST_EMBEDDING_1,
15
17
  CountDocumentsByFilterTest,
@@ -714,6 +716,30 @@ class TestDocumentStore(
714
716
  assert len(result_empty_filters) == 1
715
717
  assert len(result_empty_filters[0]) == 2
716
718
 
719
+ def test_write_documents_skip_drops_ids_repeated_in_the_batch(self, document_store: ChromaDocumentStore):
720
+ docs = [Document(content="refund policy"), Document(content="shipping"), Document(content="refund policy")]
721
+
722
+ assert document_store.write_documents(docs, policy=DuplicatePolicy.SKIP) == 2
723
+ assert document_store.count_documents() == 2
724
+
725
+ @pytest.mark.parametrize("policy", [DuplicatePolicy.FAIL, DuplicatePolicy.NONE])
726
+ def test_write_documents_fail_raises_on_ids_repeated_in_the_batch(
727
+ self, document_store: ChromaDocumentStore, policy: DuplicatePolicy
728
+ ):
729
+ docs = [Document(content="refund policy"), Document(content="shipping"), Document(content="refund policy")]
730
+
731
+ with pytest.raises(DuplicateDocumentError):
732
+ document_store.write_documents(docs, policy=policy)
733
+ assert document_store.count_documents() == 0
734
+
735
+ def test_write_documents_skip_with_repeated_ids_already_stored(self, document_store: ChromaDocumentStore):
736
+ stored = Document(content="refund policy")
737
+ document_store.write_documents([stored])
738
+
739
+ docs = [stored, Document(content="shipping"), stored]
740
+ assert document_store.write_documents(docs, policy=DuplicatePolicy.SKIP) == 1
741
+ assert document_store.count_documents() == 2
742
+
717
743
 
718
744
  @pytest.mark.integration
719
745
  class TestMetadataOperations:
@@ -9,6 +9,7 @@ from unittest import mock
9
9
 
10
10
  import pytest
11
11
  from haystack.dataclasses import Document
12
+ from haystack.document_stores.types import DuplicatePolicy
12
13
  from haystack.testing.document_store import TEST_EMBEDDING_1
13
14
  from haystack.testing.document_store_async import (
14
15
  CountDocumentsAsyncTest,
@@ -44,6 +45,18 @@ class TestDocumentStoreAsyncUnit:
44
45
  with pytest.raises(ValueError, match="Invalid client_settings"):
45
46
  await store._ensure_initialized_async()
46
47
 
48
+ async def test_write_documents_async_skip_looks_up_each_id_once(self):
49
+ store = ChromaDocumentStore(host="localhost", port=8000)
50
+ collection = mock.AsyncMock()
51
+ collection.get.return_value = {"ids": []}
52
+ store._async_collection = collection
53
+ store._ensure_initialized_async = mock.AsyncMock() # type: ignore[method-assign]
54
+ docs = [Document(content="refund policy"), Document(content="shipping"), Document(content="refund policy")]
55
+
56
+ assert await store.write_documents_async(docs, policy=DuplicatePolicy.SKIP) == 2
57
+ collection.get.assert_awaited_once_with(ids=[docs[0].id, docs[1].id])
58
+ assert collection.add.await_count == 2
59
+
47
60
 
48
61
  @pytest.mark.skipif(
49
62
  sys.platform == "win32",