Skip to content

Commit 6b19059

Browse files
dan-obxloryruta
authored andcommitted
examples: updated to use sync-model #25
1 parent 44a9470 commit 6b19059

3 files changed

Lines changed: 25 additions & 24 deletions

File tree

example/ollama/llamas.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,18 @@
1919
# Have fresh data for each start
2020
objectbox.Store.remove_db_files("objectbox")
2121

22-
@Entity(id=1, uid=1)
22+
@Entity()
2323
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,
24+
id = Id()
25+
document = String()
26+
embedding = Float32Vector(index=HnswIndex(
2827
dimensions=1024,
2928
distance_type=VectorDistanceType.COSINE
3029
))
3130

3231
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)
32+
model.entity(DocumentEmbedding)
33+
sync_model(model)
3634

3735
store = objectbox.Store(model=model)
3836
box = store.box(DocumentEmbedding)

example/tasks/model.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
from objectbox.model import *
2+
from objectbox.model.sync_model import sync_model
23

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

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

1212

1313
def get_objectbox_model():
1414
m = Model()
15-
m.entity(Task, last_property_id=IdUid(4, 1004))
16-
m.last_entity_id = IdUid(2, 2)
15+
m.entity(Task)
16+
sync_model(m)
1717
return m
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.sync_model import sync_model
4+
import objectbox
5+
import numpy as np
26

3-
@Entity(id=1, uid=1)
7+
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)
1821
return m

0 commit comments

Comments
 (0)