Demo 1 – Create Table from User Side

# Connect to Hippo 
hc = HippoClient(["ip:port"], username = "", pwd = "")
 
# Create database
db_created = hc.create_database("my_database")
 
# Create table
tbl_name = "my_test"
 
# Field declaration (field name, whether this field is primary key, data type and other params)
fields = [
    HippoField("pk", True, HippoType.INT64),
    HippoField("vector", False, HippoType.FLOAT_VECTOR, type_params = {"dimension": 2}),
    HippoField("text", False, HippoType.STRING),
    HippoField("number", False, HippoType.INT64)
]
client = hc.create_table(name = tbl_name, database_name = "my_database", fields = fields, number_of_shards = 1, number_of_replicas = 1)
 
# Create vector index
client.create_index(field_name = "vector", index_name = "vector_index",
                index_type = IndexType.IVF_FLAT, metric_type = MetricType.L2,
                nlist = 10, )
 
# Activate vector index
client.activate_index("vector_index")
 
# Insert
client.insert_rows(
    [
        [3, 4, 5],
        [[-0.1, -0.5], [0.7, 0.1], [0.1, -0.2]],
        ["how are you", "how you doing", "hello"],
        [100, 200, 300]
    ],
)
 
# Vector similarity search
result = client.query(
    "vector",
    [[0.9, 0.5]],
    ["pk", "text", "vector", "number"],
    3
)
print(result)
 
# Delete table
hc.delete_table("my_test", "my_database")
 
# Delete database
hc.delete_database("my_database")