Python client for Lantern
Project description
Python Client for Lantern
Install
pip install lantern-client
Basic usage
from lantern import SyncClient
# Initialize the SyncClient with the database URL and table configuration
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)
# Attempt to drop the existing table if it exists
try:
client.drop()
except:
print(f"An error occurred while dropping the table: {e}")
# Create a new table
client.create_table()
# Bulk insert data into the table
client.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 queries
client.create_index()
# Retrieve a specific record by ID, selecting only certain fields
vec_by_id = client.get_by_id(id="1", select_fields=["id", "metadata"])
assert(vec_by_id.embedding is None)
# Retrieve a record by ID without field restrictions
vec_by_id = client.get_by_id("1")
assert(vec_by_id.id == "1")
# Retrieve multiple records by their 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 or update a single record
client.upsert(("4", [1,0,0], { "name": "d" }))
# Update the metadata of a record by its ID
client.update_by_id(id="4", metadata={ "name": "4" })
# Get the total number of records in the table
row_count = client.count()
assert(row_count == 4)
# Retrieve a record by ID, selecting specific fields
vec_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 metadata
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 is None)
assert(vectors[0].embedding is 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.6.tar.gz
(8.5 kB
view details)
Built Distribution
File details
Details for the file lantern_client-0.0.6.tar.gz
.
File metadata
- Download URL: lantern_client-0.0.6.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f58483f9974184c6861a967b5f29b4bc004c1b55b693fcc71706c63fcdedca9 |
|
MD5 | a9bc4508d1e6e78e726c3582f11f78c9 |
|
BLAKE2b-256 | 18bb64f90ff4afd07721f24bfc94fbc6892810bc63d00903d4bf53aa550ad31e |
Provenance
The following attestation bundles were made for lantern_client-0.0.6.tar.gz
:
Publisher:
publish.yml
on lanterndata/lantern-python
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
lantern_client-0.0.6.tar.gz
- Subject digest:
8f58483f9974184c6861a967b5f29b4bc004c1b55b693fcc71706c63fcdedca9
- Sigstore transparency entry: 147008472
- Sigstore integration time:
- Predicate type:
File details
Details for the file lantern_client-0.0.6-py3-none-any.whl
.
File metadata
- Download URL: lantern_client-0.0.6-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 317ecc3c9c4faf878124a7caf5b6708ed691345a330d349754ef0ae38536277a |
|
MD5 | 1775196caa8b643158bc044b00a33b1a |
|
BLAKE2b-256 | 877e16d8435e7946271f1dd04a143fc1fac1b45234464a0557684cda498ed5b3 |
Provenance
The following attestation bundles were made for lantern_client-0.0.6-py3-none-any.whl
:
Publisher:
publish.yml
on lanterndata/lantern-python
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
lantern_client-0.0.6-py3-none-any.whl
- Subject digest:
317ecc3c9c4faf878124a7caf5b6708ed691345a330d349754ef0ae38536277a
- Sigstore transparency entry: 147008474
- Sigstore integration time:
- Predicate type: