Skip to content

embed

Embedding client wrapper: doc/query prompts + Matryoshka truncation.

Embedder

Doc/query prompt formatting + truncation over an OpenAI-style embeddings client.

embed_document(title, text)

Embed for storage, with DOC_PROMPT (or input_type=passage on NIM).

The doc and query prompts are asymmetric on purpose (see the module docstring): indexing and searching with the same prompt is the common embedding-search mistake this wrapper exists to prevent.

embed_documents(pairs)

Batch form of embed_document: ONE request for all (title, text) pairs, applying DOC_PROMPT to each and truncate_normalize to each returned vector -- same prompt, same normalization, same asymmetry guarantee, just fewer HTTP round trips.

Order safety is EmbeddingClient.embed_many's job (it sorts by the response index); this method just trusts the list it gets back is already aligned to pairs and truncates/normalizes each entry in place.

embed_query(text)

Embed a search query, with QUERY_PROMPT -- see embed_document.

truncate_normalize(vec, dims=None)

Slice a Matryoshka embedding to dims and renormalise to unit length.

Applied before every store or comparison: a raw vector's later dims carry finer distinctions a shorter, EMBED_DIMS-sized index deliberately drops, and slicing without renormalising would leave stored vectors at the wrong scale for cosine similarity. A model returning fewer dims than configured raises rather than silently zero-padding, which would fabricate signal.