Skip to main content

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

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.

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.

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:

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.

Metadata

Release files for async-annoy 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for async-annoy 0.3.0
File Size Uploaded Provenance Actions
async_annoy-0.3.0.tar.gz 4.8 kB Without provenance Details for async_annoy-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for async-annoy 0.3.0
File Interpreter ABI Platform Actions
async_annoy-0.3.0-py3-none-any.whl Python 3 none any Details for async_annoy-0.3.0-py3-none-any.whl

Total release size: 10.2 kB

Release files / async_annoy-0.3.0.tar.gz

Download URL async_annoy-0.3.0.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
5b3efbdd4f1996ac0b1b1e66c99a66b3d2bfd053feef944b40c7a088d5e1a6b3
BLAKE2b-256 checksum
How to use checksums
51377a515c4e40d6cacb2fee0416dea9a82441c83cade5c858f1bcef4d598a99
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.10.6 Darwin/23.4.0

Release files / async_annoy-0.3.0-py3-none-any.whl

Download URL async_annoy-0.3.0-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7ef8388d2ded2ee5f5b4378b67c6e6b6c06f86881cc013d389a355cc472d54bf
BLAKE2b-256 checksum
How to use checksums
6e544ae2ff2ed5cd41725e44a9f49470e8ce0fd4e4e957bd179908946873d850
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.10.6 Darwin/23.4.0

Security for async-annoy 0.3.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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page