-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
executable file
·35 lines (28 loc) · 896 Bytes
/
test.py
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
from docarray import BaseDoc, DocList
from lib import *
from lib.embedders import BgeLLMEmbedder, BgeInstructionType
from docarray import BaseDoc, DocList
from docarray.index import InMemoryExactNNIndex
from docarray.typing import NdArray
import numpy as np
@EmbeddedDoc({'embedding': BgeLLMEmbedder()})
class MyDoc(BaseDoc):
x: str
docs = DocList([
MyDoc(x='a'),
MyDoc(x='b'),
MyDoc(x='c'),
])
for doc, embed in batch_embed(docs, 'embedding',
BgeLLMEmbedder().embed_nl_query):
embed((BgeInstructionType.chat, doc.x))
for doc in docs:
print(doc.embedding)
print(batch_embed_raw([
(BgeInstructionType.chat, 'b'),
(BgeInstructionType.chat, 'c'),
(BgeInstructionType.chat, 'd')
], BgeLLMEmbedder().embed_nl_query, batch_size=1))
import os
abs_path = os.path.join(os.path.dirname(__file__), 'simple_dl')
docs.push(f'file://{abs_path}')