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")
)
Metadata
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 | Provenance | Actions |
|---|---|---|---|---|
| tortoise_vector-0.2.0.tar.gz | 2.8 kB | Without provenance | Details for tortoise_vector-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tortoise_vector-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for tortoise_vector-0.2.0-py3-none-any.whl |
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
|
Security for tortoise-vector 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.