Skip to content

Commit 494e81b

Browse files
committed
Ollama example: add some prints to report status #43
Since it may take a while, it's good to show some progress. Also, remove the DB on start, and use Cosine similarity
1 parent 6ab924d commit 494e81b

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

example/ollama/llamas.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from objectbox.model.properties import *
1919
import numpy as np
2020

21+
obx_remove_db_files(c_str("objectbox")) # Have fresh data for each start
2122

2223
@Entity(id=1, uid=1)
2324
class DocumentEmbedding:
@@ -26,7 +27,7 @@ class DocumentEmbedding:
2627
embedding = Property(np.ndarray, type=PropertyType.floatVector, id=3, uid=1003, index=HnswIndex(
2728
id=3, uid=10001,
2829
dimensions=1024,
29-
distance_type=HnswDistanceType.EUCLIDEAN
30+
distance_type=HnswDistanceType.COSINE
3031
))
3132

3233
model = Model()
@@ -37,13 +38,15 @@ class DocumentEmbedding:
3738
ob = objectbox.Builder().model(model).build()
3839
box = objectbox.Box(ob, DocumentEmbedding)
3940

41+
print("Documents to embed: ", len(documents))
4042

4143
# store each document in a vector embedding database
4244
for i, d in enumerate(documents):
4345
response = ollama.embeddings(model="mxbai-embed-large", prompt=d)
4446
embedding = response["embedding"]
4547

4648
box.put(DocumentEmbedding(document=d,embedding=embedding))
49+
print(f"Document {i + 1} embedded")
4750

4851
# an example prompt
4952
prompt = "What animals are llamas related to?"
@@ -63,6 +66,9 @@ class DocumentEmbedding:
6366
results = query.find_with_scores()
6467
data = results[0][0].document
6568

69+
print(f"Data most relevant to \"{prompt}\" : {data}")
70+
71+
print("Generating the response now...")
6672

6773
# generate a response combining the prompt and data we retrieved in step 2
6874
output = ollama.generate(

0 commit comments

Comments
 (0)