Giter Site home page Giter Site logo

swiftfaiss's Introduction

Swift Faiss

Use Faiss in Swift.

Based on Faiss Mobile and OpenMP Mobile.

Usage

Command line demo

$ swift run swift-faiss <subcommand> <options>

Available subcommands:

  • flat: create a FlatIndex, add vectors to it and search for the most similar sentences.
  • ivfflat: create an IVFFlatIndex, train and add vectors to it and search for the most similar sentences.
  • pq: create an PQIndex, train and add vectors to it and search for the most similar sentences.
  • clustering: k-means clustering example.

Command line help

$ swift run swift-faiss --help

In your own code

import SwiftFaiss

let embeddings: [[Float]] = [
    [0.1, 0.2, 0.3],
    [0.4, 0.5, 0.6],
    [0.7, 0.8, 0.9],
    [1.0, 1.1, 1.2],
    [1.3, 1.4, 1.5],
    [1.6, 1.7, 1.8]
]
let d = embeddings[0].count
let index = try FlatIndex(d: d, metricType: .l2)
try index.add(embeddings)

let result = try index.search([[0.1, 0.5, 0.9]], k: 2)
// do something with result

https://github.com/jkrukowski/UseSwiftFaiss contains an iOS example.

Installation

Swift Package Manager

You can use Swift Package Manager and specify dependency in Package.swift by adding:

.package(url: "https://github.com/jkrukowski/SwiftFaiss.git", from: "0.0.7")

Format code

$ swift package plugin --allow-writing-to-package-directory swiftformat

Tests

$ swift test

More info

swiftfaiss's People

Contributors

jkrukowski avatar actuallytaylor avatar

Stargazers

Muhammad Umer avatar

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.