Coverage for haystack/components/embedders/types/protocol.py: 100%

6 statements  

« 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 

4 

5from typing import Any, Protocol 

6 

7from haystack import Document 

8 

9 

10class TextEmbedder(Protocol): 

11 """ 

12 Protocol for Text Embedders. 

13 """ 

14 

15 def run(self, text: str) -> dict[str, Any]: 

16 """ 

17 Generate embeddings for the input text. 

18 

19 Implementing classes may accept additional optional parameters in their run method. 

20 For example: `def run (self, text: str, param_a="default", param_b="another_default")`. 

21 

22 :param text: 

23 The input text to be embedded. 

24 :returns: 

25 A dictionary containing the keys: 

26 - 'embedding', which is expected to be a list[float] representing the embedding. 

27 - any optional keys such as 'metadata'. 

28 """ 

29 ... 

30 

31 

32class DocumentEmbedder(Protocol): 

33 """ 

34 Protocol for Document Embedders. 

35 """ 

36 

37 def run(self, documents: list[Document]) -> dict[str, Any]: 

38 """ 

39 Generate embeddings for the input documents. 

40 

41 Implementing classes may accept additional optional parameters in their run method. 

42 For example: `def run (self, documents: list[Document], param_a="default", param_b="another_default")`. 

43 

44 :param documents: 

45 The input documents to be embedded. 

46 :returns: 

47 A dictionary containing the keys: 

48 - 'documents', which is expected to be a list[Document] with embeddings added to each document. 

49 - any optional keys such as 'metadata'. 

50 """ 

51 ...