Skip to main content
Two namespaces that work together. embeddings turns text into vectors you can compare. rerank takes a query and a list of candidates and reorders them by relevance.

Embedding text

Vectors come back in input order, so index i of the result matches index i of the input. Batch rather than looping: one call with fifty strings is far cheaper than fifty calls.

Options

Leave normalize on unless you have a reason. With it off, similarity scores are not comparable across texts of different lengths.

Reranking

Reranking is a different model from embedding. An embedding model encodes each text once and compares vectors, which is fast and approximate. A reranker reads the query and the candidate together, which is slower and much more accurate. The usual shape is both: retrieve widely with embeddings, then rerank the top handful. Swift also exposes helpers on the vector type:

Where this fits

Most people reach for these through RAG, which does retrieval, reranking, and generation in one session. Use the namespaces directly when you want the pieces separately: semantic search with no generation, deduplication, clustering, or classification by nearest neighbour.

Models

Embedding and reranking models are small, often tens of megabytes rather than gigabytes. That makes them cheap to keep resident alongside a language model.