tortoise-vector


Nametortoise-vector JSON
Version 0.1.2 PyPI version JSON
download
home_pageNone
Summarypgvector implementation for Tortoise-ORM
upload_time2024-11-12 20:45:49
maintainerNone
docs_urlNone
authorSebastien Nicolet
requires_python<4.0,>=3.11
licenseMIT
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/7b/8c/9030b3fef664f44fc90af7fa8f2f09321d3f3eb67dcf6932f88898b6c8ee/tortoise_vector-0.1.2.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.2",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "67ede0f8880e7e0db16d0c31293c67281f61398f14e775a0f3b3008c198a51e9",
                "md5": "cc3328d840e00e11f5ed5603ad31bc75",
                "sha256": "983ccffd07fa9b7964ebe962374162ca1c92954d660e713e7cca6c8f76a786a0"
            },
            "downloads": -1,
            "filename": "tortoise_vector-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "cc3328d840e00e11f5ed5603ad31bc75",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.11",
            "size": 3415,
            "upload_time": "2024-11-12T20:45:47",
            "upload_time_iso_8601": "2024-11-12T20:45:47.455362Z",
            "url": "https://files.pythonhosted.org/packages/67/ed/e0f8880e7e0db16d0c31293c67281f61398f14e775a0f3b3008c198a51e9/tortoise_vector-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7b8c9030b3fef664f44fc90af7fa8f2f09321d3f3eb67dcf6932f88898b6c8ee",
                "md5": "b58f6d206b9421438f23151374886a2d",
                "sha256": "6eaba0ce416a5fdcf0c1844bde75f9acf691d255ada86fe8e20f56c43f91755e"
            },
            "downloads": -1,
            "filename": "tortoise_vector-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "b58f6d206b9421438f23151374886a2d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.11",
            "size": 2545,
            "upload_time": "2024-11-12T20:45:49",
            "upload_time_iso_8601": "2024-11-12T20:45:49.432654Z",
            "url": "https://files.pythonhosted.org/packages/7b/8c/9030b3fef664f44fc90af7fa8f2f09321d3f3eb67dcf6932f88898b6c8ee/tortoise_vector-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-12 20:45:49",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "tortoise-vector"
}
        
Elapsed time: 0.35476s