Implementation of vector for Tortoise-ORM
This package adds the support of pgvector vectors to Tortoise-ORM as a new type of fields.
That way you can filter/order by cosine similarity distances for scementic search using embeddings.
Here's an example for openai's embeddings but this will work with any kind of embeddings.
Usage:
from tortoise.models import Model, QuerySet
from tortoise_vector.field import VectorField
from tortoise_vector.expression import CosineSimilarity
OPENAI_VECTOR_SIZE = 1536
class MyModel(Model):
# vectors have a fixed size, openai uses 1536 dimensions
embedding = VectorField(vector_size=OPENAI_VECTOR_SIZE)
async def get_embedding_from_text(string: str) -> list[float]:
...
async def get_nearst_models(text: str) -> QuerySet[MyModel]:
embedding = await get_embedding_from_text(text)
return (
MyModel
.all()
.annotate(
distance=CosineSimilarity(
"embedding",
embedding,
OPENAI_VECTOR_SIZE
)
)
.order_by("distance")
)
Release files for tortoise-vector 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tortoise_vector-0.2.0.tar.gz | 2.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tortoise_vector-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.7 kB
Release files / tortoise_vector-0.2.0.tar.gz
| Download URL | tortoise_vector-0.2.0.tar.gz |
|---|---|
| Size | 2.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
27692a5c8cd579809ac57f576c4400f53299403728e0d38ac62bc685c839c024
|
|
BLAKE2b-256 checksum How to use checksums |
f16d223d85c2f854371927f2ca6d76bbf82ba32a59a449c96bdd95e18c8739de
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.0.1 CPython/3.13.7 Linux/6.16.3-arch1-1
|
Release files / tortoise_vector-0.2.0-py3-none-any.whl
| Download URL | tortoise_vector-0.2.0-py3-none-any.whl |
|---|---|
| Size | 3.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
38e9b89e2357312653cd8348f92f21771716473b3922d35a13720130fb9f2fee
|
|
BLAKE2b-256 checksum How to use checksums |
eec64093934eb0baca06c3fd7c171aecc3b2c8692ec7ca403728d49481aad8b2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.0.1 CPython/3.13.7 Linux/6.16.3-arch1-1
|