#12746·haystack

InMemoryDocumentStore unique metadata count fails for list and dict values

Author: CoralGarden52Created Sep 14, 2026Updated Sep 14, 2026

Describe the bug InMemoryDocumentStore.count_unique_metadata_by_filter() raises TypeError when a requested metadata field contains a JSON-serializable list or dictionary. The async variant fails through the same implementation.

Error message

TypeError: unhashable type: list
TypeError: unhashable type: dict

Expected behavior The method should count distinct JSON-serializable metadata values, including lists and dictionaries, consistently with the Document.meta contract. Equal list or dictionary values should count once, while list order should remain significant.

Additional context Document.meta is documented as JSON-serializable. For the same documents, json.dumps(document.to_dict()), filter_documents(), and get_metadata_field_unique_values() work with these values. Existing scalar count tests pass, but composite metadata is not covered. The failure occurs when a user explicitly calls this public metadata statistics API; it is not part of the automatic retrieval path.

To Reproduce

python
from haystack import Document
from haystack.document_stores.in_memory import InMemoryDocumentStore

for metadata in ({"tags": ["news", "ai"]}, {"source": {"type": "docs", "section": {"id": 1}}}):
    store = InMemoryDocumentStore()
    store.write_documents([Document(content="Document", meta=metadata)])
    field = next(iter(metadata))
    store.count_unique_metadata_by_filter(filters={}, metadata_fields=[field])

Each call raises TypeError from the set-based unique-value collection. count_unique_metadata_by_filter_async() reproduces the same error.

FAQ Check

System:

  • OS: Linux
  • Haystack version: main at f7b46875f (2026-09-14)