Skip to content

Commit bbd67ab

Browse files
committed
examples: use uniform api #29
1 parent 378efb5 commit bbd67ab

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

example/ollama/llamas.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,8 @@ class DocumentEmbedding:
5757
model="mxbai-embed-large"
5858
)
5959

60-
61-
embedding_prop: Property = DocumentEmbedding.get_property("embedding")
6260
query = box.query(
63-
embedding_prop.nearest_neighbor(response["embedding"], 1)
61+
DocumentEmbedding.embedding.nearest_neighbor(response["embedding"], 1)
6462
).build()
6563

6664
results = query.find_with_scores()

example/vectorsearch-cities/__main__.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ def __init__(self, *args):
2525
new_db = not os.path.exists(dbdir)
2626
self._store = objectbox.Store(model=get_objectbox_model(),directory=dbdir)
2727
self._box = self._store.box(City)
28-
self._name_prop: Property = City.get_property("name")
29-
self._location_prop: Property = City.get_property("location")
3028
if new_db:
3129
with open(os.path.join(os.path.dirname(__file__), 'cities.csv')) as f:
3230
r = csv.reader(f)
@@ -40,8 +38,7 @@ def __init__(self, *args):
4038

4139
def do_ls(self, name: str = ""):
4240
"""list all cities or starting with <prefix>\nusage: ls [<prefix>]"""
43-
qb = self._box.query()
44-
qb.starts_with_string(self._name_prop, name)
41+
qb = self._box.query( City.name.starts_with(name) )
4542
query = qb.build()
4643
list_cities(query.find())
4744

@@ -57,15 +54,15 @@ def do_city_neighbors(self, args: str):
5754
num = 5
5855
if len(args) == 2:
5956
num = int(args[1])
60-
qb = self._box.query()
61-
qb.equals_string(self._name_prop, city)
57+
qb = self._box.query( City.name.equals(city) )
6258
query = qb.build()
6359
cities = query.find()
6460
if len(cities) == 1:
6561
location = cities[0].location
66-
qb = self._box.query()
67-
qb.nearest_neighbors_f32(self._location_prop, location, num+1) # +1 for the city
68-
qb.not_equals_string(self._name_prop, city)
62+
# +1 for the city
63+
qb = self._box.query(
64+
City.location.nearest_neighbor(location, num+1) & City.name.not_equals(city)
65+
)
6966
neighbors = qb.build().find_with_scores()
7067
list_cities_with_scores(neighbors)
7168
else:
@@ -81,8 +78,9 @@ def do_neighbors(self, args):
8178
raise ValueError()
8279
num = int(args[0])
8380
geocoord = [ float(args[1]), float(args[2]) ]
84-
qb = self._box.query()
85-
qb.nearest_neighbors_f32(self._location_prop, geocoord, num)
81+
qb = self._box.query(
82+
City.location.nearest_neighbor(geocoord, num)
83+
)
8684
neighbors = qb.build().find_with_scores()
8785
list_cities_with_scores(neighbors)
8886
except ValueError:

0 commit comments

Comments
 (0)