{"record":{"id":"148af563bccc07ef","repo":"deepset-ai/haystack","slug":"document-store-must-be-an-instance-of-inmemorydocu","errorCode":null,"errorMessage":"document_store must be an instance of InMemoryDocumentStore","messagePattern":"document_store must be an instance of InMemoryDocumentStore","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"haystack/components/retrievers/in_memory/bm25_retriever.py","lineNumber":71,"sourceCode":"            An instance of InMemoryDocumentStore where the retriever should search for relevant documents.\n        :param filters:\n            A dictionary with filters to narrow down the retriever's search space in the document store.\n        :param top_k:\n            The maximum number of documents to retrieve.\n        :param scale_score:\n            When `True`, scales the score of retrieved documents to a range of 0 to 1, where 1 means extremely relevant.\n            When `False`, uses raw similarity scores.\n        :param filter_policy: The filter policy to apply during retrieval.\n        Filter policy determines how filters are applied when retrieving documents. You can choose:\n        - `REPLACE` (default): Overrides the initialization filters with the filters specified at runtime.\n        Use this policy to dynamically change filtering for specific queries.\n        - `MERGE`: Combines runtime filters with initialization filters to narrow down the search.\n        :raises TypeError: If the document_store is not an instance of InMemoryDocumentStore.\n        :raises ValueError:\n            If the specified `top_k` is not > 0.\n        \"\"\"\n        if not isinstance(document_store, InMemoryDocumentStore):\n            raise TypeError(\"document_store must be an instance of InMemoryDocumentStore\")\n\n        self.document_store = document_store\n\n        if top_k <= 0:\n            raise ValueError(f\"top_k must be greater than 0. Currently, the top_k is {top_k}\")\n\n        self.filters = filters\n        self.top_k = top_k\n        self.scale_score = scale_score\n        self.filter_policy = filter_policy\n\n    def _get_telemetry_data(self) -> dict[str, Any]:\n        \"\"\"\n        Data that is sent to Posthog for usage analytics.\n        \"\"\"\n        return {\"document_store\": type(self.document_store).__name__}\n\n    def to_dict(self) -> dict[str, Any]:","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/components/retrievers/in_memory/bm25_retriever.py#L53-L89","documentation":"BM25Retriever (the in-memory variant) only supports InMemoryDocumentStore because BM25 scoring is implemented there. Passing any other DocumentStore raises a TypeError in __init__, not a ValueError.","triggerScenarios":"BM25Retriever(document_store=QdrantDocumentStore(...)) or any non-InMemoryDocumentStore instance.","commonSituations":"Swapping a document store in a pipeline template without switching the retriever class, or migrating from in-memory to a vector database but keeping BM25Retriever.","solutions":["Use the retriever class matching your store, e.g. QdrantEmbeddingRetriever / store-specific BM25 retriever","Switch document_store to InMemoryDocumentStore if BM25 in-memory retrieval is intended","Use InMemoryBM25Retriever explicitly to make intent clear"],"exampleFix":"// before\nretriever = BM25Retriever(document_store=QdrantDocumentStore(url=...))\n// after\nretriever = QdrantEmbeddingRetriever(document_store=qdrant_store)\n# or\nretriever = InMemoryBM25Retriever(document_store=InMemoryDocumentStore())","handlingStrategy":"type-guard","validationCode":"from haystack.document_stores.in_memory import InMemoryDocumentStore\nif not isinstance(store, InMemoryDocumentStore):\n    raise TypeError(f\"BM25Retriever needs InMemoryDocumentStore, got {type(store).__name__}\")","typeGuard":"def supports_inmemory_bm25(store: object) -> bool:\n    from haystack.document_stores.in_memory import InMemoryDocumentStore\n    return isinstance(store, InMemoryDocumentStore)","tryCatchPattern":"try:\n    retriever = InMemoryBM25Retriever(document_store=store)\nexcept TypeError as e:\n    logger.error(\"Incompatible document store: %s\", e)\n    retriever = InMemoryBM25Retriever(document_store=InMemoryDocumentStore())","preventionTips":["Match retriever class to document store backend","Pin retriever/store pairs in pipeline factory code","Add isinstance checks in pipeline construction utilities"],"tags":["type-error","retriever","document-store","incompatibility"],"backgroundTag":"incompatible-document-store","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}