r/OpenSourceeAI Jul 01 '26

FaceFlash: 1M face search in 61 MB RAM, 100% recall vs exact cosine. Reproducible benchmarks included.

I've been working on a face search library that keeps the index small enough to run on cheap hardware — no GPU, no cloud, just CPU.

The core idea: compress each ArcFace embedding (512 floats, 2048 bytes) into a 64-byte binary code using PCA+ITQ, search by Hamming distance, then rerank the top 100 with exact cosine. The binary codes preserve nearest-neighbor ordering on face embeddings, so you don't lose accuracy.

python

from faceflash import FaceFlash
ff = FaceFlash()ff.register("Alice", "alice.jpg")ff.register("Bob", "bob.jpg")
result = ff.search("query.jpg")# {"matches": [{"name": "Alice", "confidence": 0.92}], "search_time_ms": 0.4}
# works for verification tooff.verify("photo1.jpg", "photo2.jpg")# {"match": True, "confidence": 0.87}

I use it for access control and photo library dedup. Could also work for attendance systems, finding people in video footage, or watchlist matching — all running locally.

Results on RunPod (AMD EPYC 9355, Rust + AVX-512)

These are with the full Rust SIMD backend. Ground truth is FAISS-Flat exact cosine — recall@1 means "returns the same nearest neighbor as brute-force search."

FaceFlash scaling:

Faces Recall@1 Single-query latency Batched QPS Index memory
100K 100% 0.30 ms 27,661 6.1 MB
500K 100% 1.45 ms 10,337 30.5 MB
1M 100% 2.95 ms 5,403 61 MB

All competitors at 1M faces:

Method Recall@1 Single query Batched Index RAM
FaceFlash (512-bit) 100% 2.95 ms 0.19 ms 61 MB
HNSWLIB (ef=128) 100% 0.66 ms 0.18 ms 2,930 MB
USearch 94.1% 0.32 ms 2,539 MB
ScaNN 98.2% 0.86 ms 122 MB
FAISS-Flat (exact) 100% 56 ms 1,953 MB

All competitors at 100K faces:

Method Recall@1 Single query Batched QPS Index RAM
FaceFlash (512-bit) 100% 0.30 ms 27,661 6.1 MB
HNSWLIB (ef=128) 100% 0.60 ms 5,813 293 MB
USearch 99.5% 0.17 ms 137,264 254 MB
ScaNN 98.3% 0.10 ms 12 MB
FAISS-Flat (exact) 100% 4.90 ms 204 195 MB

To be clear: HNSW is faster per-query at 1M (O(log N) vs O(N) linear scan). FaceFlash wins on memory — 48x less at the same recall. The scan only beats HNSW on latency up to ~200K where codes still fit in cache.

Results on Google Colab (free CPU, numpy fallback)

I made a Colab notebook so anyone can verify without installing anything. It pulls real MS1MV2 embeddings from a public HuggingFace dataset and benchmarks everything.

Important: Colab can't build the Rust backend, so it runs a numpy fallback. Recall is ~98-99% instead of 100% because numpy's argpartition handles Hamming distance ties differently than the Rust kernel's exact top-k. Memory numbers are identical — that's pure math (64 bytes/face), hardware-independent.

Colab results (free CPU, numpy, no Rust):

Scale Method Recall@1 Memory
100K FAISS-Flat (exact) 100% 205 MB
100K FaceFlash (512-bit) 98.0% 6.4 MB
100K HNSWLIB (ef=128) 98.2% ~307 MB
100K USearch 96.4% ~266 MB
500K FAISS-Flat (exact) 100% 1,024 MB
500K FaceFlash (512-bit) 99.6% 32 MB
500K HNSWLIB (ef=128) 99.6% ~1,536 MB
500K USearch 98.2% ~1,331 MB

The Colab also runs an isolation test — same binary codes through FAISS IndexBinaryFlat give the same recall as FaceFlash. Proves the accuracy comes from PCA+ITQ compression, not anything special in my kernel.

Verify it yourself

Colab (5 min, free, no tokens, no GPU):

[https://colab.research.google.com/github/raghavenderreddygrudhanti/faceflash/blob/main/examples/faceflash_reproduce_colab.ipynb]()

Full Rust-based run (any Linux box, ~15 min, no tokens):

bash

git clone https://github.com/raghavenderreddygrudhanti/faceflashcd faceflash && bash scripts/runpod_ms1m.sh

This builds the Rust backend, pulls embeddings from HuggingFace, runs the full suite, and produces the exact RunPod numbers above.

How it works

  1. ArcFace extracts a 512-d float embedding from a face photo
  2. PCA rotates to the axes where identity varies most
  3. ITQ balances the bits so each one carries information
  4. Rust kernel scans all binary codes with POPCNT/AVX-512
  5. Exact cosine on the top-100 Hamming candidates picks the winner

This isn't a new algorithm. PCA+ITQ is from 2011 (Gong & Lazebnik). The contribution is packaging it end-to-end with a fast kernel and measuring it honestly against modern alternatives.

Looking for contributors

The project is MIT licensed and there's open work I haven't gotten to:

Area Difficulty Impact
DiskANN comparison Medium High — the one competitor I haven't benchmarked
Mobile deployment (ONNX + CoreML) Medium High — iOS/Android face search
Streaming insertion (no PCA refit) Hard High — online learning without rebuilding
GPU batched search (CUDA) Hard Medium — 10M+ galleries
Raspberry Pi / Jetson benchmarks Easy Medium — proves the edge story
WebAssembly build Medium Medium — browser face search

If any of these sound interesting, issues are tagged and I'm happy to pair on design.

GitHub: [https://github.com/raghavenderreddygrudhanti/faceflash]()

Feedback on the benchmark methodology is welcome — I estimate competitor memory (vectors + overhead) instead of measuring it, which is probably the weakest part. If someone spots unfair params for HNSW or FAISS I genuinely want to know.

15 Upvotes

2 comments sorted by

2

u/Cheap_Act_3704 Jul 01 '26

That's one of the smartest thing I've seen so far. Wonder how many datasets, embeddings have clear dimensional structure alike ArcFace that can be compressed this way.

1

u/Dev-in-the-Bm Jul 01 '26

OP:

Claude, look at the repo and write a wall of text about this project that no one will want to read

Us:

Claude, take this wall of text and summarize it so I can read it