> ## Documentation Index
> Fetch the complete documentation index at: https://docs.runanywhere.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Embeddings & Reranking

> Turn text into vectors, and reorder results against a query

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

```ts theme={null}
const vectors = await RunAnywhere.embeddings.embed(['hello', 'world'])
console.log(vectors[0].vector.length)
```

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, and on
a phone that difference is seconds.

## Options

| Field       | Default | Meaning                                                    |
| ----------- | ------- | ---------------------------------------------------------- |
| `normalize` | `true`  | Unit-length vectors, so cosine similarity is a dot product |
| `pooling`   | `mean`  | How token vectors collapse into one                        |

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

## Reranking

```ts theme={null}
const ranked = await RunAnywhere.rerank.rerank('refund policy', candidates, 5)
```

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.

## Where this fits

Most people reach for these through [RAG](/react-native/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, 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, which matters on a phone.
