# Local embeddings

Run an embedding model like all-MiniLM-L6-v2 on your own server. It downloads once (tens of MB), then runs on CPU.

AI developers · Part 07: Hugging Face · Card 4 of 12 · Last updated 2026-10-13

## Analogy

Self-hosting your own image resizer instead of paying per image to a SaaS.

## Code example

`local-embed.ts`

```typescript
const embed = await pipeline("feature-extraction", "Xenova/all-MiniLM-L6-v2");
const output = await embed("How do I roll back a deploy?", {
  pooling: "mean",
  normalize: true,
});
const vector = Array.from(output.data); // 384 numbers
```

## In an agent

No API key, no per-call cost, and your docs never leave your server.

## Practice

### Flashcards

- **Interview: when do you pick an open-source model?** High-volume narrow tasks (embeddings, classification), strict privacy, or when cost per call matters.

## Questions people ask

### How do I create embeddings locally without an API key?

Use Transformers.js with pipeline feature-extraction and a small model such as Xenova/all-MiniLM-L6-v2. It downloads once, tens of megabytes, then runs on the CPU. Call it with mean pooling and normalisation turned on, and convert the output to a plain array of numbers to store in your vector database.

### Are local embeddings good enough for RAG?

For many projects, yes. Small models like all-MiniLM-L6-v2 handle typical English documentation well, cost nothing per call and keep your documents on your own server. Hosted embedding models can rank better on harder or multilingual data. Compare both on your own retrieval evals before deciding.

## Related concepts

- [Open weights](https://studyvisually.com/learn/tech/ai-developers/hugging-face/open-weights)
- [OpenAI vs Hugging Face](https://studyvisually.com/learn/tech/ai-developers/hugging-face/openai-vs-hugging-face)
- [The Hugging Face Hub](https://studyvisually.com/learn/tech/ai-developers/hugging-face/hugging-face-hub)
- [Transformers.js](https://studyvisually.com/learn/tech/ai-developers/hugging-face/transformers-js)

Web page: https://studyvisually.com/learn/tech/ai-developers/hugging-face/local-embeddings
Study this card in the app: https://studyvisually.com/app/learn?category=ai-developers&card=local-embeddings
