• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

deepset-ai / haystack / 13972131258

20 Mar 2025 02:43PM UTC coverage: 90.021% (-0.03%) from 90.054%
13972131258

Pull #9069

github

web-flow
Merge 8371761b0 into 67ab3788e
Pull Request #9069: refactor!: `ChatMessage` serialization-deserialization updates

9833 of 10923 relevant lines covered (90.02%)

0.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

64.71
haystack/document_stores/types/protocol.py
1
# SPDX-FileCopyrightText: 2022-present deepset GmbH <info@deepset.ai>
2
#
3
# SPDX-License-Identifier: Apache-2.0
4

5
from typing import Any, Dict, List, Optional, Protocol
1✔
6

7
from haystack.dataclasses import Document
1✔
8
from haystack.document_stores.types.policy import DuplicatePolicy
1✔
9

10
# Ellipsis are needed for the type checker, it's safe to disable module-wide
11
# pylint: disable=unnecessary-ellipsis
12

13

14
class DocumentStore(Protocol):
1✔
15
    """
16
    Stores Documents to be used by the components of a Pipeline.
17

18
    Classes implementing this protocol often store the documents permanently and allow specialized components to
19
    perform retrieval on them, either by embedding, by keyword, hybrid, and so on, depending on the backend used.
20

21
    In order to retrieve documents, consider using a Retriever that supports the DocumentStore implementation that
22
    you're using.
23
    """
24

25
    def to_dict(self) -> Dict[str, Any]:
1✔
26
        """
27
        Serializes this store to a dictionary.
28
        """
29
        ...
×
30

31
    @classmethod
1✔
32
    def from_dict(cls, data: Dict[str, Any]) -> "DocumentStore":
1✔
33
        """
34
        Deserializes the store from a dictionary.
35
        """
36
        ...
×
37

38
    def count_documents(self) -> int:
1✔
39
        """
40
        Returns the number of documents stored.
41
        """
42
        ...
×
43

44
    def filter_documents(self, filters: Optional[Dict[str, Any]] = None) -> List[Document]:
1✔
45
        """
46
        Returns the documents that match the filters provided.
47

48
        Filters are defined as nested dictionaries that can be of two types:
49
        - Comparison
50
        - Logic
51

52
        Comparison dictionaries must contain the keys:
53

54
        - `field`
55
        - `operator`
56
        - `value`
57

58
        Logic dictionaries must contain the keys:
59

60
        - `operator`
61
        - `conditions`
62

63
        The `conditions` key must be a list of dictionaries, either of type Comparison or Logic.
64

65
        The `operator` value in Comparison dictionaries must be one of:
66

67
        - `==`
68
        - `!=`
69
        - `>`
70
        - `>=`
71
        - `<`
72
        - `<=`
73
        - `in`
74
        - `not in`
75

76
        The `operator` values in Logic dictionaries must be one of:
77

78
        - `NOT`
79
        - `OR`
80
        - `AND`
81

82

83
        A simple filter:
84
        ```python
85
        filters = {"field": "meta.type", "operator": "==", "value": "article"}
86
        ```
87

88
        A more complex filter:
89
        ```python
90
        filters = {
91
            "operator": "AND",
92
            "conditions": [
93
                {"field": "meta.type", "operator": "==", "value": "article"},
94
                {"field": "meta.date", "operator": ">=", "value": 1420066800},
95
                {"field": "meta.date", "operator": "<", "value": 1609455600},
96
                {"field": "meta.rating", "operator": ">=", "value": 3},
97
                {
98
                    "operator": "OR",
99
                    "conditions": [
100
                        {"field": "meta.genre", "operator": "in", "value": ["economy", "politics"]},
101
                        {"field": "meta.publisher", "operator": "==", "value": "nytimes"},
102
                    ],
103
                },
104
            ],
105
        }
106

107
        :param filters: the filters to apply to the document list.
108
        :returns: a list of Documents that match the given filters.
109
        """
110
        ...
×
111

112
    def write_documents(self, documents: List[Document], policy: DuplicatePolicy = DuplicatePolicy.NONE) -> int:
1✔
113
        """
114
        Writes Documents into the DocumentStore.
115

116
        :param documents: a list of Document objects.
117
        :param policy: the policy to apply when a Document with the same id already exists in the DocumentStore.
118
            - `DuplicatePolicy.NONE`: Default policy, behaviour depends on the Document Store.
119
            - `DuplicatePolicy.SKIP`: If a Document with the same id already exists, it is skipped and not written.
120
            - `DuplicatePolicy.OVERWRITE`: If a Document with the same id already exists, it is overwritten.
121
            - `DuplicatePolicy.FAIL`: If a Document with the same id already exists, an error is raised.
122
        :raises DuplicateError: If `policy` is set to `DuplicatePolicy.FAIL` and a Document with the same id already
123
            exists.
124
        :returns: The number of Documents written.
125
            If `DuplicatePolicy.OVERWRITE` is used, this number is always equal to the number of documents in input.
126
            If `DuplicatePolicy.SKIP` is used, this number can be lower than the number of documents in the input list.
127
        """
128
        ...
×
129

130
    def delete_documents(self, document_ids: List[str]) -> None:
1✔
131
        """
132
        Deletes all documents with a matching document_ids from the DocumentStore.
133

134
        Fails with `MissingDocumentError` if no document with this id is present in the DocumentStore.
135

136
        :param document_ids: the object_ids to delete
137
        """
138
        ...
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc