|
| 1 | +#!/usr/bin/env python |
| 2 | +# -*- coding:utf-8 -*- |
| 3 | + |
| 4 | +import time |
| 5 | + |
| 6 | +from pyepsilla import enterprise |
| 7 | + |
| 8 | +# Connect to Epsilla Enterprise API EndPoint |
| 9 | +client = enterprise.Client(base_url="https://api.epsilla.com") |
| 10 | +client.hello() |
| 11 | + |
| 12 | +# Get DB List |
| 13 | +# db_list = client.get_db_list() |
| 14 | +# print("db_list:", db_list) |
| 15 | + |
| 16 | +db_name = "helloepsilla" |
| 17 | +db_id = "helloepsilla-1234567890" |
| 18 | +table_name = "HelloEpsilla" |
| 19 | + |
| 20 | + |
| 21 | +# Create a new db |
| 22 | +status_code, response = client.create_db(db_name, db_id) |
| 23 | +print(status_code, response) |
| 24 | + |
| 25 | +# Get info of db |
| 26 | +status_code, response = client.get_db_info(db_id) |
| 27 | +print(status_code, response) |
| 28 | + |
| 29 | +time.sleep(5) |
| 30 | +# Load db |
| 31 | +status_code, response = client.load_db(db_id) |
| 32 | +print(status_code, response) |
| 33 | + |
| 34 | +# Connect to an existing db |
| 35 | +db = client.vectordb(db_id) |
| 36 | + |
| 37 | +# Create table with schema |
| 38 | +status_code, response = db.create_table( |
| 39 | + table_name="MyTable", |
| 40 | + table_fields=[ |
| 41 | + {"name": "ID", "dataType": "INT", "primaryKey": True}, |
| 42 | + {"name": "Doc", "dataType": "STRING"}, |
| 43 | + {"name": "Embedding", "dataType": "VECTOR_FLOAT", "dimensions": 4}, |
| 44 | + ], |
| 45 | +) |
| 46 | +print(status_code, response) |
| 47 | + |
| 48 | + |
| 49 | +# Insert new vector records into table |
| 50 | +status_code, response = db.insert( |
| 51 | + table_name="MyTable", |
| 52 | + records=[ |
| 53 | + {"ID": 11, "Doc": "Berlin", "Embedding": [0.05, 0.61, 0.76, 0.74]}, |
| 54 | + {"ID": 12, "Doc": "London", "Embedding": [0.19, 0.81, 0.75, 0.11]}, |
| 55 | + {"ID": 13, "Doc": "Moscow", "Embedding": [0.36, 0.55, 0.47, 0.94]}, |
| 56 | + {"ID": 14, "Doc": "San Francisco", "Embedding": [0.18, 0.01, 0.85, 0.80]}, |
| 57 | + {"ID": 15, "Doc": "Shanghai", "Embedding": [0.24, 0.18, 0.22, 0.44]}, |
| 58 | + ], |
| 59 | +) |
| 60 | +print(status_code, response) |
| 61 | + |
| 62 | +# Query Vectors with specific response field |
| 63 | +status_code, response = db.query( |
| 64 | + table_name="MyTable", |
| 65 | + query_field="Embedding", |
| 66 | + query_vector=[0.35, 0.55, 0.47, 0.94], |
| 67 | + response_fields=["Doc"], |
| 68 | + limit=2, |
| 69 | +) |
| 70 | +print(status_code, response) |
| 71 | + |
| 72 | +# Query Vectors without specific response field, then it will return all fields |
| 73 | +status_code, response = db.query( |
| 74 | + table_name="MyTable", |
| 75 | + query_field="Embedding", |
| 76 | + query_vector=[0.35, 0.55, 0.47, 0.94], |
| 77 | + limit=2, |
| 78 | +) |
| 79 | +print(status_code, response) |
| 80 | + |
| 81 | +# Get |
| 82 | +status_code, response = db.get( |
| 83 | + table_name="MyTable", |
| 84 | + response_fields=["Doc", "Embedding"], |
| 85 | + filter="Doc <> 'San Francisco'", |
| 86 | + limit=5, |
| 87 | +) |
| 88 | +print(status_code, response) |
| 89 | + |
| 90 | + |
| 91 | +# Delete specific records from table |
| 92 | +status_code, response = db.delete(table_name="MyTable", primary_keys=[4, 5]) |
| 93 | +print(status_code, response) |
| 94 | +status_code, response = db.delete(table_name="MyTable", filter="Doc <> 'San Francisco'") |
| 95 | +print(status_code, response) |
| 96 | + |
| 97 | + |
| 98 | +# Drop table |
| 99 | +status_code, response = db.drop_table("MyTable") |
| 100 | +print(response) |
| 101 | + |
| 102 | +# Delete db |
| 103 | +status_code, response = client.drop_db(db_id) |
| 104 | +print(status_code, response) |
0 commit comments