Coverage for haystack/components/retrievers/types/protocol.py: 100%
5 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-21 13:53 +0000
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-21 13:53 +0000
1# SPDX-FileCopyrightText: 2022-present deepset GmbH <info@deepset.ai>
2#
3# SPDX-License-Identifier: Apache-2.0
5from typing import Any, Protocol
8class TextRetriever(Protocol):
9 """
10 This protocol defines the minimal interface that all keyword-based BM25 Retrievers must implement.
12 Retrievers are components that process a query and, based on that query, return relevant documents from a document
13 store or other data source. They return a dictionary with a list of Document objects.
14 """
16 def run(self, query: str, filters: dict[str, Any] | None = None, top_k: int | None = None) -> dict[str, Any]:
17 """
18 Retrieve documents that are relevant to the query.
20 Implementing classes may accept additional optional parameters in their run method.
22 :param query: The input query string.
23 :param filters: A dictionary of filters to apply when retrieving documents.
24 :param top_k: The maximum number of documents to return.
26 :returns:
27 A dictionary containing:
28 `documents`: List of retrieved documents sorted by relevance score.
29 """
30 ...
33class EmbeddingRetriever(Protocol):
34 """
35 This protocol defines the minimal interface that all embedding-based Retrievers must implement.
37 Retrievers are components that process a query and, based on that query, return relevant documents from a document
38 store or other data source. They return a dictionary with a list of Document objects.
39 """
41 def run(
42 self, query_embedding: list[float], filters: dict[str, Any] | None = None, top_k: int | None = None
43 ) -> dict[str, Any]:
44 """
45 Retrieve documents that are relevant to the query.
47 Implementing classes may accept additional optional parameters in their run method.
49 :param query_embedding: The input query embedding.
50 :param filters: A dictionary of filters to apply when retrieving documents.
51 :param top_k: The maximum number of documents to return.
52 :returns:
53 A dictionary containing:
54 `documents`: List of retrieved documents sorted by relevance score.
55 """
56 ...