SkillAgentSearch skills...

Spheni

Lightweight Vector Search Library focused on Memory Efficiency

Install / Use

/learn @datavorous/Spheni
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

<p align="center"> <img src="media/banner.png" width="700px"> </p> <h2 align="center">Spheni</h2> <p align="center"> A lightweight vector search library focused on <b>memory-efficient</b> approximate nearest neighbor search. </p> <p align="center"> <a href="LICENSE"><img src="https://img.shields.io/badge/License-Apache_2.0-blue.svg"></a> <a href="https://discord.gg/XPrAs44vdH"><img src="https://img.shields.io/discord/1463893045731921934?label=Discord&logo=discord" alt="Discord"></a> </p>

Index

  1. Overview
  2. Features
  3. Getting Started
  4. API Reference
  5. Benchmarks
  6. Roadmap
  7. References

Overview

The goal of Spheni is to be focused on memory efficiency rather than accuracy, and act a candidate generation system.

It implements inverted indexing and product quantization with residual encoding to reduce memory usage while supporting fast similarity search.

With Cohere 1M Embeddings, the current benchmark reports up to 213.9x compression (13.69 MB index at M=8) and up to 94.20% Recall@10-in-100 (M=64, nprobe=32), with the baseline at 80.1x compression and 83.25% Recall@10-in-100 (M=32, nprobe=32).

Features

  • Indexes: Flat, IVF, FlatPQ, IVF-PQ
  • Metrics: Cosine similarity, L2 distance
  • Operations: train, add, search

Getting Started

Build

Requirements:

  • CMake >= 3.15
  • A C++20 compiler (GCC/Clang)

Quick build

chmod +x build.sh
./build.sh

After building, this repository produces build/libspheni.a. You only need the public header (include/spheni.h) and the static library (libspheni.a) to consume Spheni in another project.

Usage

g++ -std=c++20 -O3 main.cpp -I /path/to/spheni/include /path/to/libspheni.a -o main

Example

Check out examples/ folder for more.

#include "spheni.h"
#include <iostream>

int main() {
        // define
        spheni::IVFSpec spec{{3, spheni::Metric::Cosine, true}, 2, 1};
        spheni::IVFIndex index(spec);

        long long ids[] = {0, 1, 2};
        float vecs[] = {
            1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f,
        };
        // train
        index.train(ids, vecs);

        float query[] = {1.0f, 0.2f, 0.0f};
        // search
        auto hits = index.search(query, 3);

        for (const auto &h : hits) {
                std::cout << h.id << " " << h.score << "\n";
        }
        return 0;
}

API Reference

Detailed public API documentation is available in docs/api-reference.md.

Benchmarks

Current Benchmark Report (single-core run, 200 queries, Recall@k-in-100).
Legacy Report is also available.

Roadmap

  • [ ] Implement save/load for seralized data
  • [ ] Implement multithreading with OpenMP wherever applicable
  • [ ] Implement OPQ (tough for me)
  • [ ] SIMD vectorizations

References

Papers

  1. FAISS: ArXiv Paper
  2. Near Neighbor Search in Large Metric Spaces
  3. The Binary Vector as the Basis of an Inverted Index File
  4. Product Quantization for Nearest Neighbour Search

Blogs

  1. A Bhayani - Product Quantization
  2. W Lin - Building a high recall vector database serving 1 billion embeddings from a single machine
View on GitHub
GitHub Stars176
CategoryDevelopment
Updated3d ago
Forks15

Languages

C++

Security Score

100/100

Audited on Mar 24, 2026

No findings