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§
- Brute
Force - 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
efon layer 0. Removal unlinks the node at once and repairs its neighbours, so no removed vector stays in memory or in a page; pastmax_deleted_fractionremovals the graph rebuilds in id order. - Hnsw
Params - Build and search settings of an HNSW index.
Fields are private; start from
Defaultand use thewith_*setters.new_indexvalidates 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§
- Index
Error - Failure of an index call. Caller input gets an error, never a panic.
CorruptPagemeans persisted pages were refused; the store then rebuilds from vectors. - Index
Kind - Which index to build. Default
BruteForce, which is exact.Hnswis approximate and faster on large sets. Passed tonew_index. - Page
Change - One page change since the last
take_changescall.Putwrites or replaces the bytes of a key,Deleteremoves it. The bytes are opaque to the store and untrusted on restore. - PageKey
- Key of one persisted page.
Headerholds graph-wide state,Nodethe links of one id. Brute force emits no pages. - Quantization
- In-memory format of stored vectors. Queries stay f32.
F32is exact,F16halves memory,I8quarters it with one f32 scale per vector. DefaultF32.
Constants§
- MAX_
DIMS - Largest vector dimension an index accepts.
Larger values are refused by
new_indexand by inserts. Bounds memory per vector and the cost of one score. - MAX_K
- Largest
ka search accepts. Larger values are refused withIndexError::Invalid. Bounds the result heap and the HNSW beam width.
Traits§
- Vector
Index - A vector index over
u64ids with one fixed dimension. Search uses cosine similarity, higher is closer, ties by lower id, at mostkresults, only ids whereallowreturns true.
Functions§
- new_
index - Builds an empty index of the given kind, dimension and format.
Input:
dimsin1..=MAX_DIMSand, for HNSW, params in range. Output: the boxed index, orInvalidnaming the bad setting.