Skip to content

Commit 6d4fb34

Browse files
committed
Merge branch '59-minimize-required-model-interaction' into 'dev'
Resolve "Minimize required model interaction" #59 Closes #59 See merge request objectbox/objectbox-python!44
2 parents 402cbd5 + 6c88a48 commit 6d4fb34

24 files changed

+329
-228
lines changed

example/README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,18 @@ pip install --pre objectbox
1313

1414
The following examples are available from this directory:
1515

16-
- `tasks`: CRUD Application Example (see below for details)
17-
- `vectorsearch-cities`: VectorSearch Application Example (see below for details)
16+
- `tasks`: CRUD Example (see below for details)
17+
- `vectorsearch-cities`: VectorSearch Example (see below for details)
1818
- `ollama`: LLM + VectorSearch Embeddings Script Example (See [ollama/README.md](./ollama/README.md) for details)
1919

2020

21-
## Application Example: Tasks
21+
## Example: Tasks
2222

2323
This is our classic Tasks application using a CLI.
2424

2525
```
26-
$ python -m tasks
26+
cd tasks
27+
$ python main.py
2728
2829
Welcome to the ObjectBox tasks-list app example. Type help or ? for a list of commands.
2930
> new buy oat
@@ -45,13 +46,14 @@ Welcome to the ObjectBox tasks-list app example. Type help or ? for a list of co
4546
> exit
4647
```
4748

48-
## Vector-Search Example: Cities
49+
## Example: Vector-Search
4950

5051
This example application starts with a pre-defined set of capital cities and their geo coordinates.
5152
It allows to search for nearest neighbors of a city (`city_neighbors`) or by coordinates (`neighbors`) as well as adding more locations (`add`).
5253

5354
```
54-
$ python -m vectorsearch-cities
55+
cd example/vector-search-cities
56+
$ python main.py
5557
5658
Welcome to the ObjectBox vectorsearch-cities example. Type help or ? for a list of commands.
5759
> ls

example/__init__.py

Whitespace-only changes.

example/ollama/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ based on https://ollama.com/blog/embedding-models
3333
## Run Example
3434
3535
```
36-
$ python llamas.py
36+
$ python main.py
3737
3838
Llamas are members of the camel family, which includes other large, even-toed ungulates such as camels, dromedaries, and Bactrian camels. Llamas are most closely related to alpacas, which are also native to South America and share many similarities in terms of their physical characteristics and behavior. Both llamas and alpacas belong to the family Camelidae, and are classified as ruminants due to their unique digestive system that allows them to break down cellulose in plant material.
3939
```
Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
import ollama
55
import objectbox
6+
from objectbox.model import *
7+
from objectbox.model.properties import *
68

79
documents = [
810
"Llamas are members of the camelid family meaning they're pretty closely related to vicuñas and camels",
@@ -13,12 +15,6 @@
1315
"Llamas live to be about 20 years old, though some only live for 15 years and others live to be 30 years old",
1416
]
1517

16-
17-
from objectbox.model import *
18-
from objectbox.model.idsync import sync_model
19-
from objectbox.model.properties import *
20-
import numpy as np
21-
2218
# Have fresh data for each start
2319
objectbox.Store.remove_db_files("objectbox")
2420

@@ -31,11 +27,7 @@ class DocumentEmbedding:
3127
distance_type=VectorDistanceType.COSINE
3228
))
3329

34-
model = Model()
35-
model.entity(DocumentEmbedding)
36-
sync_model(model, os.path.join(os.path.dirname(__file__),"objectbox-model.json") )
37-
38-
store = objectbox.Store(model=model)
30+
store = objectbox.Store()
3931
box = store.box(DocumentEmbedding)
4032

4133
print("Documents to embed: ", len(documents))

example/tasks/__init__.py

Whitespace-only changes.
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
from cmd import Cmd
22
import objectbox
3+
from objectbox.model import *
34
import time
4-
from .model import *
5+
6+
@Entity()
7+
class Task:
8+
id = Id()
9+
text = String()
10+
11+
date_created = Date(py_type=int)
12+
date_finished = Date(py_type=int)
13+
514

615

716
# objectbox expects date timestamp in milliseconds since UNIX epoch
@@ -15,7 +24,7 @@ def format_date(timestamp_ms: int) -> str:
1524

1625
class TasklistCmd(Cmd):
1726
prompt = "> "
18-
_store = objectbox.Store(model=get_objectbox_model(), directory="tasklist-db")
27+
_store = objectbox.Store(directory="tasklist-db")
1928
_box = _store.box(Task)
2029

2130
def do_ls(self, _):

example/tasks/model.py

Lines changed: 0 additions & 18 deletions
This file was deleted.

example/vectorsearch-cities/__init__.py

Whitespace-only changes.
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
from cmd import Cmd
22
import objectbox
3+
from objectbox.model import *
34
import time
4-
from .model import *
55
import csv
66
import os
77

8+
@Entity()
9+
class City:
10+
id = Id()
11+
name = String()
12+
location = Float32Vector(index=HnswIndex(
13+
dimensions=2,
14+
distance_type=VectorDistanceType.EUCLIDEAN
15+
))
16+
817
def list_cities(cities):
918
print("{:3s} {:25s} {:>9s} {:>9s}".format("ID", "Name", "Latitude", "Longitude"))
1019
for city in cities:
@@ -23,7 +32,7 @@ def __init__(self, *args):
2332
Cmd.__init__(self, *args)
2433
dbdir = "cities-db"
2534
new_db = not os.path.exists(dbdir)
26-
self._store = objectbox.Store(model=get_objectbox_model(),directory=dbdir)
35+
self._store = objectbox.Store(directory=dbdir)
2736
self._box = self._store.box(City)
2837
if new_db:
2938
with open(os.path.join(os.path.dirname(__file__), 'cities.csv')) as f:

example/vectorsearch-cities/model.py

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)