-
Notifications
You must be signed in to change notification settings - Fork 238
Expand file tree
/
Copy pathdocument.py
More file actions
81 lines (68 loc) · 2.73 KB
/
document.py
File metadata and controls
81 lines (68 loc) · 2.73 KB
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
from typing import Optional, overload, TYPE_CHECKING, Dict, Union
from .base import BaseDocumentArray
from .mixins import AllMixins
if TYPE_CHECKING:
from ..types import DocumentArraySourceType
from .memory import DocumentArrayInMemory
from .sqlite import DocumentArraySqlite
from .annlite import DocumentArrayAnnlite
from .weaviate import DocumentArrayWeaviate
from .storage.sqlite import SqliteConfig
from .storage.annlite import AnnliteConfig
from .storage.weaviate import WeaviateConfig
class DocumentArray(AllMixins, BaseDocumentArray):
@overload
def __new__(
cls, _docs: Optional['DocumentArraySourceType'] = None, copy: bool = False
) -> 'DocumentArrayInMemory':
"""Create an in-memory DocumentArray object."""
...
@overload
def __new__(
cls,
_docs: Optional['DocumentArraySourceType'] = None,
storage: str = 'sqlite',
config: Optional[Union['SqliteConfig', Dict]] = None,
) -> 'DocumentArraySqlite':
"""Create a SQLite-powered DocumentArray object."""
...
@overload
def __new__(
cls,
_docs: Optional['DocumentArraySourceType'] = None,
storage: str = 'weaviate',
config: Optional[Union['WeaviateConfig', Dict]] = None,
) -> 'DocumentArrayWeaviate':
"""Create a Weaviate-powered DocumentArray object."""
...
@overload
def __new__(
cls,
_docs: Optional['DocumentArraySourceType'] = None,
storage: str = 'annlite',
config: Optional[Union['AnnliteConfig', Dict]] = None,
) -> 'DocumentArrayAnnlite':
"""Create a AnnLite-powered DocumentArray object."""
...
def __new__(cls, *args, storage: str = 'memory', **kwargs):
if cls is DocumentArray:
if storage == 'memory':
from .memory import DocumentArrayInMemory
instance = super().__new__(DocumentArrayInMemory)
elif storage == 'sqlite':
from .sqlite import DocumentArraySqlite
instance = super().__new__(DocumentArraySqlite)
elif storage == 'annlite':
from .annlite import DocumentArrayAnnlite
instance = super().__new__(DocumentArrayAnnlite)
elif storage == 'weaviate':
from .weaviate import DocumentArrayWeaviate
instance = super().__new__(DocumentArrayWeaviate)
elif storage == 'qdrant':
from .qdrant import DocumentArrayQdrant
instance = super().__new__(DocumentArrayQdrant)
else:
raise ValueError(f'storage=`{storage}` is not supported.')
else:
instance = super().__new__(cls)
return instance