Skip to content

Commit f94d1e4

Browse files
committed
Merge branch '25-auto-assign-iduids-model-json' into dev
2 parents cb21388 + f1f4b7f commit f94d1e4

29 files changed

+1399
-336
lines changed

benchmark.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import objectbox
22
import time
3+
from objectbox.store import Store
34
from tests.model import TestEntity
4-
from tests.common import remove_test_dir, load_empty_test_default_store
5+
from tests.common import create_test_store
56

67

78
class ObjectBoxPerf:
@@ -10,8 +11,8 @@ class ObjectBoxPerf:
1011
"""
1112

1213
def __init__(self):
13-
self.store = load_empty_test_default_store()
14-
self.box = store.box(TestEntity)
14+
self.store = create_test_store()
15+
self.box = self.store.box(TestEntity)
1516

1617
def remove_all(self):
1718
self.box.remove_all()
@@ -110,10 +111,10 @@ def __progress_bar(text, value, endvalue, bar_length=20):
110111

111112

112113
if __name__ == "__main__":
113-
remove_test_dir()
114+
Store.remove_db_files("testdata")
114115

115116
obPerf = ObjectBoxPerf()
116117
executor = PerfExecutor(obPerf)
117118
executor.run(count=10000, runs=20)
118119

119-
remove_test_dir()
120+
Store.remove_db_files("testdata")

example/ollama/llamas.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,25 @@
1515

1616

1717
from objectbox.model import *
18+
from objectbox.model.idsync import sync_model
19+
from objectbox.model.properties import *
20+
import numpy as np
1821

1922
# Have fresh data for each start
2023
objectbox.Store.remove_db_files("objectbox")
2124

22-
@Entity(id=1, uid=1)
25+
@Entity()
2326
class DocumentEmbedding:
24-
id = Id(id=1, uid=1001)
25-
document = String(id=2, uid=1002)
26-
embedding = Float32Vector(id=3, uid=1003, index=HnswIndex(
27-
id=3, uid=10001,
27+
id = Id()
28+
document = String()
29+
embedding = Float32Vector(index=HnswIndex(
2830
dimensions=1024,
2931
distance_type=VectorDistanceType.COSINE
3032
))
3133

3234
model = Model()
33-
model.entity(DocumentEmbedding, last_property_id=IdUid(3, 1003))
34-
model.last_entity_id = IdUid(1, 1)
35-
model.last_index_id = IdUid(3,10001)
35+
model.entity(DocumentEmbedding)
36+
sync_model(model, os.path.join(os.path.dirname(__file__),"objectbox-model.json") )
3637

3738
store = objectbox.Store(model=model)
3839
box = store.box(DocumentEmbedding)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"_note1": "KEEP THIS FILE! Check it into a version control system (VCS) like git.",
3+
"_note2": "ObjectBox manages crucial IDs for your object model. See docs for details.",
4+
"_note3": "If you have VCS merge conflicts, you must resolve them according to ObjectBox docs.",
5+
"modelVersionParserMinimum": 5,
6+
"entities": [
7+
{
8+
"id": "1:6961408191300375810",
9+
"name": "DocumentEmbedding",
10+
"lastPropertyId": "3:1544317969640594905",
11+
"properties": [
12+
{
13+
"id": "1:3876977054512990044",
14+
"name": "id",
15+
"type": 6,
16+
"flags": 1
17+
},
18+
{
19+
"id": "2:7160924628219144152",
20+
"name": "document",
21+
"type": 9
22+
},
23+
{
24+
"id": "3:1544317969640594905",
25+
"name": "embedding",
26+
"type": 28,
27+
"flags": 8,
28+
"indexId": "1:3700549598877373380"
29+
}
30+
]
31+
}
32+
],
33+
"lastEntityId": "1:6961408191300375810",
34+
"lastIndexId": "1:3700549598877373380"
35+
}

example/tasks/model.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
from objectbox.model import *
2+
from objectbox.model.idsync import sync_model
3+
import os.path
24

3-
4-
@Entity(id=1, uid=1)
5+
@Entity()
56
class Task:
6-
id = Id(id=1, uid=1001)
7-
text = String(id=2, uid=1002)
7+
id = Id()
8+
text = String()
89

9-
date_created = Date(py_type=int, id=3, uid=1003)
10-
date_finished = Date(py_type=int, id=4, uid=1004)
10+
date_created = Date(py_type=int)
11+
date_finished = Date(py_type=int)
1112

1213

1314
def get_objectbox_model():
1415
m = Model()
15-
m.entity(Task, last_property_id=IdUid(4, 1004))
16-
m.last_entity_id = IdUid(2, 2)
16+
m.entity(Task)
17+
sync_model(m, os.path.join(os.path.dirname(__file__),"objectbox-model.json") )
1718
return m

example/tasks/objectbox-model.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"_note1": "KEEP THIS FILE! Check it into a version control system (VCS) like git.",
3+
"_note2": "ObjectBox manages crucial IDs for your object model. See docs for details.",
4+
"_note3": "If you have VCS merge conflicts, you must resolve them according to ObjectBox docs.",
5+
"modelVersionParserMinimum": 5,
6+
"entities": [
7+
{
8+
"id": "1:5152209066423907023",
9+
"name": "Task",
10+
"lastPropertyId": "4:7654179801863866748",
11+
"properties": [
12+
{
13+
"id": "1:705340479536670333",
14+
"name": "id",
15+
"type": 6,
16+
"flags": 1
17+
},
18+
{
19+
"id": "2:488411871914776672",
20+
"name": "text",
21+
"type": 9,
22+
"flags": 0
23+
},
24+
{
25+
"id": "3:3330502346908829733",
26+
"name": "date_created",
27+
"type": 10,
28+
"flags": 0
29+
},
30+
{
31+
"id": "4:7654179801863866748",
32+
"name": "date_finished",
33+
"type": 10,
34+
"flags": 0
35+
}
36+
]
37+
}
38+
],
39+
"lastEntityId": "1:5152209066423907023",
40+
"lastIndexId": "0:0"
41+
}
Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
from objectbox.model import *
2+
from objectbox.model.properties import *
3+
from objectbox.model.idsync import sync_model
4+
import objectbox
5+
import numpy as np
6+
import os.path
27

3-
@Entity(id=1, uid=1)
8+
@Entity()
49
class City:
5-
id = Id(id=1, uid=1001)
6-
name = String(id=2, uid=1002)
7-
location = Float32Vector(id=3, uid=1003, index=HnswIndex(
8-
id=3, uid=10001,
10+
id = Id()
11+
name = String()
12+
location = Float32Vector(index=HnswIndex(
913
dimensions=2,
1014
distance_type=VectorDistanceType.EUCLIDEAN
1115
))
1216

1317
def get_objectbox_model():
1418
m = Model()
15-
m.entity(City, last_property_id=IdUid(3, 1003))
16-
m.last_entity_id = IdUid(1, 1)
17-
m.last_index_id = IdUid(3, 10001)
19+
m.entity(City)
20+
sync_model(m, os.path.join(os.path.dirname(__file__),"objectbox-model.json") )
1821
return m
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"_note1": "KEEP THIS FILE! Check it into a version control system (VCS) like git.",
3+
"_note2": "ObjectBox manages crucial IDs for your object model. See docs for details.",
4+
"_note3": "If you have VCS merge conflicts, you must resolve them according to ObjectBox docs.",
5+
"modelVersionParserMinimum": 5,
6+
"entities": [
7+
{
8+
"id": "1:1326033324603613162",
9+
"name": "City",
10+
"lastPropertyId": "3:3620267477682371232",
11+
"properties": [
12+
{
13+
"id": "1:2574904406208562760",
14+
"name": "id",
15+
"type": 6,
16+
"flags": 1
17+
},
18+
{
19+
"id": "2:17672653531649098",
20+
"name": "name",
21+
"type": 9,
22+
"flags": 0
23+
},
24+
{
25+
"id": "3:3620267477682371232",
26+
"name": "location",
27+
"type": 28,
28+
"flags": 8,
29+
"indexId": "1:1492488102116293126"
30+
}
31+
]
32+
}
33+
],
34+
"lastEntityId": "1:1326033324603613162",
35+
"lastIndexId": "1:1492488102116293126"
36+
}

objectbox/box.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def get_all(self) -> list:
142142
obx_bytes_array_free(c_bytes_array_p)
143143

144144
def remove(self, id_or_object) -> bool:
145-
if isinstance(id_or_object, self._entity.cls):
145+
if isinstance(id_or_object, self._entity.user_type):
146146
id = self._entity.get_object_id(id_or_object)
147147
else:
148148
id = id_or_object

0 commit comments

Comments
 (0)