AutoFaiss

2.18.0 · active · verified Fri Apr 17

AutoFaiss is a Python library that automatically selects and tunes the best Faiss index for a given dataset, optimizing for search quality and inference speed. It simplifies the process of building and evaluating vector search indexes, abstracting away much of the complexity of Faiss. The current version is 2.18.0, and it generally follows a minor release cadence driven by dependency updates and small feature enhancements.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to build a Faiss index using `autofaiss.build_index` from a NumPy array. It highlights essential parameters like `index_path`, `max_ram_usage`, and `metric_type`. The `max_ram_usage` parameter is critical for preventing out-of-memory errors on large datasets.

import numpy as np
from autofaiss import build_index

# Create dummy data: 1000 vectors of 128 dimensions, float32 is recommended
data = np.float32(np.random.rand(1000, 128))

# Build the index. Specify max_ram_usage relevant to your system.
# For production, consider 'metric_type="ip"' for inner product or 'l2' for L2 distance.
index, index_infos = build_index(
    data,
    index_path="my_autofaiss_index.bin",
    index_infos_path="my_autofaiss_index_infos.json",
    max_ram_usage="4GB", # IMPORTANT: Adjust based on available RAM
    metric_type="ip" 
)

print(f"Index built and saved to my_autofaiss_index.bin with info in my_autofaiss_index_infos.json")

view raw JSON →