Git Product home page Git Product logo

python-faiss-grpc-server's Introduction

python-faiss-grpc-server

GitHub Actions Status

Python gRPC server for apploximate nearest neighbor by Faiss.

Installation

You can install as package by pip install on repository root.

pip install .

Usage

You can start gRPC server by running following command.

python python/faiss_grpc/main.py

Environment variable

Python Faiss gRPC server has some environment variables starts with prefix FAISS_GRPC_.

Variable Default Description Required
FAISS_GRPC_INDEX_PATH - Path to Faiss index o
FAISS_GRPC_NORMALIZE_QUERY False Normalize query for search (This is useful to cosine distance metrics) x
FAISS_GRPC_NPROBE None Faiss nprobe parameter x
FAISS_GRPC_HOST [::] gRPC server host x
FAISS_GRPC_PORT 50051 gRPC server listening port x
FAISS_GRPC_MAX_WORKERS 10 Maximum number of gRPC server workers x

Support .env file

Python Faiss gRPC server supports .env file, above environment variables can specified like

# .env
FAISS_GRPC_INDEX_PATH=/path/to/index
FAISS_GRPC_NORMALIZE_QUERY=True
FAISS_GRPC_NPROBE=10

FAISS_GRPC_HOST=[::]
FAISS_GRPC_PORT=50051
FAISS_GRPC_MAX_WORKERS=2

Examples

Client side code is under the examples/client.py. You can run following command or directly running on interpreter.

cd examples

# show usage of client example
python client.py -h

# show heatbeat message
python client.py heatbeat

# search by query, get numer of neighbors given value (query is auto generated in command as identity vector)
python client.py search 10

# search by specified id, get numer of neighbors given value
python client.py search-by-id 0 10

Development

Generate python code

Following command will generate two python grpc code faiss_pb2.py and faiss_pb2_grpc.py under the python/faiss_grpc/proto. If you update grpc definition proto/faiss.proto, you should regenerate at first.

make codegen

Then you have to fix import path in faiss_pb2_grpc.py.

# Before
import faiss_pb2 as faiss__pb2
# After
import faiss_grpc.proto.faiss_pb2 as faiss__pb2

Cautionary points

  • Avoid to use SearchById on the index built by add_with_ids (can use from IndexIDMap, IndexIVF etc.). These index does not keep id complicatedly so reconstruct_n method may do unexpected behavior.
  • Support only CPU index.

Future work

  • Prepare docker image
  • Auto download index from remote location if FAISS_GRPC_INDEX_PATH was specified remote path

python-faiss-grpc-server's People

Contributors

kanchishimono avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

python-faiss-grpc-server's Issues

Support for other ANN libraries

I'm currently working on Annoy index integration into faiss-grpc-server, source code is located here:

Are you interested in such features or do you prefer that I start a new project ?

In addition to annoy I plan to:

  • create a docker image
  • download remote index files (from S3 or GCP)
  • sync if a new index file is posted to original URL (file, S3, GCP)
  • serve multiple index files (this will break the service contract by introducing an index name in RPC methods)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.