Skip to content

Commit 3f30ac0

Browse files
committed
update
1 parent 89107c5 commit 3f30ac0

2 files changed

Lines changed: 84 additions & 38 deletions

File tree

examples/gist-960-euclidean.py

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,72 +7,85 @@
77
# 3. wget http://ann-benchmarks.com/gist-960-euclidean.hdf5
88
# 4. python3 gist-960-euclidean.py
99

10-
from pyepsilla import vectordb
11-
import os, h5py, datetime
10+
import datetime
11+
import os
1212
from urllib.parse import urlparse
1313

14-
## Connect to Epsilla vector database
15-
client = vectordb.Client(host='127.0.0.1', port='8888')
16-
client.load_db(db_name="benchmark", db_path="/tmp/epsilla", vector_scale=1000000, wal_enabled=False) ## pay attention to change db_path to persistent volume for production environment
14+
import h5py
15+
from pyepsilla import vectordb
16+
17+
# Connect to Epsilla vector database
18+
client = vectordb.Client(host="127.0.0.1", port="8888")
19+
client.load_db(
20+
db_name="benchmark", db_path="/tmp/epsilla", vector_scale=1000000, wal_enabled=False
21+
) # pay attention to change db_path to persistent volume for production environment
1722
client.use_db(db_name="benchmark")
1823

19-
## Check gist-960-euclidean dataset hdf5 file to download or not
24+
# Check gist-960-euclidean dataset hdf5 file to download or not
2025
dataset_download_url = "http://ann-benchmarks.com/gist-960-euclidean.hdf5"
2126
dataset_filename = os.path.basename(urlparse(dataset_download_url).path)
2227
if not os.path.isfile(dataset_filename):
2328
os.system("wget --no-check-certificate {}".format(dataset_download_url))
2429

25-
## Read gist-960-euclidean data from hdf5
26-
f = h5py.File('gist-960-euclidean.hdf5', 'r')
30+
# Read gist-960-euclidean data from hdf5
31+
f = h5py.File("gist-960-euclidean.hdf5", "r")
2732
print(list(f.keys()))
2833
training_data = f["train"]
2934
size = training_data.size
3035
records_num, dimensions = training_data.shape
3136

32-
## Create table for gist-960-euclidean
37+
# Create table for gist-960-euclidean
3338
id_field = {"name": "id", "dataType": "INT", "primaryKey": True}
3439
vec_field = {"name": "vector", "dataType": "VECTOR_FLOAT", "dimensions": dimensions}
3540
fields = [id_field, vec_field]
3641
status_code, response = client.create_table(table_name="benchmark", table_fields=fields)
3742

38-
## Insert 20000 data into table
39-
records_data = [ {"id": i, "vector": training_data[i].tolist()} for i in range(10000)]
43+
# Insert 20000 data into table
44+
records_data = [{"id": i, "vector": training_data[i].tolist()} for i in range(10000)]
4045
client.insert(table_name="benchmark", records=records_data)
4146

42-
## Insert all data into table
43-
indexs = [ i for i in range(0, records_num+10000, 50000)]
47+
# Insert all data into table
48+
indexs = [i for i in range(0, records_num + 10000, 50000)]
4449
print("Begin to insert all gist data into table ...")
45-
for i in range(len(indexs)-1):
46-
print("-"*20)
47-
start=datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S")
48-
print(indexs[i], indexs[i+1])
49-
records_data = [{"id": i, "vector": training_data[i].tolist()} for i in range(indexs[i], indexs[i+1])]
50+
for i in range(len(indexs) - 1):
51+
print("-" * 20)
52+
start = datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S")
53+
print(indexs[i], indexs[i + 1])
54+
records_data = [
55+
{"id": i, "vector": training_data[i].tolist()}
56+
for i in range(indexs[i], indexs[i + 1])
57+
]
5058
client.insert(table_name="benchmark", records=records_data)
5159
end = datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S")
5260
print("START:", start, "\nEND :", end)
5361

5462

55-
## Delete some data by ids
63+
# Delete some data by ids
5664
# client.delete(table_name="benchmark", ids=[300033, 600066])
5765
client.delete(table_name="benchmark", ids=[9999])
5866

5967

60-
## Rebuild ann graph, it will wait until rebuild is finished, wait time is depended on the amount of dataset
68+
# Rebuild ann graph, it will wait until rebuild is finished, wait time is depended on the amount of dataset
6169
client.rebuild()
6270

63-
## Query vectors
71+
# Query vectors
6472
query_field = "vector"
6573
query_vector = training_data[40000].tolist()
6674
response_fields = ["id"]
6775
limit = 2
6876

69-
status_code, response = client.query(table_name="benchmark", query_field=query_field, query_vector=query_vector, response_fields=response_fields, limit=limit, with_distance=True)
77+
status_code, response = client.query(
78+
table_name="benchmark",
79+
query_field=query_field,
80+
query_vector=query_vector,
81+
response_fields=response_fields,
82+
limit=limit,
83+
with_distance=True,
84+
)
7085
print("Response:", response)
7186

7287

73-
## Get
88+
# Get
7489
status_code, body = client.get(table_name="benchmark")
7590
print("Status Code:", status_code)
7691
print("Size of result gotten", len(body["result"]))
77-
78-

examples/hello_epsilla_cloud_embedding.py

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
{"name": "Doc", "dataType": "STRING"},
2929
],
3030
indices=[
31-
{"name": "Index", "field": "Doc"},
32-
]
31+
{"name": "Index", "field": "Doc"},
32+
],
3333
)
3434
print(status_code, response)
3535

@@ -38,16 +38,46 @@
3838
status_code, response = db.insert(
3939
table_name="MyTable",
4040
records=[
41-
{"ID": 1, "Doc": "The garden was blooming with vibrant flowers, attracting butterflies and bees with their sweet nectar."},
42-
{"ID": 2, "Doc": "In the busy city streets, people rushed to and fro, hardly noticing the beauty of the day."},
43-
{"ID": 3, "Doc": "The library was a quiet haven, filled with the scent of old books and the soft rustling of pages."},
44-
{"ID": 4, "Doc": "High in the mountains, the air was crisp and clear, revealing breathtaking views of the valley below."},
45-
{"ID": 5, "Doc": "At the beach, children played joyfully in the sand, building castles and chasing the waves."},
46-
{"ID": 6, "Doc": "Deep in the forest, a deer cautiously stepped out, its ears alert for any signs of danger."},
47-
{"ID": 7, "Doc": "The old town's historical architecture spoke volumes about its rich cultural past."},
48-
{"ID": 8, "Doc": "Night fell, and the sky was a canvas of stars, shining brightly in the moon's soft glow."},
49-
{"ID": 9, "Doc": "A cozy cafe on the corner served the best hot chocolate, warming the hands and hearts of its visitors."},
50-
{"ID": 10, "Doc": "The artist's studio was cluttered but inspiring, filled with unfinished canvases and vibrant paints."},
41+
{
42+
"ID": 1,
43+
"Doc": "The garden was blooming with vibrant flowers, attracting butterflies and bees with their sweet nectar.",
44+
},
45+
{
46+
"ID": 2,
47+
"Doc": "In the busy city streets, people rushed to and fro, hardly noticing the beauty of the day.",
48+
},
49+
{
50+
"ID": 3,
51+
"Doc": "The library was a quiet haven, filled with the scent of old books and the soft rustling of pages.",
52+
},
53+
{
54+
"ID": 4,
55+
"Doc": "High in the mountains, the air was crisp and clear, revealing breathtaking views of the valley below.",
56+
},
57+
{
58+
"ID": 5,
59+
"Doc": "At the beach, children played joyfully in the sand, building castles and chasing the waves.",
60+
},
61+
{
62+
"ID": 6,
63+
"Doc": "Deep in the forest, a deer cautiously stepped out, its ears alert for any signs of danger.",
64+
},
65+
{
66+
"ID": 7,
67+
"Doc": "The old town's historical architecture spoke volumes about its rich cultural past.",
68+
},
69+
{
70+
"ID": 8,
71+
"Doc": "Night fell, and the sky was a canvas of stars, shining brightly in the moon's soft glow.",
72+
},
73+
{
74+
"ID": 9,
75+
"Doc": "A cozy cafe on the corner served the best hot chocolate, warming the hands and hearts of its visitors.",
76+
},
77+
{
78+
"ID": 10,
79+
"Doc": "The artist's studio was cluttered but inspiring, filled with unfinished canvases and vibrant paints.",
80+
},
5181
],
5282
)
5383
print(status_code, response)
@@ -62,7 +92,10 @@
6292

6393
# Delete specific records from table
6494
status_code, response = db.delete(table_name="MyTable", primary_keys=[4, 5])
65-
status_code, response = db.delete(table_name="MyTable", filter="Doc <> 'A cozy cafe on the corner served the best hot chocolate, warming the hands and hearts of its visitors.'")
95+
status_code, response = db.delete(
96+
table_name="MyTable",
97+
filter="Doc <> 'A cozy cafe on the corner served the best hot chocolate, warming the hands and hearts of its visitors.'",
98+
)
6699
print(status_code, response)
67100

68101
# Drop table

0 commit comments

Comments
 (0)