forked from MemTensor/MemOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_item.py
More file actions
38 lines (27 loc) · 998 Bytes
/
test_item.py
File metadata and controls
38 lines (27 loc) · 998 Bytes
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
import uuid
import pytest
from pydantic import ValidationError
from memos.vec_dbs.item import VecDBItem
def test_item_creation():
id = str(uuid.uuid4())
item = VecDBItem(id=id, vector=[0.1, 0.2, 0.3], payload={"foo": "bar"})
assert item.id == id
assert item.vector == [0.1, 0.2, 0.3]
assert item.payload == {"foo": "bar"}
assert item.score is None
def test_item_with_score():
item = VecDBItem(vector=[1.0], payload={}, score=0.99)
assert item.score == 0.99
def test_item_validation():
with pytest.raises(ValidationError):
VecDBItem(id=None, vector=[0.1], payload={})
with pytest.raises(ValidationError):
VecDBItem(id="id", vector=None, payload={})
def test_item_from_dict():
id = str(uuid.uuid4())
d = {"id": id, "vector": [1, 2], "payload": {"a": 1}, "score": 0.5}
item = VecDBItem.from_dict(d)
assert item.id == id
assert item.vector == [1, 2]
assert item.payload == {"a": 1}
assert item.score == 0.5