Skip to main content

Faiss Instant

Build a Faiss service instantly. Faiss-instant will simply load existing Faiss index (and the corresponding ID mapping) and provide the search service via POST request.

New features: Now Faiss-instant also provides the toolkit for encoding texts into embeddings via SBERT models and indexing the embeddings into a Faiss ANN index. One just needs to install the toolkit via

pip install faiss-instant

and try this example.

Usage

First, one needs to put the resource files (the ID mapping and the Faiss index, please refer to resources/README.md) under the folder ./resources:

make download  # This will download example resource files. The example index comes from building a SQ index (QT_8bit_uniform) on a 10K-document version of the NQ corpus (dpr-single-nq-base was used for encoding). For other indices, please find under https://public.ukp.informatik.tu-darmstadt.de/kwang/faiss-instant/.

Then, one needs to start the faiss-instant service via docker:

docker pull kwang2049/faiss-instant  # Or `make pull`; or `make build` to build the docker image
docker run --detach --rm -it -p 5001:5000 -v ${PWD}/resources:/opt/faiss-instant/resources --name faiss-instant kwang2049/faiss-instant  # Or `make run`; notice here a volume mapping will be made from ./resources to /opt/faiss-instant in the container

Finally, do the query:

bash query_example.sh  # curl 'localhost:5001/search' -X POST -d '{"k": 5, "vectors":  [[0.31800827383995056, -0.19993115961551666, -0.029884858056902885, ...]]}'

This will return the mappings from document IDs to the corresponding scores:

[{"2426246":106.54305267333984,"4944584":107.05268096923828,"6195536":106.5833511352539,"6398884":107.19760131835938,"8077664":107.86164093017578}]

Whenever update the resources, one needs reload them:

curl 'localhost:5001/reload' -X GET  # Or `make reload`

Advanced

Multiple Indices

One can have multiple indices in the resource folder, to load a certain one (actually a pair of index_name.index and index_name.txt, here the index name is 'ivf-32-sq-QT_8bit_uniform'):

curl -d '{"index_name":"ivf-32-sq-QT_8bit_uniform", "use_gpu":true}' -H "Content-Type: application/json" -X POST 'http://localhost:5001/reload'

To view the available indices under the resource folder and the index loaded, one can run:

curl -X GET 'http://localhost:5001/index_list'

To load a specified index:

curl -d '{"index_name":"ivf-32-sq-QT_8bit_uniform"}' -H "Content-Type: application/json" -X POST 'http://localhost:5001/reload'

Use GPU

Note Faiss only supports part of the index types: https://github.com/facebookresearch/faiss/wiki/Faiss-on-the-GPU#implemented-indexes. And for PQ, it cannot support large m such as 384.

One can also use GPU to accelerate the search. To achieve that, one needs to use the GPU version:

docker pull kwang2049/faiss-instant-gpu  # The current image supports only CUDA 10.2 or higher version

And then start the GPU-version container:

docker run --runtime=nvidia -e CUDA_VISIBLE_DEVICES=0 --detach --rm -it -p 5001:5000 -v ${PWD}/resources:/opt/faiss-instant/resources --name faiss-instant-gpu kwang2049/faiss-instant-gpu  # Or `make run-gpu`

This will split and load the index onto all the GPUs available (in this example it uses only gpu:0). To load a specified index and make it on GPU, one can run:

curl -d '{"index_name":"ivf-32-sq-QT_8bit_uniform", "use_gpu":true}' -H "Content-Type: application/json" -X POST 'http://localhost:5001/reload'

Reconstruct

To get the original vector without indexing by its ID, run:

curl -X 'GET' 'http://localhost:5001/reconstruct?id=1'  # This example returns the vector by its ID='1'

Explain

To compute the similarity score between a given query vector and a support vector by its ID:

bash explain_example.sh

Philosophy

Faiss-instant provides only the search service and relies on uploaded Faiss indices. By using the volume mapping, the huge pain of uploading index files to the docker service can be directly removed. Consequently, a minimal efficient Faiss system for search is born.

For creating index files (and also benchmarking ANN methods), please refer to kwang2049/benchmarking-ann.

Reference

plippe/faiss-web-service

Metadata

Release files for faiss-instant 0.0.4

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

Source distribution (sdist)

Source distribution for faiss-instant 0.0.4
File Size Uploaded Provenance Actions
faiss-instant-0.0.4.tar.gz 14.1 kB Without provenance Details for faiss-instant-0.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for faiss-instant 0.0.4
File Interpreter ABI Platform Actions
faiss_instant-0.0.4-py3-none-any.whl Python 3 none any Details for faiss_instant-0.0.4-py3-none-any.whl

Total release size: 28.2 kB

Release files / faiss-instant-0.0.4.tar.gz

Download URL faiss-instant-0.0.4.tar.gz
Size 14.1 kB
Tags Source
SHA-256 checksum
How to use checksums
59bae37e9d17f330813f418b76d7cc18ac0d186fbd90db6a1de9e625d861cda3
BLAKE2b-256 checksum
How to use checksums
140a1ad6f8caf775e876455420ce307ed8df6cbf04bb55b06e2c1518df8312ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7

Release files / faiss_instant-0.0.4-py3-none-any.whl

Download URL faiss_instant-0.0.4-py3-none-any.whl
Size 14.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d68209faa0def3cc8082b00ef5b1e74e825d821186ce376e72f1aea84325e805
BLAKE2b-256 checksum
How to use checksums
786e07a9f57aa5b0ff8c9fe499dd24e00571a172067d9cf8235c2d43fdbf29f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7

Security for faiss-instant 0.0.4

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