File size: 6,396 Bytes
b3d711f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
from abc import abstractmethod
from typing import Optional, Sequence, Tuple
from uuid import UUID
from chromadb.api.collection_configuration import (
    CreateCollectionConfiguration,
    UpdateCollectionConfiguration,
)
from chromadb.api.types import Schema
from chromadb.types import (
    Collection,
    CollectionAndSegments,
    Database,
    Tenant,
    Metadata,
    Segment,
    SegmentScope,
    OptionalArgument,
    Unspecified,
    UpdateMetadata,
)
from chromadb.config import DEFAULT_DATABASE, DEFAULT_TENANT, Component


class SysDB(Component):
    """Data interface for Chroma's System database"""

    @abstractmethod
    def create_database(

        self, id: UUID, name: str, tenant: str = DEFAULT_TENANT

    ) -> None:
        """Create a new database in the System database. Raises an Error if the Database

        already exists."""
        pass

    @abstractmethod
    def get_database(self, name: str, tenant: str = DEFAULT_TENANT) -> Database:
        """Get a database by name and tenant. Raises an Error if the Database does not

        exist."""
        pass

    @abstractmethod
    def delete_database(self, name: str, tenant: str = DEFAULT_TENANT) -> None:
        """Delete a database."""
        pass

    @abstractmethod
    def list_databases(

        self,

        limit: Optional[int] = None,

        offset: Optional[int] = None,

        tenant: str = DEFAULT_TENANT,

    ) -> Sequence[Database]:
        """List all databases for a tenant."""
        pass

    @abstractmethod
    def create_tenant(self, name: str) -> None:
        """Create a new tenant in the System database. The name must be unique.

        Raises an Error if the Tenant already exists."""
        pass

    @abstractmethod
    def get_tenant(self, name: str) -> Tenant:
        """Get a tenant by name. Raises an Error if the Tenant does not exist."""
        pass

    # TODO: Investigate and remove this method, as segment creation is done as
    # part of collection creation.
    @abstractmethod
    def create_segment(self, segment: Segment) -> None:
        """Create a new segment in the System database. Raises an Error if the ID

        already exists."""
        pass

    @abstractmethod
    def delete_segment(self, collection: UUID, id: UUID) -> None:
        """Delete a segment from the System database."""
        pass

    @abstractmethod
    def get_segments(

        self,

        collection: UUID,

        id: Optional[UUID] = None,

        type: Optional[str] = None,

        scope: Optional[SegmentScope] = None,

    ) -> Sequence[Segment]:
        """Find segments by id, type, scope or collection."""
        pass

    @abstractmethod
    def update_segment(

        self,

        collection: UUID,

        id: UUID,

        metadata: OptionalArgument[Optional[UpdateMetadata]] = Unspecified(),

    ) -> None:
        """Update a segment. Unspecified fields will be left unchanged. For the

        metadata, keys with None values will be removed and keys not present in the

        UpdateMetadata dict will be left unchanged."""
        pass

    @abstractmethod
    def create_collection(

        self,

        id: UUID,

        name: str,

        schema: Optional[Schema],

        configuration: CreateCollectionConfiguration,

        segments: Sequence[Segment],

        metadata: Optional[Metadata] = None,

        dimension: Optional[int] = None,

        get_or_create: bool = False,

        tenant: str = DEFAULT_TENANT,

        database: str = DEFAULT_DATABASE,

    ) -> Tuple[Collection, bool]:
        """Create a new collection and associated resources

        in the SysDB. If get_or_create is True, the

        collection will be created if one with the same name does not exist.

        The metadata will be updated using the same protocol as update_collection. If get_or_create

        is False and the collection already exists, an error will be raised.



        Returns a tuple of the created collection and a boolean indicating whether the

        collection was created or not.

        """
        pass

    @abstractmethod
    def delete_collection(

        self,

        id: UUID,

        tenant: str = DEFAULT_TENANT,

        database: str = DEFAULT_DATABASE,

    ) -> None:
        """Delete a collection, all associated segments and any associate resources (log stream)

        from the SysDB and the system at large."""
        pass

    @abstractmethod
    def get_collections(

        self,

        id: Optional[UUID] = None,

        name: Optional[str] = None,

        tenant: str = DEFAULT_TENANT,

        database: str = DEFAULT_DATABASE,

        limit: Optional[int] = None,

        offset: Optional[int] = None,

    ) -> Sequence[Collection]:
        """Find collections by id or name. If name is provided, tenant and database must also be provided."""
        pass

    @abstractmethod
    def count_collections(

        self,

        tenant: str = DEFAULT_TENANT,

        database: Optional[str] = None,

    ) -> int:
        """Gets the number of collections for the (tenant, database) combination."""
        pass

    @abstractmethod
    def get_collection_with_segments(

        self, collection_id: UUID

    ) -> CollectionAndSegments:
        """Get a consistent snapshot of a collection by id. This will return a collection with segment

        information that matches the collection version and log position.

        """
        pass

    @abstractmethod
    def update_collection(

        self,

        id: UUID,

        name: OptionalArgument[str] = Unspecified(),

        dimension: OptionalArgument[Optional[int]] = Unspecified(),

        metadata: OptionalArgument[Optional[UpdateMetadata]] = Unspecified(),

        configuration: OptionalArgument[

            Optional[UpdateCollectionConfiguration]

        ] = Unspecified(),

    ) -> None:
        """Update a collection. Unspecified fields will be left unchanged. For metadata,

        keys with None values will be removed and keys not present in the UpdateMetadata

        dict will be left unchanged."""
        pass

    @abstractmethod
    def get_collection_size(self, id: UUID) -> int:
        """Returns the number of records in a collection."""
        pass