You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromlanternimportSyncClient# Initialize the SyncClient with the database URL and table configurationDB_URL="postgresql://postgres@localhost:5432/lantern"client=SyncClient(url=DB_URL, table_name="small_world", dimensions=3, distance_type="l2sq", m=12, ef=64, ef_construction=64)
# Attempt to drop the existing table if it existstry:
client.drop()
except:
print(f"An error occurred while dropping the table: {e}")
# Create a new tableclient.create_table()
# Bulk insert data into the tableclient.bulk_insert([
("1", [0,0,0], { "name": "a" }),
("2", [0,1,0], { "name": "b" }),
("3", [0,0,1], { "name": "c" })
])
# Create an index to optimize search queriesclient.create_index()
# Retrieve a specific record by ID, selecting only certain fieldsvec_by_id=client.get_by_id(id="1", select_fields=["id", "metadata"])
assert(vec_by_id.embeddingisNone)
# Retrieve a record by ID without field restrictionsvec_by_id=client.get_by_id("1")
assert(vec_by_id.id=="1")
# Retrieve multiple records by their IDsvectors_by_ids=client.get_by_ids(["1", "3"])
assert(len(vectors_by_ids) ==2)
assert(vectors_by_ids[0].id=="1")
assert(vectors_by_ids[1].id=="3")
# Insert or update a single recordclient.upsert(("4", [1,0,0], { "name": "d" }))
# Update the metadata of a record by its IDclient.update_by_id(id="4", metadata={ "name": "4" })
# Get the total number of records in the tablerow_count=client.count()
assert(row_count==4)
# Retrieve a record by ID, selecting specific fieldsvec_by_id=client.get_by_id(id="4", select_fields=["id", "embedding", "metadata"])
assert(vec_by_id.metadata['name'] =="4")
# Search for vectors similar to the one with ID "4"vectors=client.search(query_id="4")
assert(len(vectors) ==row_count)
assert(vectors[0].id=="4")
assert(vectors[0].distance==0)
# Search for vectors using the embedding of the vector with ID "4"# Limit the results to 2 and apply a filter on the metadatavectors=client.search(query_embedding=vec_by_id.embedding, limit=2, filter={"name": "a"}, select_fields=["id"])
assert(len(vectors) ==1)
assert(vectors[0].id=="1")
assert(vectors[0].metadataisNone)
assert(vectors[0].embeddingisNone)