Ultra-fast semantic vector store with two-stage ANN search (Hamming sign-bit sketch prefilter + exact cosine rerank) in pure C. Canonical header is <ttypt/sepal.h>.
git clone https://github.com/tty-pt/libsepalDocumentation
Manual Pages
libsepal
Ultra-fast semantic vector store with two-stage ANN search (Hamming sign-bit sketch prefilter + exact cosine rerank) in pure C. Canonical header is<ttypt/sepal.h>.
1. Quickstart
Store vector embeddings and perform nearest-neighbor semantic search in under 15 lines:
#include <stdio.h>
#include <ttypt/sepal.h>
int main(void) {
// Open in-memory semantic vector store
sepal_vecstore_t *vs = sepal_open(NULL, NULL);
float vec_a[4] = {0.9f, 0.1f, 0.0f, 0.0f};
float vec_b[4] = {0.8f, 0.2f, 0.1f, 0.0f};
sepal_put(vs, 1, vec_a, 4); // Ref 1
sepal_put(vs, 2, vec_b, 4); // Ref 2
// Query 2-nearest neighbors by cosine similarity
float query[4] = {0.85f, 0.15f, 0.0f, 0.0f};
sepal_hit_t hits[2];
size_t n = sepal_search(vs, query, 4, 2, 0.0f, 0, hits);
for (size_t i = 0; i < n; i++) {
printf("Hit %zu: ref=%u score=%.4f\n", i, hits[i].ref, hits[i].score);
}
sepal_close(vs);
return 0;
}
Compile and link:
cc semantic_search.c $(pkg-config --cflags --libs libsepal) -o semantic_search
๐ For full hybrid search setups paired with axil-auren and liblemma, see docs/SEMANTIC_SEARCH.md.
2. Core API Reference
The essential functions for vector storage and Approximate Nearest Neighbor (ANN) search:
| Function | Signature | Description |
|---|---|---|
sepal_open | sepal_vecstore_t *sepal_open(file, db) | Open in-memory or persisted vector store |
sepal_put | int sepal_put(vs, rec_ref_t ref, vec, dim) | Store float vector tagged to a uniform 32-bit ref |
sepal_search | size_t sepal_search(vs, q, dim, k, min_sim, m, hits) | Run two-stage ANN search returning top-k best hits |
sepal_fill_approx | int sepal_fill_approx(vs, q, dim, m, set) | Stream candidate pool into a recall candidate set |
sepal_rank | int sepal_rank(ctx, rec_ref_t ref, &score) | Exact cosine reranking callback for the recall kernel |
rec_axis_store_typed | int rec_axis_store_typed(ref, data, len, qtype, ctx) | Ingest raw float vector embeddings directly from HTOK binary containers |
sepal_close | void sepal_close(vs) | Flush persistence and release memory |
3. Two-Stage ANN Architecture
libsepal converts high-dimensional float vectors into compact binary representations (VEC1) and searches them in two stages:
Query Vector โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โผ
Stage 1: Sign-Bit Sketch Prefilter (Hamming distance in L2 cache)
[ 10,000 Vector Candidates ] โโโโโโโโโโโโโโโบ [ Top 50 Finalists (99.5% discarded) ]
โ
Stage 2: Exact Cosine Reranking (AVX2 FMA floating-point math) โผ
[ Top 50 Finalists ] โโโโโโโโโโโโโโโโโโโโโโโบ [ Top 5 Semantic Matches (50 ยตs) ]
- Compact Binary Footprint: Matryoshka dimension truncation condenses 768-dimensional vectors from ~7 KB of raw text into 1,136-byte cache-friendly binary blobs (
VEC1). - Bitwise Hamming Prefilter: Stage 1 performs bitwise popcounts over sign-bit sketches in L2 CPU cache, discarding 95โ99% of candidates in nanoseconds.
- Exact AVX2 Cosine Rerank: Stage 2 performs exact AVX2 FMA cosine reranking on only top finalists, finishing in under 50 microseconds.
4. corm CLI Multi-Axis Integration
libsepal attaches directly to the corm CLI tool as the @sepal vector axis for semantic search:
# Ingest documents and generate vector embeddings (requires axil-auren or embedding endpoint):
export CORM_SEPAL_EMBED_URL="http://127.0.0.1:4242/v1/embeddings"
export CORM_SEPAL_EMBED_MODEL="bge-base"
corm -p "High-performance vector similarity search in pure C" docs.db@sepal:a:s
# Semantic similarity query via corm CLI:
corm -X "sepal" --sepal="vector database" docs.db@sepal:a:s
libsepal also supports CORM_SEPAL_EMBED_CACHE, a persistent file-backed vector cache:
- Zero Re-Embedding: Caches text hashes and corresponding float vectors to disk, eliminating redundant neural evaluations across restarts.
- Configuration: Set
CORM_SEPAL_EMBED_CACHE=/path/to/embed.dbin your environment.
5. Installation & Build
Prebuilt Packages
Prebuilt packages for Linux (APT / Alpine / Arch / Fedora-RHEL), macOS (Homebrew), Windows (winget / MSYS2), and OpenBSD, and mobile static sysroots for Android (https://tty.pt/android/ โ arm64-v8a, armeabi-v7a, x86_64) and iOS (https://tty.pt/ios/ โ libsepal.xcframework) are distributed via tty.pt packages. Use libsepal as the package name.
Build from Source
Builds use shared libstele rules (include ttypt/include.mk):
make # builds lib/libsepal.so
make test # run unit, property, and stress tests
sudo make install # install headers and library to system
6. JavaScript & WebAssembly Bindings (@tty-pt/sepal)
Official Node.js and Browser WebAssembly bindings are colocated in npm/:
- Two-Stage ANN Vector Search: Fast bitwise Hamming sign-bit sketch pre-filtering with exact normalized cosine similarity reranking.
- Client-Side & Edge Semantic Search: Run embeddings search in browser tabs and edge functions with precompiled
dist/sepal.wasm. - C Development Headers: Install via
npm install @tty-pt/sepal(from npm orhttps://tty.pt/npm/) and consume headers fromnode_modules/@tty-pt/sepal/include.
๐ For complete TypeScript usage, vector indexing guides, and API reference, see npm/README.md.
License
BSD 2-Clause License. Copyright (c) 2025, tty-pt. See LICENSE.