Skip to content

Commit b6da3f4

Browse files
committed
fix the bug in example
Signed-off-by: Eric <eric@epsilla.com>
1 parent d8b170c commit b6da3f4

1 file changed

Lines changed: 29 additions & 21 deletions

File tree

examples/hello_epsilla_cloud.py

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,40 @@
66
# 2. create a table with schema in db
77
# 3. get the epsilla cloud api key with project id, run this program
88

9-
import sys
109
import os
10+
import sys
11+
1112
from pyepsilla import cloud
1213

13-
project_id = os.getenv("EPSILLA_PROJECT_ID", "Your-Project-ID")
14-
epsilla_api_key = os.getenv("EPSILLA_API_KEY", "Your-Epsilla-API-Key")
15-
db_id = os.getenv("EPSILLA_DB_ID", "Your-DB-ID")
14+
EPSILLA_PROJECT_ID = os.getenv("EPSILLA_PROJECT_ID", "Your-Project-ID")
15+
EPSILLA_API_KEY = os.getenv("EPSILLA_API_KEY", "Your-Epsilla-API-Key")
16+
17+
DB_ID = os.getenv("DB_ID", "Your-DB-ID")
18+
DB_NAME = os.getenv("DB_NAME", "MyDB")
19+
DB_PATH = os.getenv("DB_PATH", "/tmp/epsilla_demo")
20+
TABLE_NAME = os.getenv("TABLE_NAME", "MyTable")
21+
1622

17-
if not project_id or not api_key or not db_id:
18-
print("Please set the environment variables: EPSILLA_PROJECT_ID, EPSILLA_API_KEY, EPSILLA_DB_ID")
23+
if not EPSILLA_PROJECT_ID or not EPSILLA_API_KEY or not DB_ID:
24+
print(
25+
"Please set the environment variables: EPSILLA_PROJECT_ID, EPSILLA_API_KEY, DB_ID"
26+
)
1927
sys.exit(1)
2028

2129
# Connect to Epsilla Cloud
2230
cloud_client = cloud.Client(
23-
project_id=project_id,
24-
api_key=epsilla_api_key,
31+
project_id=EPSILLA_PROJECT_ID,
32+
api_key=EPSILLA_API_KEY,
2533
)
2634

2735
# Connect to Vectordb
28-
db_cloud = cloud_client.vectordb(db_id=db_id)
29-
36+
db_client = cloud_client.vectordb(db_id=DB_ID)
3037

3138

3239
try:
3340
# Create a table with schema
34-
status_code, response = db.create_table(
35-
table_name="MyTable",
41+
status_code, response = db_client.create_table(
42+
table_name=TABLE_NAME,
3643
table_fields=[
3744
{"name": "ID", "dataType": "INT", "primaryKey": True},
3845
{"name": "Doc", "dataType": "STRING"},
@@ -44,8 +51,8 @@
4451
raise Exception("Failed to create table")
4552

4653
# Insert new vector records into table
47-
status_code, response = db.insert(
48-
table_name="MyTable",
54+
status_code, response = db_client.insert(
55+
table_name=TABLE_NAME,
4956
records=[
5057
{"ID": 1, "Doc": "Berlin", "Embedding": [0.05, 0.61, 0.76, 0.74]},
5158
{"ID": 2, "Doc": "London", "Embedding": [0.19, 0.81, 0.75, 0.11]},
@@ -59,8 +66,8 @@
5966
raise Exception("Failed to insert records")
6067

6168
# Query Vectors with specific response field, otherwise it will return all fields
62-
status_code, response = db.query(
63-
table_name="MyTable",
69+
status_code, response = db_client.query(
70+
table_name=TABLE_NAME,
6471
query_field="Embedding",
6572
query_vector=[0.35, 0.55, 0.47, 0.94],
6673
response_fields=["Doc"],
@@ -70,23 +77,24 @@
7077
if status_code != 200:
7178
raise Exception("Failed to query table")
7279

73-
7480
# Delete specific records from table
75-
status_code, response = db.delete(table_name="MyTable", primary_keys=[4, 5])
81+
status_code, response = db_client.delete(table_name=TABLE_NAME, primary_keys=[4, 5])
7682
print(status_code, response)
7783
if status_code != 200:
7884
raise Exception("Failed to delete records by primary keys")
7985

80-
status_code, response = db.delete(table_name="MyTable", filter="Doc <> 'San Francisco'")
86+
status_code, response = db_client.delete(
87+
table_name=TABLE_NAME, filter="Doc <> 'San Francisco'"
88+
)
8189
print(status_code, response)
8290
if status_code != 200:
8391
raise Exception("Failed to delete records by filter")
8492

8593
# Drop table
86-
status_code, response = db.drop_table(table_name="MyTable")
94+
status_code, response = db_client.drop_table(table_name=TABLE_NAME)
8795
print(status_code, response)
8896
if status_code != 200:
8997
raise Exception("Failed to drop table")
9098
except Exception as e:
9199
print(f"An error occurred: {e}")
92-
sys.exit(1)
100+
sys.exit(1)

0 commit comments

Comments
 (0)