class

Semtrace::EmbeddingStore

Inherits Reference < Object

Loads and indexes a static token embedding matrix for nearest-neighbor search.

Binary format (from extract_embeddings.py): Header: vocab_size (u32 LE), dimensions (u32 LE) Data: vocab_size * dimensions float32 values, row-major

Constructors

new(embeddings_path : String, vocab_path : String, skip_index : Bool = false, build_norm_index : Bool = false)
Source

Class methods

Adds vector b to vector a, returning a new array.

Source
norm(vec : Array(Float32) | Slice(Float32)) : Float32

Computes the L2 (Euclidean) norm of a vector.

Source

Subtracts vector b from vector a, returning a new array.

Source

Instance methods

close
Source
dimensions
Source
has_ip_index?

Whether an inner product index is available.

Source
has_norm_index?

Whether a normalized index is available.

Source
norm_vector_for(token_id : Int) : Slice(Float32)

Returns the L2-normalized embedding vector for a token ID. Only available if build_norm_index was true.

Source
search(query : Array(Float32) | Slice(Float32), k : Int = 1) : Array(USearch::SearchResult)

Finds the k nearest tokens to a query vector.

Source
search_ip(query : Array(Float32) | Slice(Float32), k : Int = 1) : Array(USearch::SearchResult)

Finds the k nearest tokens by inner product.

Source
search_normalized(query : Array(Float32) | Slice(Float32), k : Int = 1) : Array(USearch::SearchResult)

Finds the k nearest normalized tokens to a query vector.

Source
token_for(token_id : Int) : String

Returns the token string for an ID.

Source
vector_for(token_id : Int) : Slice(Float32)

Returns the raw embedding vector for a token ID.

Source
vocab
Source
vocab_size
Source