Django client for Lantern
Project description
Django Client for Lantern
Install
pip install lantern-django
Basic usage
Create a migration to enable the extensions:
from django.db import migrations
from lantern_django import LanternExtension, LanternExtrasExtension
class Migration(migrations.Migration):
operations = [
LanternExtension(),
LanternExtrasExtension(),
]
Add a REAL[]
field to your model
from django.db import models
from django.contrib.postgres.fields import ArrayField
from lantern_django import RealField
class Item(models.Model):
embedding = ArrayField(RealField(), size=3, null=True)
Insert a vector
item = Item(embedding=[1, 2, 3])
item.save()
Get the nearest neighbors to a vector
from lantern_django import L2Distance
Item.objects.order_by(L2Distance('embedding', [3, 1, 2]))[:5]
Get nearest neighbors to a text embedding
distance = L2Distance('embedding', TextEmbedding(
'BAAI/bge-small-en', 'hello'))
results = Item.objects.annotate(distance=distance).order_by('distance')[:5]
Get the distance
Item.objects.annotate(distance=L2Distance('embedding', [3, 1, 2]))
Get items within a certain distance
Item.objects.alias(distance=L2Distance('embedding', [3, 1, 2])).filter(distance__lt=5)
Add an index
from lantern_django import HnswIndex
class Item(models.Model):
class Meta:
indexes = [
HnswIndex(
name='hnsw_idx',
fields=['embedding'],
m=16,
ef=64,
ef_construction=64,
dim=384,
opclasses=['dist_l2sq_ops']
)
]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file lantern_django-0.0.1.tar.gz
.
File metadata
- Download URL: lantern_django-0.0.1.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ebe3ec98de7352354de2df78fb3ee14b1022ef6889063a0bf313b532569a862b |
|
MD5 | 022095f714939db453388f72d50dd3d1 |
|
BLAKE2b-256 | 9f76549adc6eff1a529c96c649ef3f4002c364fc1fd8fe9867479d9c3b3e3896 |
Provenance
The following attestation bundles were made for lantern_django-0.0.1.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_django-0.0.1.tar.gz
- Subject digest:
ebe3ec98de7352354de2df78fb3ee14b1022ef6889063a0bf313b532569a862b
- Sigstore transparency entry: 147008465
- Sigstore integration time:
- Predicate type:
File details
Details for the file lantern_django-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: lantern_django-0.0.1-py3-none-any.whl
- Upload date:
- Size: 4.5 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 | d03dbbae2a3c2d91b9daf968abf8542700d9e90aa81665d6b4a6f24b1e248284 |
|
MD5 | 040384cbce48aa228034f631f9d77a64 |
|
BLAKE2b-256 | c244725fd4047998a22b8253e6fdae8f689347b8857a97759d9beb4eda4249b3 |
Provenance
The following attestation bundles were made for lantern_django-0.0.1-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_django-0.0.1-py3-none-any.whl
- Subject digest:
d03dbbae2a3c2d91b9daf968abf8542700d9e90aa81665d6b4a6f24b1e248284
- Sigstore transparency entry: 147008466
- Sigstore integration time:
- Predicate type: