NAME
ttypt/sepal.h - libsepal โ the meaning (semantic) axis.
SYNOPSIS
#include <stddef.h>
#include <stdint.h>
#include <ttypt/corm.h>
Data Structures
Macros
Typedefs
Functions
Detailed Description
libsepal โ the meaning (semantic) axis.
A dim-tagged vector store with a two-stage ANN pipeline: Hamming prefilter over a sign-bit sketch (top-m) followed by exact cosine rerank (top-k). Built on the corm persistent map and the recall kernel (rec.h). Follows the same standard as libjoint / libislet / liblemma (mk stack, ttypt headers).
DESIGN CONTRACT
- Refs are caller-opaque rec_ref_t (u32): the caller passes them at put time and owns ref<->schema mapping. The store never maps refs.
- Per-blob dims: every vector stores its own exact-stage dim (the "matryoshka" prefix) = min(full_dim, SEPAL_EXACT_DIM). Vectors already <= SEPAL_EXACT_DIM dims are stored untruncated.
- sepal_get NEVER truncates: asking for more dims than stored is fine (returns the stored count); asking for fewer returns 0 (mismatch).
- Search is pure two-stage ANN. Exact brute force is the test-side reference and is NOT provided by the library (exactness is a kernel property, not a sepal feature).
Macro Definition Documentation
#define SEPAL_EXACT_DIM 256
Matryoshka default: exact-stage dim cap (per-blob dim, not store config).
#define SEPAL_M_DEFAULT 10
m knob default: 10x k when m==0 (capped at the store size).
#define SEPAL_VEC_MAX 2048
Max full dimensionality accepted at put (any dim is truncated to this).
Typedef Documentation
typedef struct sepal_hit sepal_hit_t
A search hit: (ref, cosine score).
typedef struct sepal_vecstore sepal_vecstore_t
Opaque vector store handle (corm-backed; memory-only when opened NULL).
Function Documentation
int sepal_blob_hdr (const uint8_t * blob, size_t avail, sepal_blob_hdr_t * hdr)
Parse the VEC1 header; 0 ok, -1 invalid/truncated.
size_t sepal_blob_len (const uint8_t * blob, size_t avail)
Byte length of a valid VEC1 blob; 0 when invalid (bad magic/version, inconsistent fields) or truncated (declared length > avail).
size_t sepal_blob_put (uint8_t * buf, size_t avail, const float * v, size_t full_dim, size_t dim)
Encode a vector as a VEC1 blob (sketch over full_dim, norm of the truncated prefix dim = min(full_dim, SEPAL_EXACT_DIM)). Writes at most avail bytes; returns the byte length written, or 0 on error (bad dims or avail too small). dim must be <= SEPAL_EXACT_DIM and <= full_dim.
float sepal_cosine (const float * a, const float * b, size_t n)
Column-normalized cosine similarity (mm_cosine semantics); 0 when either vector has zero norm.
int sepal_del (sepal_vecstore_t * vs, rec_ref_t ref)
Delete a ref; 0 if present, -1 if absent.
size_t sepal_dim (sepal_vecstore_t * vs, rec_ref_t ref)
Stored exact-stage dim of ref (0 if absent).
int sepal_fill_approx (sepal_vecstore_t * vs, const float * q, size_t qdim, size_t m, float min_sim, rec_set_t * out)
Approximate set fill (kernel form): streams the top-m Hamming refs into out, seals it, then declares it approximate via rec_set_set_approx() with owed bound = (m >= n ? 1.0 : (float)m / n) โ the oversampling heuristic (caller may override after the call; the setter exists). Additive: on entry out may already hold refs (result is their union, sealed). 0 on success; -1 on NULL args / bad dims.
size_t sepal_full_dim (sepal_vecstore_t * vs, rec_ref_t ref)
Full (sketch) dim of ref (0 if absent).
size_t sepal_get (sepal_vecstore_t * vs, rec_ref_t ref, float * out, size_t max)
Copy the stored exact-dim floats into out (space for >= dim). Returns the stored exact dim (>0). Returns 0 on missing ref, or when max < stored dim (mismatch โ never truncates, per the design contract).
int sepal_index_validate (const sepal_vecstore_t * vs)
Consistency check of the internal search index (T2): 0 when the flat sketch table, its refs, and the store's count agree; nonzero otherwise. NULL store is valid (returns 0). Cheap; meant for tests and diagnostics.
size_t sepal_n (const sepal_vecstore_t * vs)
Number of vectors in the store.
int sepal_put (sepal_vecstore_t * vs, rec_ref_t ref, const float * v, size_t full_dim)
Store vector v (full_dim floats); dim stored = min(full_dim, SEPAL_EXACT_DIM). full_dim must be in [1, SEPAL_VEC_MAX]; -1 on error. Re-putting a ref replaces its blob.
int sepal_rank (struct sepal_rank_ctx * ctx, rec_ref_t ref, float * score)
Exact cosine rerank of one ref. 0 on success (score written, >= min_sim); nonzero when ref is missing, dims mismatch, or score < min_sim (score is left untouched on failure).
int sepal_sketch (const float * v, size_t n, uint64_t * words, size_t nwords)
Sign-bit sketch: nwords must be >= ceil(n/64) (else -1). words[w] bit b is the sign bit (IEEE bit 31) of v[w*64 + b], for dims w*64+b < n; the bits past n in the last word are zeroed. Returns 0 on success.
Author
Generated automatically by Doxygen for sepal from the source code.