Skip to main content

Crate troupekit_index

Crate troupekit_index 

Source
Expand description

Vector index contract for Troupekit: exact brute force and HNSW. Sync and pure: no I/O, no async. A store persists the vectors and the opaque pages an index emits, and hands both back on open.

Structs§

BruteForce
Exact index: scores every allowed vector on each search. Ids and vectors sit in parallel slots with an id-to-slot map; removal swaps the last slot in. Emits no pages.
Hnsw
Approximate index after Malkov and Yashunin: a layered graph with greedy descent and a beam search of width ef on layer 0. Removal unlinks the node at once and repairs its neighbours, so no removed vector stays in memory or in a page; past max_deleted_fraction removals the graph rebuilds in id order.
HnswParams
Build and search settings of an HNSW index. Fields are private; start from Default and use the with_* setters. new_index validates the values.
Neighbor
One search result: an id and its cosine similarity to the query. Higher scores are closer. Results come sorted by score descending, ties broken by the lower id.

Enums§

IndexError
Failure of an index call. Caller input gets an error, never a panic. CorruptPage means persisted pages were refused; the store then rebuilds from vectors.
IndexKind
Which index to build. Default BruteForce, which is exact. Hnsw is approximate and faster on large sets. Passed to new_index.
PageChange
One page change since the last take_changes call. Put writes or replaces the bytes of a key, Delete removes it. The bytes are opaque to the store and untrusted on restore.
PageKey
Key of one persisted page. Header holds graph-wide state, Node the links of one id. Brute force emits no pages.
Quantization
In-memory format of stored vectors. Queries stay f32. F32 is exact, F16 halves memory, I8 quarters it with one f32 scale per vector. Default F32.

Constants§

MAX_DIMS
Largest vector dimension an index accepts. Larger values are refused by new_index and by inserts. Bounds memory per vector and the cost of one score.
MAX_K
Largest k a search accepts. Larger values are refused with IndexError::Invalid. Bounds the result heap and the HNSW beam width.

Traits§

VectorIndex
A vector index over u64 ids with one fixed dimension. Search uses cosine similarity, higher is closer, ties by lower id, at most k results, only ids where allow returns true.

Functions§

new_index
Builds an empty index of the given kind, dimension and format. Input: dims in 1..=MAX_DIMS and, for HNSW, params in range. Output: the boxed index, or Invalid naming the bad setting.