Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

History

History
History
50 lines (43 loc) 路 1.44 KB

File metadata and controls

50 lines (43 loc) 路 1.44 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import numpy as np
from docarray import DocumentArray, Document
def random_docs(
num_docs,
chunks_per_doc=5,
embed_dim=10,
jitter=1,
start_id=0,
embedding=True,
sparse_embedding=False,
text='hello world',
) -> DocumentArray:
da = DocumentArray()
next_chunk_doc_id = start_id + num_docs
for j in range(num_docs):
doc_id = str(start_id + j)
d = Document(id=doc_id)
d.text = text
d.tags['id'] = f'myself id is: {doc_id}'
if embedding:
if sparse_embedding:
from scipy.sparse import coo_matrix
d.embedding = coo_matrix(
(np.array([1, 1, 1]), (np.array([0, 1, 2]), np.array([1, 2, 1])))
)
else:
d.embedding = np.random.random(
[embed_dim + np.random.randint(0, jitter)]
)
for _ in range(chunks_per_doc):
chunk_doc_id = str(next_chunk_doc_id)
c = Document(id=chunk_doc_id)
c.text = 'i\'m chunk %s from doc %s' % (chunk_doc_id, doc_id)
if embedding:
c.embedding = np.random.random(
[embed_dim + np.random.randint(0, jitter)]
)
c.tags['parent_id'] = f'my parent is: {id}'
c.tags['id'] = f'myself id is: {doc_id}'
d.chunks.append(c)
next_chunk_doc_id += 1
da.append(d)
return da
Morty Proxy This is a proxified and sanitized view of the page, visit original site.