Skip to content

Commit a44f907

Browse files
authored
Merge pull request #51 from shru0405/Python-cloud
Added JSON serialization and method calls in hello_epsilla,py
2 parents 11493ab + 89cc5de commit a44f907

1 file changed

Lines changed: 79 additions & 0 deletions

File tree

hello_epsilla_cloud_embedding.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import sys
2+
import json
3+
4+
try:
5+
from pyepsilla import cloud
6+
except ImportError as e:
7+
print("Failed to import pyepsilla. Ensure the library is installed.")
8+
sys.exit(1)
9+
10+
try:
11+
# Connect to Epsilla Cloud
12+
client = cloud.Client(
13+
project_id="project-id",
14+
api_key="epsilla-cloud-api-key",
15+
)
16+
17+
# Connect to Vectordb
18+
db = client.vectordb(db_id="6accafb1-476d-43b0-aa64-12ebfbf7442d")
19+
20+
# Data for creating table
21+
table_fields = [
22+
{"name": "ID", "dataType": "INT", "primaryKey": True},
23+
{"name": "Doc", "dataType": "STRING"},
24+
{"name": "Embedding", "dataType": "VECTOR_FLOAT", "dimensions": 4},
25+
]
26+
print("Table fields:", table_fields)
27+
28+
# Create a table with schema
29+
status_code, response = db.create_table(
30+
table_name="MyTable",
31+
table_fields=table_fields,
32+
)
33+
print(status_code, response)
34+
35+
# Data for inserting records
36+
records = [
37+
{"ID": 1, "Doc": "Berlin", "Embedding": [0.05, 0.61, 0.76, 0.74]},
38+
{"ID": 2, "Doc": "London", "Embedding": [0.19, 0.81, 0.75, 0.11]},
39+
{"ID": 3, "Doc": "Moscow", "Embedding": [0.36, 0.55, 0.47, 0.94]},
40+
{"ID": 4, "Doc": "San Francisco", "Embedding": [0.18, 0.01, 0.85, 0.80]},
41+
{"ID": 5, "Doc": "Shanghai", "Embedding": [0.24, 0.18, 0.22, 0.44]},
42+
]
43+
print("Records:", records)
44+
45+
# Insert new vector records into table
46+
status_code, response = db.insert(
47+
table_name="MyTable",
48+
records=records,
49+
)
50+
print(status_code, response)
51+
52+
# Query parameters
53+
query_vector = [0.35, 0.55, 0.47, 0.94]
54+
print("Query vector:", query_vector)
55+
56+
# Query Vectors with specific response field, otherwise it will return all fields
57+
status_code, response = db.query(
58+
table_name="MyTable",
59+
query_field="Embedding",
60+
query_vector=query_vector,
61+
response_fields=["Doc"],
62+
limit=2,
63+
)
64+
print(status_code, response)
65+
66+
# Delete specific records from table
67+
primary_keys_to_delete = [4, 5]
68+
print("Primary keys to delete:", primary_keys_to_delete)
69+
status_code, response = db.delete(table_name="MyTable", primary_keys=primary_keys_to_delete)
70+
print(status_code, response)
71+
status_code, response = db.delete(table_name="MyTable", filter="Doc <> 'San Francisco'")
72+
print(status_code, response)
73+
74+
# Drop table
75+
status_code, response = db.drop_table(table_name="MyTable")
76+
print(status_code, response)
77+
except Exception as e:
78+
print(f"An error occurred: {e}")
79+

0 commit comments

Comments
 (0)