async-annoy


Nameasync-annoy JSON
Version 0.3.0 PyPI version JSON
download
home_pagehttps://github.com/ryzhakar/async-annoy
SummaryAsynchronous wrapper around the Annoy library for approximate nearest neighbor search.
upload_time2024-06-23 21:01:44
maintainerNone
docs_urlNone
authorArthur Ryzhak
requires_python<4.0,>=3.10
licenseMIT
keywords annoy asynchronous nearest neighbors semantic search vector database search aiorwlock
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # async-annoy README

## Overview
`async-annoy` simplifies working with Annoy indices in async applications like web servers. It's built to let you read from or write to Annoy indices without worrying about the complexities of concurrent access. You get easy, thread-safe operations, whether you're querying nearest neighbors or building the index, all in the background.

## Features
- **Automated Index Management**: Handles all the tricky parts of managing Annoy indices on disk.
- **Concurrency Made Simple**: Supports multiple readers at once or a single writer by managing access locks behind the scenes.

## Installation
```bash
pip install async-annoy
```
Make sure Annoy and numpy are installed as they're needed to run the library.

## How to Use
### Reading from the Index
Ideal for fetching nearest neighbors in response to web requests.
```python
from async_annoy import AsyncAnnoy

async with AsyncAnnoy("my_index").reader() as reader:
    neighbours = await reader.get_neighbours_for(vector=my_vector, n=5)
    print(neighbours)
```
### Writing to the Index
The writer will wait for all readers to finish and start the index from scratch.
The Annoy library doesn't support index updates, only rebuilds.
```python
from async_annoy import AsyncAnnoy

async with AsyncAnnoy("my_index").writer() as writer:
    await writer.add_item(index=1, vector=my_vector)
    # The index is automatically built and saved when done.
```
## Configuration
The initial setup of `async-annoy` relies on environment variables to configure the Annoy index parameters, ensuring a seamless start. While these defaults offer convenience, you may need to customize settings to fit your application's specific requirements. It's critical to maintain parameter consistency across all readers and writers interacting with the same index.

### Default Parameters
`async-annoy` uses the following environment variables for initial configuration:
- `ASYNC_ANNOY_DIMENSIONS`: The dimensionality of the vectors stored in the index.
- `ASYNC_ANNOY_METRIC`: The distance metric used for comparing vectors in the index (e.g., "angular", "euclidean").

### Overriding Default Parameters
Although `async-annoy` configures itself with environment variables, you can override these defaults directly in your code. When creating a new `AnnoyReader` or `AnnoyWriter`, simply pass the desired dimensions and metric as arguments:

```python
from async_annoy import AsyncAnnoy

# Override default parameters when initializing
index_manager = AsyncAnnoy("my_index", dimensions=128, metric="euclidean")
```

## Development Status
Currently, async-annoy is in alpha. It's ready for testing, and we're eager for your feedback to make it better. This is an initial version, so we're still working on adding more features and smoothing out the experience.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ryzhakar/async-annoy",
    "name": "async-annoy",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": "annoy, asynchronous, nearest neighbors, semantic search, vector database, search, aiorwlock",
    "author": "Arthur Ryzhak",
    "author_email": "ryzhakar@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/51/37/7a515c4e40d6cacb2fee0416dea9a82441c83cade5c858f1bcef4d598a99/async_annoy-0.3.0.tar.gz",
    "platform": null,
    "description": "# async-annoy README\n\n## Overview\n`async-annoy` simplifies working with Annoy indices in async applications like web servers. It's built to let you read from or write to Annoy indices without worrying about the complexities of concurrent access. You get easy, thread-safe operations, whether you're querying nearest neighbors or building the index, all in the background.\n\n## Features\n- **Automated Index Management**: Handles all the tricky parts of managing Annoy indices on disk.\n- **Concurrency Made Simple**: Supports multiple readers at once or a single writer by managing access locks behind the scenes.\n\n## Installation\n```bash\npip install async-annoy\n```\nMake sure Annoy and numpy are installed as they're needed to run the library.\n\n## How to Use\n### Reading from the Index\nIdeal for fetching nearest neighbors in response to web requests.\n```python\nfrom async_annoy import AsyncAnnoy\n\nasync with AsyncAnnoy(\"my_index\").reader() as reader:\n    neighbours = await reader.get_neighbours_for(vector=my_vector, n=5)\n    print(neighbours)\n```\n### Writing to the Index\nThe writer will wait for all readers to finish and start the index from scratch.\nThe Annoy library doesn't support index updates, only rebuilds.\n```python\nfrom async_annoy import AsyncAnnoy\n\nasync with AsyncAnnoy(\"my_index\").writer() as writer:\n    await writer.add_item(index=1, vector=my_vector)\n    # The index is automatically built and saved when done.\n```\n## Configuration\nThe initial setup of `async-annoy` relies on environment variables to configure the Annoy index parameters, ensuring a seamless start. While these defaults offer convenience, you may need to customize settings to fit your application's specific requirements. It's critical to maintain parameter consistency across all readers and writers interacting with the same index.\n\n### Default Parameters\n`async-annoy` uses the following environment variables for initial configuration:\n- `ASYNC_ANNOY_DIMENSIONS`: The dimensionality of the vectors stored in the index.\n- `ASYNC_ANNOY_METRIC`: The distance metric used for comparing vectors in the index (e.g., \"angular\", \"euclidean\").\n\n### Overriding Default Parameters\nAlthough `async-annoy` configures itself with environment variables, you can override these defaults directly in your code. When creating a new `AnnoyReader` or `AnnoyWriter`, simply pass the desired dimensions and metric as arguments:\n\n```python\nfrom async_annoy import AsyncAnnoy\n\n# Override default parameters when initializing\nindex_manager = AsyncAnnoy(\"my_index\", dimensions=128, metric=\"euclidean\")\n```\n\n## Development Status\nCurrently, async-annoy is in alpha. It's ready for testing, and we're eager for your feedback to make it better. This is an initial version, so we're still working on adding more features and smoothing out the experience.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Asynchronous wrapper around the Annoy library for approximate nearest neighbor search.",
    "version": "0.3.0",
    "project_urls": {
        "Homepage": "https://github.com/ryzhakar/async-annoy",
        "Repository": "https://github.com/ryzhakar/async-annoy"
    },
    "split_keywords": [
        "annoy",
        " asynchronous",
        " nearest neighbors",
        " semantic search",
        " vector database",
        " search",
        " aiorwlock"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6e544ae2ff2ed5cd41725e44a9f49470e8ce0fd4e4e957bd179908946873d850",
                "md5": "c94d759df8056edd1fc325632d9b2b09",
                "sha256": "7ef8388d2ded2ee5f5b4378b67c6e6b6c06f86881cc013d389a355cc472d54bf"
            },
            "downloads": -1,
            "filename": "async_annoy-0.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c94d759df8056edd1fc325632d9b2b09",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 5457,
            "upload_time": "2024-06-23T21:01:43",
            "upload_time_iso_8601": "2024-06-23T21:01:43.222050Z",
            "url": "https://files.pythonhosted.org/packages/6e/54/4ae2ff2ed5cd41725e44a9f49470e8ce0fd4e4e957bd179908946873d850/async_annoy-0.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "51377a515c4e40d6cacb2fee0416dea9a82441c83cade5c858f1bcef4d598a99",
                "md5": "6f94aa466cc8b71da79b811a0b0d2d7a",
                "sha256": "5b3efbdd4f1996ac0b1b1e66c99a66b3d2bfd053feef944b40c7a088d5e1a6b3"
            },
            "downloads": -1,
            "filename": "async_annoy-0.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "6f94aa466cc8b71da79b811a0b0d2d7a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 4767,
            "upload_time": "2024-06-23T21:01:44",
            "upload_time_iso_8601": "2024-06-23T21:01:44.845222Z",
            "url": "https://files.pythonhosted.org/packages/51/37/7a515c4e40d6cacb2fee0416dea9a82441c83cade5c858f1bcef4d598a99/async_annoy-0.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-23 21:01:44",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ryzhakar",
    "github_project": "async-annoy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "async-annoy"
}
        
Elapsed time: 0.30784s