Skip to content

Commit 661bfbe

Browse files
dan-obxgreenrobot
authored andcommitted
examples: simplfied using one script per example #59
1 parent 92c2942 commit 661bfbe

File tree

10 files changed

+29
-37
lines changed

10 files changed

+29
-37
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
```

example/tasks/__init__.py

Whitespace-only changes.
Lines changed: 10 additions & 1 deletion
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

example/tasks/model.py

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

example/vectorsearch-cities/__init__.py

Whitespace-only changes.
Lines changed: 10 additions & 1 deletion
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:

example/vectorsearch-cities/model.py

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

0 commit comments

Comments
 (0)