Skip to main content

embeddings.embed

Returns one vector per input, in input order, each carrying its index.
An empty list returns an empty list without touching the model. Anything else loads an embedding model first, downloading it when needed, and throws SDKException when none is available.
Embedding carries index (the position of the source text in your list) and vector, a Float32List.
The model parameter is a Flutter addition. The cross-SDK contract has embed(texts, options) only; pass model when you want to pin an embedding model for one call.

EmbedOptions

Both enums are prefixed EMBEDDINGS_NORMALIZE_MODE_ and EMBEDDINGS_POOLING_STRATEGY_.

Cosine similarity

With L2 normalization, cosine similarity is a dot product.

rerank.rerank

A cross-encoder scores each document against the query directly, which is more accurate than comparing embeddings but costs one forward pass per document. The usual pattern is to retrieve widely with embeddings, then rerank the shortlist.
Results come back sorted best first. RankedResult carries index, a pointer into your documents list, and relevanceScore, which is comparable only within one result set. An empty documents list returns an empty list. topN null returns every document. It throws SDKException when the SDK is not initialized or no rerank model is loaded. Unlike the generation verbs, rerank does not auto-load: load the model yourself first.

Reranking RAG results

Models

Embedding and rerank models are ONNX artifacts. Register the ONNX backend and the model, then load it.
See RAG for a complete multi-file embedding registration.

See also

RAG

Sessions that use both

Models

Registering ONNX models