GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — chore: first commit · docarray/docarray@08fb5f2

This repository was archived by the owner on Sep 9, 2026. It is now read-only.

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • docarray
    • __init__.py
    • array
      • __init__.py
      • document.py
    • document
      • __init__.py
      • data.py
      • mixins
        • __init__.py
        • attribute.py
        • audio.py
        • base.py
        • content.py
        • mesh.py
        • property.py
        • text.py
        • video.py
    • typing.py
  • scripts
    • generate_property.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎docarray/__init__.py‎

Copy file name to clipboard
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
from .document import Document
2-
from .array import DocumentArray
2+
from .array import DocumentArray
Collapse file

‎docarray/array/__init__.py‎

Copy file name to clipboard
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .document import DocumentArray
1+
from .document import DocumentArray
Collapse file

‎docarray/array/document.py‎

Copy file name to clipboardExpand all lines: docarray/array/document.py
+21-13Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
import itertools
22
from collections.abc import MutableSequence
3-
from typing import Optional, TYPE_CHECKING, Generator, Iterator, Dict, Union, Iterable, Sequence
3+
from typing import (
4+
Optional,
5+
TYPE_CHECKING,
6+
Generator,
7+
Iterator,
8+
Dict,
9+
Union,
10+
Iterable,
11+
Sequence,
12+
)
413

514
from .. import Document
615
from ..helper import typename
@@ -10,13 +19,16 @@
1019

1120

1221
class DocumentArray(MutableSequence):
13-
14-
def __init__(self, docs: Optional['DocumentArraySourceType'] = None, copy: bool = False):
22+
def __init__(
23+
self, docs: Optional['DocumentArraySourceType'] = None, copy: bool = False
24+
):
1525
super().__init__()
1626
self._pb_body = []
1727
if docs is None:
1828
return
19-
elif isinstance(docs, (DocumentArray, list, tuple, Generator, Iterator, itertools.chain)):
29+
elif isinstance(
30+
docs, (DocumentArray, list, tuple, Generator, Iterator, itertools.chain)
31+
):
2032
if copy:
2133
self._pb_body.extend(Document(d, copy=True) for d in docs)
2234
elif isinstance(docs, DocumentArray):
@@ -66,9 +78,7 @@ def __setitem__(self, key, value: 'Document'):
6678
elif isinstance(key, str):
6779
self[self._index_map[key]].copy_from(value)
6880
else:
69-
raise IndexError(
70-
f'do not support this index type {typename(key)}: {key}'
71-
)
81+
raise IndexError(f'do not support this index type {typename(key)}: {key}')
7282

7383
def __delitem__(self, index: Union[int, str, slice]):
7484
if isinstance(index, int):
@@ -85,9 +95,9 @@ def __delitem__(self, index: Union[int, str, slice]):
8595

8696
def __eq__(self, other):
8797
return (
88-
type(self) is type(other)
89-
and type(self._pb_body) is type(other._pb_body)
90-
and self._pb_body == other._pb_body
98+
type(self) is type(other)
99+
and type(self._pb_body) is type(other._pb_body)
100+
and self._pb_body == other._pb_body
91101
)
92102

93103
def __len__(self):
@@ -109,9 +119,7 @@ def __getitem__(self, index: Union[int, str, slice, Sequence[int]]):
109119
elif isinstance(index, (list, tuple)):
110120
return DocumentArray(self._pb_body[t] for t in index)
111121
else:
112-
IndexError(
113-
f'do not support this index type {typename(index)}: {index}'
114-
)
122+
IndexError(f'do not support this index type {typename(index)}: {index}')
115123

116124
def append(self, doc: 'Document'):
117125
"""
Collapse file

‎docarray/document/__init__.py‎

Copy file name to clipboard
+10-196Lines changed: 10 additions & 196 deletions
Original file line numberDiff line numberDiff line change
@@ -1,215 +1,29 @@
1-
from typing import TYPE_CHECKING, Dict, List, Optional
21
import copy as cp
3-
from .base import BaseDocument, DocumentData
2+
from typing import TYPE_CHECKING, Optional
3+
4+
from .data import DocumentData
45
from .mixins import AllMixins
56

67
if TYPE_CHECKING:
78
from .score import NamedScore
8-
from ..typing import ArrayType, DocumentContentType, StructValueType
9-
from datetime import datetime
10-
from .. import DocumentArray
119

1210

13-
class Document(AllMixins, BaseDocument):
11+
class Document(AllMixins):
1412
_all_doc_content_keys = {'content', 'blob', 'text', 'buffer'}
1513

16-
def __init__(self, obj: Optional['Document'] = None,
17-
copy: bool = False, **kwargs):
18-
self._pb_body = None
14+
def __init__(self, obj: Optional['Document'] = None, copy: bool = False, **kwargs):
15+
self._doc_data = None
1916
if isinstance(obj, Document):
2017
if copy:
21-
self._pb_body = cp.deepcopy(obj._pb_body)
18+
self._doc_data = cp.deepcopy(obj._doc_data)
2219
else:
23-
self._pb_body = obj._pb_body
20+
self._doc_data = obj._doc_data
2421
if kwargs:
2522
# check if there are mutually exclusive content fields
2623
if len(self._all_doc_content_keys.intersection(kwargs.keys())) > 1:
2724
raise ValueError(
2825
f'Document content fields are mutually exclusive, please provide only one of {self._all_doc_content_keys}'
2926
)
30-
self._pb_body = DocumentData(**kwargs)
27+
self._doc_data = DocumentData(**kwargs)
3128
if obj is None and not kwargs:
32-
self._pb_body = DocumentData()
33-
34-
def _clear_content(self):
35-
self._pb_body.text = None
36-
self._pb_body.blob = None
37-
self._pb_body.buffer = None
38-
39-
@property
40-
def id(self) -> str:
41-
return self._pb_body.id
42-
43-
@id.setter
44-
def id(self, value: str):
45-
self._pb_body.id = value
46-
47-
@property
48-
def granularity(self) -> Optional[int]:
49-
return self._pb_body.granularity
50-
51-
@granularity.setter
52-
def granularity(self, value: Optional[int]):
53-
self._pb_body.granularity = value
54-
55-
@property
56-
def adjacency(self) -> Optional[int]:
57-
return self._pb_body.adjacency
58-
59-
@adjacency.setter
60-
def adjacency(self, value: Optional[int]):
61-
self._pb_body.adjacency = value
62-
63-
@property
64-
def parent_id(self) -> Optional[str]:
65-
return self._pb_body.parent_id
66-
67-
@parent_id.setter
68-
def parent_id(self, value: Optional[str]):
69-
self._pb_body.parent_id = value
70-
71-
@property
72-
def buffer(self) -> Optional[bytes]:
73-
return self._pb_body.buffer
74-
75-
@buffer.setter
76-
def buffer(self, value: Optional[bytes]):
77-
self._clear_content()
78-
self._pb_body.buffer = value
79-
80-
@property
81-
def blob(self) -> Optional['ArrayType']:
82-
return self._pb_body.blob
83-
84-
@blob.setter
85-
def blob(self, value: Optional['ArrayType']):
86-
self._clear_content()
87-
self._pb_body.blob = value
88-
89-
@property
90-
def text(self) -> Optional[str]:
91-
return self._pb_body.text
92-
93-
@text.setter
94-
def text(self, value: Optional[str]):
95-
self._clear_content()
96-
self._pb_body.text = value
97-
98-
@property
99-
def content(self) -> Optional['DocumentContentType']:
100-
return self._pb_body.content
101-
102-
@content.setter
103-
def content(self, value: Optional['DocumentContentType']):
104-
if isinstance(value, bytes):
105-
self.buffer = value
106-
elif isinstance(value, str):
107-
self.text = value
108-
else:
109-
self.blob = value
110-
111-
@property
112-
def weight(self) -> Optional[float]:
113-
return self._pb_body.weight
114-
115-
@weight.setter
116-
def weight(self, value: Optional[float]):
117-
self._pb_body.weight = value
118-
119-
@property
120-
def uri(self) -> Optional[str]:
121-
return self._pb_body.uri
122-
123-
@uri.setter
124-
def uri(self, value: Optional[str]):
125-
self._pb_body.uri = value
126-
127-
@property
128-
def mime_type(self) -> Optional[str]:
129-
return self._pb_body.mime_type
130-
131-
@mime_type.setter
132-
def mime_type(self, value: Optional[str]):
133-
self._pb_body.mime_type = value
134-
135-
@property
136-
def tags(self) -> Optional[Dict[str, 'StructValueType']]:
137-
return self._pb_body.tags
138-
139-
@tags.setter
140-
def tags(self, value: Optional[Dict[str, 'StructValueType']]):
141-
self._pb_body.tags = value
142-
143-
@property
144-
def offset(self) -> Optional[float]:
145-
return self._pb_body.offset
146-
147-
@offset.setter
148-
def offset(self, value: Optional[float]):
149-
self._pb_body.offset = value
150-
151-
@property
152-
def location(self) -> Optional[List[float]]:
153-
return self._pb_body.location
154-
155-
@location.setter
156-
def location(self, value: Optional[List[float]]):
157-
self._pb_body.location = value
158-
159-
@property
160-
def embedding(self) -> Optional['ArrayType']:
161-
return self._pb_body.embedding
162-
163-
@embedding.setter
164-
def embedding(self, value: Optional['ArrayType']):
165-
self._pb_body.embedding = value
166-
167-
@property
168-
def modality(self) -> Optional[str]:
169-
return self._pb_body.modality
170-
171-
@modality.setter
172-
def modality(self, value: Optional[str]):
173-
self._pb_body.modality = value
174-
175-
@property
176-
def evaluations(self) -> Optional[Dict[str, 'NamedScore']]:
177-
return self._pb_body.evaluations
178-
179-
@evaluations.setter
180-
def evaluations(self, value: Optional[Dict[str, 'NamedScore']]):
181-
self._pb_body.evaluations = value
182-
183-
@property
184-
def scores(self) -> Optional[Dict[str, 'NamedScore']]:
185-
return self._pb_body.scores
186-
187-
@scores.setter
188-
def scores(self, value: Optional[Dict[str, 'NamedScore']]):
189-
self._pb_body.scores = value
190-
191-
@property
192-
def chunks(self) -> Optional['DocumentArray']:
193-
if self._pb_body.chunks is None:
194-
self._pb_body.chunks = DocumentArray()
195-
return self._pb_body.chunks
196-
197-
@chunks.setter
198-
def chunks(self, value: Optional['DocumentArray']):
199-
self._pb_body.chunks = value
200-
201-
@property
202-
def matches(self) -> Optional['DocumentArray']:
203-
return self._pb_body.matches
204-
205-
@matches.setter
206-
def matches(self, value: Optional['DocumentArray']):
207-
self._pb_body.matches = value
208-
209-
@property
210-
def timestamps(self) -> Optional[Dict[str, 'datetime']]:
211-
return self._pb_body.timestamps
212-
213-
@timestamps.setter
214-
def timestamps(self, value: Optional[Dict[str, 'datetime']]):
215-
self._pb_body.timestamps = value
29+
self._doc_data = DocumentData()
Collapse file

‎docarray/document/data.py‎

Copy file name to clipboard
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import uuid
2+
from dataclasses import dataclass, field
3+
from typing import TYPE_CHECKING, Dict, List, Optional
4+
5+
if TYPE_CHECKING:
6+
from .score import NamedScore
7+
from .. import DocumentArray
8+
from ..typing import ArrayType, DocumentContentType, StructValueType
9+
from datetime import datetime
10+
11+
12+
@dataclass
13+
class DocumentData:
14+
id: str = field(default_factory=lambda: uuid.uuid1().hex)
15+
granularity: Optional[int] = None
16+
adjacency: Optional[int] = None
17+
parent_id: Optional[str] = None
18+
buffer: Optional[bytes] = None
19+
blob: Optional['ArrayType'] = None
20+
text: Optional[str] = None
21+
content: Optional['DocumentContentType'] = None
22+
weight: Optional[float] = None
23+
uri: Optional[str] = None
24+
mime_type: Optional[str] = None
25+
tags: Optional[Dict[str, 'StructValueType']] = None
26+
offset: Optional[float] = None
27+
location: Optional[List[float]] = None
28+
embedding: Optional['ArrayType'] = None
29+
modality: Optional[str] = None
30+
evaluations: Optional[Dict[str, 'NamedScore']] = None
31+
scores: Optional[Dict[str, 'NamedScore']] = None
32+
chunks: Optional['DocumentArray'] = None
33+
matches: Optional['DocumentArray'] = None
34+
timestamps: Optional[Dict[str, 'datetime']] = None
Collapse file

‎docarray/document/mixins/__init__.py‎

Copy file name to clipboardExpand all lines: docarray/document/mixins/__init__.py
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1-
from .attribute import GetSetAttributeMixin
1+
from .attribute import GetAttributesMixin
22
from .audio import AudioDataMixin
3+
from .base import BaseDocumentMixin
34
from .buffer import BufferDataMixin
45
from .content import ContentPropertyMixin
56
from .convert import ConvertMixin
67
from .dump import DumpFileMixin
78
from .image import ImageDataMixin
89
from .mesh import MeshDataMixin
910
from .plot import PlotMixin
11+
from .property import PropertyMixin
1012
from .sugar import SingletonSugarMixin
1113
from .text import TextDataMixin
1214
from .video import VideoDataMixin
1315

1416

1517
class AllMixins(
18+
BaseDocumentMixin,
19+
PropertyMixin,
1620
ContentPropertyMixin,
1721
ConvertMixin,
1822
AudioDataMixin,
@@ -24,7 +28,7 @@ class AllMixins(
2428
PlotMixin,
2529
DumpFileMixin,
2630
SingletonSugarMixin,
27-
GetSetAttributeMixin,
31+
GetAttributesMixin,
2832
):
2933
"""All plugins that can be used in :class:`Document`. """
3034

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.