Skip to content

andreidore/flyannoy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FlyAnnoy

A simple server around Annoy (K-NN). You can add, delete and search vectors.

Install

pip install git+https://github.com/andreidore/flyannoy

Command line

Start a server with s3 storage.

flyannoy-server --length 1536 --storage s3 --s3_bucket buckey --s3_key key 

Python code example

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)

Methods

Add vector

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

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

Storage

FlyAnnoy support pluggable storage for vectors and index.

Local Storage

Local storage store the vector in separate files in local file system.

S3 Storage

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)

About

Simple server for annoy

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages