Skip to main content

Python client for Lantern

Project description

Python Client for Lantern

Install

pip install lantern-client

Basic usage

DB_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)
try:
  client.drop()
except:
 pass
client.create_table()
client.bulk_insert([
  ("1", [0,0,0], { "name": "a" }),
  ("2", [0,1,0], { "name": "b" }),
  ("3", [0,0,1], { "name": "c" })
])
client.create_index()

# Select specific fields
vec_by_id = client.get_by_id(id="1", select_fields=["id", "metadata"])
assert(vec_by_id.embedding == None)
# Get by id
vec_by_id = client.get_by_id("1")
assert(vec_by_id.id == "1")

# Get by ids
vectors_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 one
client.upsert(("4", [1,0,0], { "name": "d" }))

# Update
client.update_by_id(id="4", metadata={ "name": "4" })

# Get row count
row_count = client.count()
assert(row_count == 4)

vec_by_id = client.get_by_id(id="4", select_fields=["id", "embedding", "metadata"])
assert(vec_by_id.metadata.name == "4")

vectors = client.search(query_id="4")
assert(len(vectors) == row_count)
assert(vectors[0].id == "4")
assert(vectors[0].distance == 0)
vectors = 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].metadata == None)
assert(vectors[0].embedding == None)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lantern-client-0.0.2.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

lantern_client-0.0.2-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file lantern-client-0.0.2.tar.gz.

File metadata

  • Download URL: lantern-client-0.0.2.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for lantern-client-0.0.2.tar.gz
Algorithm Hash digest
SHA256 5346aa1d66d2fba5d86eb9595500961ec25e16df9217edffccb8826316a32301
MD5 f9f9fadc734fa5deca221274f99ab3ed
BLAKE2b-256 1a5b52cf58b1ad890a520a2309c9bf60a22680ed547bf44c059306609479ae3c

See more details on using hashes here.

File details

Details for the file lantern_client-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for lantern_client-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 02788f0e23357335b54b709c59a2773106558a688649b4f00ce7b90fb24f6ac8
MD5 6609ba0d67763ffc1dc8161d583927c0
BLAKE2b-256 35f8b5c5f2ba4c8e95dc9826b712a587be9253794699ea27c7d4bd0fbfa43707

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page