pgvector implementation for Tortoise-ORM
Project description
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")
)
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tortoise_vector-0.2.0.tar.gz.
File metadata
- Download URL: tortoise_vector-0.2.0.tar.gz
- Upload date:
- Size: 2.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.0.1 CPython/3.13.7 Linux/6.16.3-arch1-1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
27692a5c8cd579809ac57f576c4400f53299403728e0d38ac62bc685c839c024
|
|
| MD5 |
d4df48590dafda92676c3789c8ae976c
|
|
| BLAKE2b-256 |
f16d223d85c2f854371927f2ca6d76bbf82ba32a59a449c96bdd95e18c8739de
|
File details
Details for the file tortoise_vector-0.2.0-py3-none-any.whl.
File metadata
- Download URL: tortoise_vector-0.2.0-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.0.1 CPython/3.13.7 Linux/6.16.3-arch1-1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
38e9b89e2357312653cd8348f92f21771716473b3922d35a13720130fb9f2fee
|
|
| MD5 |
a822a391a4a9d755af6527d31daa4294
|
|
| BLAKE2b-256 |
eec64093934eb0baca06c3fd7c171aecc3b2c8692ec7ca403728d49481aad8b2
|