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

# Local Embeddings

> Embed documents on-device with a built-in model.

Moss embeds documents on-device using a built-in model, so the text and resulting vectors
stay on the machine and embedding stays off the network path. You choose the model at index
creation.

## How it works

<div className="docs-diagram-frame">
  <img src="https://mintcdn.com/moss-afcfb0b6/qKHE-zU1VqxhLNDK/images/diagrams/local-embeddings-light.svg?fit=max&auto=format&n=qKHE-zU1VqxhLNDK&q=85&s=a6046639fccb9cd107633fb678e5b09a" alt="Text stays on device, flows through a local embedding model, becomes vectors, and is stored in a local index" className="docs-diagram-vertical mint-block dark:mint-hidden" noZoom width="214" height="648" data-path="images/diagrams/local-embeddings-light.svg" />

  <img src="https://mintcdn.com/moss-afcfb0b6/qKHE-zU1VqxhLNDK/images/diagrams/local-embeddings-dark.svg?fit=max&auto=format&n=qKHE-zU1VqxhLNDK&q=85&s=1eec31d66824e77a97df8ce9b6fa4753" alt="Text stays on device, flows through a local embedding model, becomes vectors, and is stored in a local index" className="docs-diagram-vertical mint-hidden dark:mint-block" noZoom width="214" height="648" data-path="images/diagrams/local-embeddings-dark.svg" />
</div>

## Setup

Pick the on-device model at index creation: `moss-minilm` (fast, lightweight) or `moss-mediumlm` (higher accuracy). Moss embeds your documents on-device with the model you choose. If you'd rather supply precomputed vectors from your own pipeline, see [Custom embeddings](/docs/integrate/custom-embeddings).

```ts theme={null}
import { MossClient } from '@moss-dev/moss'
const client = new MossClient(process.env.MOSS_PROJECT_ID!, process.env.MOSS_PROJECT_KEY!)
await client.createIndex('local-embeddings', docs, { modelId: 'moss-minilm' })
```

## Tips

* Batch inputs for speed
* Cache vectors for unchanged content
* Use hybrid retrieval for best relevance

## Related

<CardGroup cols={2}>
  <Card title="Custom embeddings" icon="vector-square" href="/docs/integrate/custom-embeddings">
    Bring your own precomputed vectors.
  </Card>

  <Card title="Sub-10ms knowledge retrieval" icon="gauge-high" href="/docs/build/offline-first-search">
    The local retrieval pipeline.
  </Card>
</CardGroup>
