Skip to content

DeveloperMindset-com/faiss-mobile

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

17 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

FAISS Mobile

This library provides means to compile and distribute FAISS library for iOS.

FAISS is a library β€” developed by Facebook AI β€” that enables efficient similarity search. So, given a set of vectors, we can index them using Faiss β€” then using another vector (the query vector), we search for the most similar vectors within the index.

Version

Latest supported version of FAISS is 1.7.4.

Supported platforms

  • iOS
  • iOS Simulator
  • tvOS
  • tvOS Simulator
  • watchOS
  • watchOS Simulator
  • macOS

Requirements

  • Git LFS
  • Xcode (including multiple platforms)
  • LLVM with Clang
  • Homebrew
  • g++
  • CMake
  • node
  • python
  • perl
  • ruby (for Cocoapods)
  • carthage
  • swift
  • OpenMP

Why

Modern machine learning tools focus on the server side or desktop solutions, few of them optimise their code bases for mobile, this repository is a structured way to get the FAISS source code compiled and distributed to iOS developers.

Getting started

Run ./faiss.sh and it will create dist/faiss.xcframework that you can use in your Xcode project.

faiss.xcframework

Once the compilation is done, you'll have XCframework created with the files below:

tree dist/faiss.xcframework -P '*.a'
dist/faiss.xcframework
β”œβ”€β”€ ios-arm64_arm64e
β”‚   β”œβ”€β”€ Headers
β”‚   β”‚   └── faiss
β”‚   β”‚       β”œβ”€β”€ c_api
β”‚   β”‚       β”‚   β”œβ”€β”€ impl
β”‚   β”‚       β”‚   └── utils
β”‚   β”‚       β”œβ”€β”€ impl
β”‚   β”‚       β”‚   └── code_distance
β”‚   β”‚       β”œβ”€β”€ invlists
β”‚   β”‚       └── utils
β”‚   β”‚           β”œβ”€β”€ approx_topk
β”‚   β”‚           β”œβ”€β”€ approx_topk_hamming
β”‚   β”‚           β”œβ”€β”€ distances_fused
β”‚   β”‚           β”œβ”€β”€ hamming_distance
β”‚   β”‚           └── transpose
β”‚   └── libfaiss.a
β”œβ”€β”€ ios-arm64_arm64e_x86_64-simulator
β”‚   β”œβ”€β”€ Headers
β”‚   β”‚   └── faiss
β”‚   β”‚       β”œβ”€β”€ c_api
β”‚   β”‚       β”‚   β”œβ”€β”€ impl
β”‚   β”‚       β”‚   └── utils
β”‚   β”‚       β”œβ”€β”€ impl
β”‚   β”‚       β”‚   └── code_distance
β”‚   β”‚       β”œβ”€β”€ invlists
β”‚   β”‚       └── utils
β”‚   β”‚           β”œβ”€β”€ approx_topk
β”‚   β”‚           β”œβ”€β”€ approx_topk_hamming
β”‚   β”‚           β”œβ”€β”€ distances_fused
β”‚   β”‚           β”œβ”€β”€ hamming_distance
β”‚   β”‚           └── transpose
β”‚   └── libfaiss.a
β”œβ”€β”€ macos-arm64_arm64e_x86_64
β”‚   β”œβ”€β”€ Headers
β”‚   β”‚   └── faiss
β”‚   β”‚       β”œβ”€β”€ c_api
β”‚   β”‚       β”‚   β”œβ”€β”€ impl
β”‚   β”‚       β”‚   └── utils
β”‚   β”‚       β”œβ”€β”€ impl
β”‚   β”‚       β”‚   └── code_distance
β”‚   β”‚       β”œβ”€β”€ invlists
β”‚   β”‚       └── utils
β”‚   β”‚           β”œβ”€β”€ approx_topk
β”‚   β”‚           β”œβ”€β”€ approx_topk_hamming
β”‚   β”‚           β”œβ”€β”€ distances_fused
β”‚   β”‚           β”œβ”€β”€ hamming_distance
β”‚   β”‚           └── transpose
β”‚   └── libfaiss.a
β”œβ”€β”€ tvos-arm64
β”‚   β”œβ”€β”€ Headers
β”‚   β”‚   └── faiss
β”‚   β”‚       β”œβ”€β”€ c_api
β”‚   β”‚       β”‚   β”œβ”€β”€ impl
β”‚   β”‚       β”‚   └── utils
β”‚   β”‚       β”œβ”€β”€ impl
β”‚   β”‚       β”‚   └── code_distance
β”‚   β”‚       β”œβ”€β”€ invlists
β”‚   β”‚       └── utils
β”‚   β”‚           β”œβ”€β”€ approx_topk
β”‚   β”‚           β”œβ”€β”€ approx_topk_hamming
β”‚   β”‚           β”œβ”€β”€ distances_fused
β”‚   β”‚           β”œβ”€β”€ hamming_distance
β”‚   β”‚           └── transpose
β”‚   └── libfaiss.a
β”œβ”€β”€ tvos-x86_64-simulator
β”‚   β”œβ”€β”€ Headers
β”‚   β”‚   └── faiss
β”‚   β”‚       β”œβ”€β”€ c_api
β”‚   β”‚       β”‚   β”œβ”€β”€ impl
β”‚   β”‚       β”‚   └── utils
β”‚   β”‚       β”œβ”€β”€ impl
β”‚   β”‚       β”‚   └── code_distance
β”‚   β”‚       β”œβ”€β”€ invlists
β”‚   β”‚       └── utils
β”‚   β”‚           β”œβ”€β”€ approx_topk
β”‚   β”‚           β”œβ”€β”€ approx_topk_hamming
β”‚   β”‚           β”œβ”€β”€ distances_fused
β”‚   β”‚           β”œβ”€β”€ hamming_distance
β”‚   β”‚           └── transpose
β”‚   └── libfaiss.a
β”œβ”€β”€ watchos-arm64_32_armv7k
β”‚   β”œβ”€β”€ Headers
β”‚   β”‚   └── faiss
β”‚   β”‚       β”œβ”€β”€ c_api
β”‚   β”‚       β”‚   β”œβ”€β”€ impl
β”‚   β”‚       β”‚   └── utils
β”‚   β”‚       β”œβ”€β”€ impl
β”‚   β”‚       β”‚   └── code_distance
β”‚   β”‚       β”œβ”€β”€ invlists
β”‚   β”‚       └── utils
β”‚   β”‚           β”œβ”€β”€ approx_topk
β”‚   β”‚           β”œβ”€β”€ approx_topk_hamming
β”‚   β”‚           β”œβ”€β”€ distances_fused
β”‚   β”‚           β”œβ”€β”€ hamming_distance
β”‚   β”‚           └── transpose
β”‚   └── libfaiss.a
└── watchos-i386-simulator
    β”œβ”€β”€ Headers
    β”‚   └── faiss
    β”‚       β”œβ”€β”€ c_api
    β”‚       β”‚   β”œβ”€β”€ impl
    β”‚       β”‚   └── utils
    β”‚       β”œβ”€β”€ impl
    β”‚       β”‚   └── code_distance
    β”‚       β”œβ”€β”€ invlists
    β”‚       └── utils
    β”‚           β”œβ”€β”€ approx_topk
    β”‚           β”œβ”€β”€ approx_topk_hamming
    β”‚           β”œβ”€β”€ distances_fused
    β”‚           β”œβ”€β”€ hamming_distance
    β”‚           └── transpose
    └── libfaiss.a

106 directories, 7 files

faiss_c.xcframework

A C only version, without C++ dependency is inside faiss_c.xcframework.

dist/faiss_c.xcframework
β”œβ”€β”€ Info.plist
β”œβ”€β”€ ios-arm64_arm64e
β”‚   β”œβ”€β”€ Headers
β”‚   β”‚   β”œβ”€β”€ AutoTune_c.h
β”‚   β”‚   β”œβ”€β”€ Clustering_c.h
β”‚   β”‚   β”œβ”€β”€ IndexBinary_c.h
β”‚   β”‚   β”œβ”€β”€ IndexFlat_c.h
β”‚   β”‚   β”œβ”€β”€ IndexIVFFlat_c.h
β”‚   β”‚   β”œβ”€β”€ IndexIVF_c.h
β”‚   β”‚   β”œβ”€β”€ IndexLSH_c.h
β”‚   β”‚   β”œβ”€β”€ IndexPreTransform_c.h
β”‚   β”‚   β”œβ”€β”€ IndexReplicas_c.h
β”‚   β”‚   β”œβ”€β”€ IndexScalarQuantizer_c.h
β”‚   β”‚   β”œβ”€β”€ IndexShards_c.h
β”‚   β”‚   β”œβ”€β”€ Index_c.h
β”‚   β”‚   β”œβ”€β”€ MetaIndexes_c.h
β”‚   β”‚   β”œβ”€β”€ VectorTransform_c.h
β”‚   β”‚   β”œβ”€β”€ clone_index_c.h
β”‚   β”‚   β”œβ”€β”€ error_c.h
β”‚   β”‚   β”œβ”€β”€ error_impl.h
β”‚   β”‚   β”œβ”€β”€ faiss_c.h
β”‚   β”‚   β”œβ”€β”€ impl
β”‚   β”‚   β”‚   └── AuxIndexStructures_c.h
β”‚   β”‚   β”œβ”€β”€ index_factory_c.h
β”‚   β”‚   β”œβ”€β”€ index_io_c.h
β”‚   β”‚   β”œβ”€β”€ macros_impl.h
β”‚   β”‚   └── utils
β”‚   β”‚       └── distances_c.h
β”‚   └── libfaiss_c.a
β”œβ”€β”€ ios-arm64_arm64e_x86_64-simulator
β”‚   β”œβ”€β”€ Headers
β”‚   β”‚   β”œβ”€β”€ AutoTune_c.h
β”‚   β”‚   β”œβ”€β”€ Clustering_c.h
β”‚   β”‚   β”œβ”€β”€ IndexBinary_c.h
β”‚   β”‚   β”œβ”€β”€ IndexFlat_c.h
β”‚   β”‚   β”œβ”€β”€ IndexIVFFlat_c.h
β”‚   β”‚   β”œβ”€β”€ IndexIVF_c.h
β”‚   β”‚   β”œβ”€β”€ IndexLSH_c.h
β”‚   β”‚   β”œβ”€β”€ IndexPreTransform_c.h
β”‚   β”‚   β”œβ”€β”€ IndexReplicas_c.h
β”‚   β”‚   β”œβ”€β”€ IndexScalarQuantizer_c.h
β”‚   β”‚   β”œβ”€β”€ IndexShards_c.h
β”‚   β”‚   β”œβ”€β”€ Index_c.h
β”‚   β”‚   β”œβ”€β”€ MetaIndexes_c.h
β”‚   β”‚   β”œβ”€β”€ VectorTransform_c.h
β”‚   β”‚   β”œβ”€β”€ clone_index_c.h
β”‚   β”‚   β”œβ”€β”€ error_c.h
β”‚   β”‚   β”œβ”€β”€ error_impl.h
β”‚   β”‚   β”œβ”€β”€ faiss_c.h
β”‚   β”‚   β”œβ”€β”€ impl
β”‚   β”‚   β”‚   └── AuxIndexStructures_c.h
β”‚   β”‚   β”œβ”€β”€ index_factory_c.h
β”‚   β”‚   β”œβ”€β”€ index_io_c.h
β”‚   β”‚   β”œβ”€β”€ macros_impl.h
β”‚   β”‚   └── utils
β”‚   β”‚       └── distances_c.h
β”‚   └── libfaiss_c.a
β”œβ”€β”€ macos-arm64_arm64e_x86_64
β”‚   β”œβ”€β”€ Headers
β”‚   β”‚   β”œβ”€β”€ AutoTune_c.h
β”‚   β”‚   β”œβ”€β”€ Clustering_c.h
β”‚   β”‚   β”œβ”€β”€ IndexBinary_c.h
β”‚   β”‚   β”œβ”€β”€ IndexFlat_c.h
β”‚   β”‚   β”œβ”€β”€ IndexIVFFlat_c.h
β”‚   β”‚   β”œβ”€β”€ IndexIVF_c.h
β”‚   β”‚   β”œβ”€β”€ IndexLSH_c.h
β”‚   β”‚   β”œβ”€β”€ IndexPreTransform_c.h
β”‚   β”‚   β”œβ”€β”€ IndexReplicas_c.h
β”‚   β”‚   β”œβ”€β”€ IndexScalarQuantizer_c.h
β”‚   β”‚   β”œβ”€β”€ IndexShards_c.h
β”‚   β”‚   β”œβ”€β”€ Index_c.h
β”‚   β”‚   β”œβ”€β”€ MetaIndexes_c.h
β”‚   β”‚   β”œβ”€β”€ VectorTransform_c.h
β”‚   β”‚   β”œβ”€β”€ clone_index_c.h
β”‚   β”‚   β”œβ”€β”€ error_c.h
β”‚   β”‚   β”œβ”€β”€ error_impl.h
β”‚   β”‚   β”œβ”€β”€ faiss_c.h
β”‚   β”‚   β”œβ”€β”€ impl
β”‚   β”‚   β”‚   └── AuxIndexStructures_c.h
β”‚   β”‚   β”œβ”€β”€ index_factory_c.h
β”‚   β”‚   β”œβ”€β”€ index_io_c.h
β”‚   β”‚   β”œβ”€β”€ macros_impl.h
β”‚   β”‚   └── utils
β”‚   β”‚       └── distances_c.h
β”‚   └── libfaiss_c.a
β”œβ”€β”€ tvos-arm64
β”‚   β”œβ”€β”€ Headers
β”‚   β”‚   β”œβ”€β”€ AutoTune_c.h
β”‚   β”‚   β”œβ”€β”€ Clustering_c.h
β”‚   β”‚   β”œβ”€β”€ IndexBinary_c.h
β”‚   β”‚   β”œβ”€β”€ IndexFlat_c.h
β”‚   β”‚   β”œβ”€β”€ IndexIVFFlat_c.h
β”‚   β”‚   β”œβ”€β”€ IndexIVF_c.h
β”‚   β”‚   β”œβ”€β”€ IndexLSH_c.h
β”‚   β”‚   β”œβ”€β”€ IndexPreTransform_c.h
β”‚   β”‚   β”œβ”€β”€ IndexReplicas_c.h
β”‚   β”‚   β”œβ”€β”€ IndexScalarQuantizer_c.h
β”‚   β”‚   β”œβ”€β”€ IndexShards_c.h
β”‚   β”‚   β”œβ”€β”€ Index_c.h
β”‚   β”‚   β”œβ”€β”€ MetaIndexes_c.h
β”‚   β”‚   β”œβ”€β”€ VectorTransform_c.h
β”‚   β”‚   β”œβ”€β”€ clone_index_c.h
β”‚   β”‚   β”œβ”€β”€ error_c.h
β”‚   β”‚   β”œβ”€β”€ error_impl.h
β”‚   β”‚   β”œβ”€β”€ faiss_c.h
β”‚   β”‚   β”œβ”€β”€ impl
β”‚   β”‚   β”‚   └── AuxIndexStructures_c.h
β”‚   β”‚   β”œβ”€β”€ index_factory_c.h
β”‚   β”‚   β”œβ”€β”€ index_io_c.h
β”‚   β”‚   β”œβ”€β”€ macros_impl.h
β”‚   β”‚   └── utils
β”‚   β”‚       └── distances_c.h
β”‚   └── libfaiss_c.a
β”œβ”€β”€ tvos-x86_64-simulator
β”‚   β”œβ”€β”€ Headers
β”‚   β”‚   β”œβ”€β”€ AutoTune_c.h
β”‚   β”‚   β”œβ”€β”€ Clustering_c.h
β”‚   β”‚   β”œβ”€β”€ IndexBinary_c.h
β”‚   β”‚   β”œβ”€β”€ IndexFlat_c.h
β”‚   β”‚   β”œβ”€β”€ IndexIVFFlat_c.h
β”‚   β”‚   β”œβ”€β”€ IndexIVF_c.h
β”‚   β”‚   β”œβ”€β”€ IndexLSH_c.h
β”‚   β”‚   β”œβ”€β”€ IndexPreTransform_c.h
β”‚   β”‚   β”œβ”€β”€ IndexReplicas_c.h
β”‚   β”‚   β”œβ”€β”€ IndexScalarQuantizer_c.h
β”‚   β”‚   β”œβ”€β”€ IndexShards_c.h
β”‚   β”‚   β”œβ”€β”€ Index_c.h
β”‚   β”‚   β”œβ”€β”€ MetaIndexes_c.h
β”‚   β”‚   β”œβ”€β”€ VectorTransform_c.h
β”‚   β”‚   β”œβ”€β”€ clone_index_c.h
β”‚   β”‚   β”œβ”€β”€ error_c.h
β”‚   β”‚   β”œβ”€β”€ error_impl.h
β”‚   β”‚   β”œβ”€β”€ faiss_c.h
β”‚   β”‚   β”œβ”€β”€ impl
β”‚   β”‚   β”‚   └── AuxIndexStructures_c.h
β”‚   β”‚   β”œβ”€β”€ index_factory_c.h
β”‚   β”‚   β”œβ”€β”€ index_io_c.h
β”‚   β”‚   β”œβ”€β”€ macros_impl.h
β”‚   β”‚   └── utils
β”‚   β”‚       └── distances_c.h
β”‚   └── libfaiss_c.a
β”œβ”€β”€ watchos-arm64_32_armv7k
β”‚   β”œβ”€β”€ Headers
β”‚   β”‚   β”œβ”€β”€ AutoTune_c.h
β”‚   β”‚   β”œβ”€β”€ Clustering_c.h
β”‚   β”‚   β”œβ”€β”€ IndexBinary_c.h
β”‚   β”‚   β”œβ”€β”€ IndexFlat_c.h
β”‚   β”‚   β”œβ”€β”€ IndexIVFFlat_c.h
β”‚   β”‚   β”œβ”€β”€ IndexIVF_c.h
β”‚   β”‚   β”œβ”€β”€ IndexLSH_c.h
β”‚   β”‚   β”œβ”€β”€ IndexPreTransform_c.h
β”‚   β”‚   β”œβ”€β”€ IndexReplicas_c.h
β”‚   β”‚   β”œβ”€β”€ IndexScalarQuantizer_c.h
β”‚   β”‚   β”œβ”€β”€ IndexShards_c.h
β”‚   β”‚   β”œβ”€β”€ Index_c.h
β”‚   β”‚   β”œβ”€β”€ MetaIndexes_c.h
β”‚   β”‚   β”œβ”€β”€ VectorTransform_c.h
β”‚   β”‚   β”œβ”€β”€ clone_index_c.h
β”‚   β”‚   β”œβ”€β”€ error_c.h
β”‚   β”‚   β”œβ”€β”€ error_impl.h
β”‚   β”‚   β”œβ”€β”€ faiss_c.h
β”‚   β”‚   β”œβ”€β”€ impl
β”‚   β”‚   β”‚   └── AuxIndexStructures_c.h
β”‚   β”‚   β”œβ”€β”€ index_factory_c.h
β”‚   β”‚   β”œβ”€β”€ index_io_c.h
β”‚   β”‚   β”œβ”€β”€ macros_impl.h
β”‚   β”‚   └── utils
β”‚   β”‚       └── distances_c.h
β”‚   └── libfaiss_c.a
└── watchos-i386-simulator
    β”œβ”€β”€ Headers
    β”‚   β”œβ”€β”€ AutoTune_c.h
    β”‚   β”œβ”€β”€ Clustering_c.h
    β”‚   β”œβ”€β”€ IndexBinary_c.h
    β”‚   β”œβ”€β”€ IndexFlat_c.h
    β”‚   β”œβ”€β”€ IndexIVFFlat_c.h
    β”‚   β”œβ”€β”€ IndexIVF_c.h
    β”‚   β”œβ”€β”€ IndexLSH_c.h
    β”‚   β”œβ”€β”€ IndexPreTransform_c.h
    β”‚   β”œβ”€β”€ IndexReplicas_c.h
    β”‚   β”œβ”€β”€ IndexScalarQuantizer_c.h
    β”‚   β”œβ”€β”€ IndexShards_c.h
    β”‚   β”œβ”€β”€ Index_c.h
    β”‚   β”œβ”€β”€ MetaIndexes_c.h
    β”‚   β”œβ”€β”€ VectorTransform_c.h
    β”‚   β”œβ”€β”€ clone_index_c.h
    β”‚   β”œβ”€β”€ error_c.h
    β”‚   β”œβ”€β”€ error_impl.h
    β”‚   β”œβ”€β”€ faiss_c.h
    β”‚   β”œβ”€β”€ impl
    β”‚   β”‚   └── AuxIndexStructures_c.h
    β”‚   β”œβ”€β”€ index_factory_c.h
    β”‚   β”œβ”€β”€ index_io_c.h
    β”‚   β”œβ”€β”€ macros_impl.h
    β”‚   └── utils
    β”‚       └── distances_c.h
    └── libfaiss_c.a

29 directories, 169 files

Distribution

This package is available using following package managers.

Swift Package Manager

./Pacakage.swift points to remote release hosted on this GitHub repository. Use these instructions to add this GitHub repository.

SPM version points to both libraries FAISS in C++ and its C version FAISS_C.

Cocoapods

./FAISS.podspec and ./FAISS_C.podspec include all the specific details about the build.

In your Podfile you can add this library using this syntax:

pod 'FAISS', :git => 'https://github.com/eugenehp/faiss-mobile.git', :tag => 'v1.7.4'
pod 'FAISS_C', :git => 'https://github.com/eugenehp/faiss-mobile.git', :tag => 'v1.7.4'

Carthage

In Cartfile add following:

binary "https://raw.githubusercontent.com/eugenehp/faiss-mobile/master/carthage/faiss-static-xcframework.json" ~> 1.7.4

Slightly different for a C version:

binary "https://raw.githubusercontent.com/eugenehp/faiss-mobile/master/carthage/faiss-c-static-xcframework.json" ~> 1.7.4

Releases

Release management works using gh.

brew install gh tree

To release a draft:

./faiss.sh release

Examples

Contributing

Contributions are welcome, feel free to submit an issue or open a pull request.

License

MIT

Copyright Β© 2023 Eugene Hauptmann

Legal

Faiss is MIT-licensed, refer to the LICENSE file in the top level directory.

Copyright Β© Meta Platforms, Inc. See the Terms of Use and Privacy Policy for this project.