A simple server around Annoy (K-NN). You can add, delete and search vectors.
pip install git+https://github.com/andreidore/flyannoy
Start a server with s3 storage.
flyannoy-server --length 1536 --storage s3 --s3_bucket buckey --s3_key key
from flyannoy import FlyAnnoy
from flask import Flask
flyannoy = FlyAnnoy(url_prefix="/api/annoy", vector_length=3)
app = Flask(__name__)
app.register_blueprint(flyannoy)
app.run(debug=True)
Add vector to index.
Mandatory fields:
- id - id of the vector. Must be an unique string.
- vector - list of number
Optional fields:
- metdata - metadata
curl --header "Content-Type: application/json" \
--request POST \
--data '{"id":"1","vector":[1.2,3.4,5.6]}' \
http://localhost:5000/api/annoy/add
Delete vector from index.
Mandatory fields:
- id - id of the vector.
Delete vector
curl --header "Content-Type: application/json" \
--request POST \
--data '{"id":"1"}' \
http://localhost:5000/api/annoy/delete
Search vector
curl --header "Content-Type: application/json" \
--request POST \
--data '{"vector":[1,2,3]}' \
http://localhost:5000/api/annoy/search
Refresh index
curl --header "Content-Type: application/json" \
--request POST \
http://localhost:5000/api/annoy/refresh
FlyAnnoy support pluggable storage for vectors and index.
Local storage store the vector in separate files in local file system.
You can store vectors, metadata and index in S3
from flyannoy import FlyAnnoy,S3Storage
from flask import Flask
flyannoy = FlyAnnoy(url_prefix="/api/annoy", vector_length=3,storage=S3Storage("bucket","key","local_path")
app = Flask(__name__)
app.register_blueprint(flyannoy)
app.run(debug=True)