Name | tortoise-vector JSON |
Version |
0.1.3
JSON |
| download |
home_page | None |
Summary | pgvector implementation for Tortoise-ORM |
upload_time | 2025-02-04 16:37:03 |
maintainer | None |
docs_url | None |
author | Sebastien Nicolet |
requires_python | <4.0,>=3.11 |
license | MIT |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# 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:
```python
from tortoise_vector.field import VectorField
from tortoise_vector.expressions import CosineSimilarity
from tortoise import Model
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(str: 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")
)
```
Raw data
{
"_id": null,
"home_page": null,
"name": "tortoise-vector",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.11",
"maintainer_email": null,
"keywords": null,
"author": "Sebastien Nicolet",
"author_email": "snicolet95@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/55/23/256a0a520a0922b8e973460cf4e136d13252128151b55197a6a93db50e41/tortoise_vector-0.1.3.tar.gz",
"platform": null,
"description": "# Implementation of vector for Tortoise-ORM\nThis package adds the support of `pgvector` vectors to Tortoise-ORM as a new type of fields.\nThat way you can filter/order by cosine similarity distances for scementic search using embeddings.\nHere's an example for openai's embeddings but this will work with any kind of embeddings.\nUsage:\n\n```python\nfrom tortoise_vector.field import VectorField\nfrom tortoise_vector.expressions import CosineSimilarity\nfrom tortoise import Model\n\n\nOPENAI_VECTOR_SIZE = 1536\n\n\nclass MyModel(Model):\n # vectors have a fixed size, openai uses 1536 dimensions\n embedding = VectorField(vector_size=OPENAI_VECTOR_SIZE)\n\n\n\nasync def get_embedding_from_text(str: str) -> list[float]:\n ...\n\n\nasync def get_nearst_models(text: str) -> Queryset[MyModel]:\n embedding = await get_embedding_from_text(text)\n return (\n MyModel\n .all()\n .annotate(\n distance=CosineSimilarity(\n \"embedding\",\n embedding,\n OPENAI_VECTOR_SIZE\n )\n )\n .order_by(\"distance\")\n )\n```\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "pgvector implementation for Tortoise-ORM",
"version": "0.1.3",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "6ddf87713555facbddcfa61db456efde6beffce069d5145288a0c50d1af77425",
"md5": "6e752b666b587bd271973a287d0a7533",
"sha256": "0ab39c43946749936a346a5d663c066afa053b79419c5340d40e0db5b260afd1"
},
"downloads": -1,
"filename": "tortoise_vector-0.1.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "6e752b666b587bd271973a287d0a7533",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.11",
"size": 3413,
"upload_time": "2025-02-04T16:37:01",
"upload_time_iso_8601": "2025-02-04T16:37:01.846767Z",
"url": "https://files.pythonhosted.org/packages/6d/df/87713555facbddcfa61db456efde6beffce069d5145288a0c50d1af77425/tortoise_vector-0.1.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "5523256a0a520a0922b8e973460cf4e136d13252128151b55197a6a93db50e41",
"md5": "21c444a578dd38743f583a1fab7d449f",
"sha256": "ed3df8ce0047ffbf89237a0f2958fa4c084feaea31340a31c7ddb99e36b48159"
},
"downloads": -1,
"filename": "tortoise_vector-0.1.3.tar.gz",
"has_sig": false,
"md5_digest": "21c444a578dd38743f583a1fab7d449f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.11",
"size": 2439,
"upload_time": "2025-02-04T16:37:03",
"upload_time_iso_8601": "2025-02-04T16:37:03.581907Z",
"url": "https://files.pythonhosted.org/packages/55/23/256a0a520a0922b8e973460cf4e136d13252128151b55197a6a93db50e41/tortoise_vector-0.1.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-04 16:37:03",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "tortoise-vector"
}