ttypt/sepal.h(3)sepal

NAME

ttypt/sepal.h - libsepal โ€” the meaning (semantic) axis.

SYNOPSIS

#include <stddef.h>
#include <stdint.h>
#include <ttypt/corm.h>

Data Structures

struct sepal_hit
struct sepal_rank_ctx

Macros

#define SEPAL_VEC_MAX 2048
#define SEPAL_EXACT_DIM 256
#define SEPAL_M_DEFAULT 10

Typedefs

typedef struct sepal_vecstore sepal_vecstore_t
typedef struct sepal_hit sepal_hit_t

Functions

int sepal_put (sepal_vecstore_t *vs, rec_ref_t ref, const float *v, size_t full_dim)
int sepal_del (sepal_vecstore_t *vs, rec_ref_t ref)
size_t sepal_get (sepal_vecstore_t *vs, rec_ref_t ref, float *out, size_t max)
size_t sepal_dim (sepal_vecstore_t *vs, rec_ref_t ref)
size_t sepal_full_dim (sepal_vecstore_t *vs, rec_ref_t ref)
size_t sepal_n (const sepal_vecstore_t *vs)
int sepal_index_validate (const sepal_vecstore_t *vs)
float sepal_cosine (const float *a, const float *b, size_t n)
int sepal_sketch (const float *v, size_t n, uint64_t *words, size_t nwords)
int sepal_fill_approx (sepal_vecstore_t *vs, const float *q, size_t qdim, size_t m, float min_sim, rec_set_t *out)
int sepal_rank (struct sepal_rank_ctx *ctx, rec_ref_t ref, float *score)
size_t sepal_blob_len (const uint8_t *blob, size_t avail)
int sepal_blob_hdr (const uint8_t *blob, size_t avail, sepal_blob_hdr_t *hdr)
size_t sepal_blob_put (uint8_t *buf, size_t avail, const float *v, size_t full_dim, size_t dim)

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

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.