Semtrace::Decomposer
Greedy residual decomposition of embedding vectors.
Given a target vector v, iteratively finds the nearest token embedding, subtracts it, and repeats until the residual norm falls below epsilon or max_steps is reached.
Constructors
Instance methods
Concept arithmetic: sum positive tokens, subtract negative tokens, decompose. Example: arithmetic(positive: [" king", " woman"], negative: [" man"]) = E(" king") - E(" man") + E(" woman")
Decomposes a target vector into a sequence of tokens. When lookahead > 1, evaluates the top-k candidates at each step and picks the one that minimizes the residual norm after subtraction.
Decomposes using inner product search. Requires the store to have an inner product HNSW index.
Decomposes using L2-normalized token vectors. Requires the store to have a normalized HNSW index (build_norm_index: true). Searches the normalized index AND subtracts normalized vectors.
Midpoint between two tokens.
Decomposes a bag-of-words sentence embedding (sum of static token embeddings).
Decomposes a single token's embedding (sanity check: should return itself).