Local AI Local AI Intermediate

Generate Local Embeddings

Run embedding models for RAG without sending data to the cloud

59 of 66

What are embeddings?

Embeddings turn text into lists of numbers. Similar text gets similar numbers. They power search, recommendations, and retrieval-augmented generation (RAG).

Pull an embedding model

ollama pull nomic-embed-text

Generate an embedding

curl http://localhost:11434/api/embeddings -d '{
  "model": "nomic-embed-text",
  "prompt": "How do I reset my password?"
}'

Build a tiny RAG pipeline in Python

import requests, numpy as np

def embed(text):
    r = requests.post("http://localhost:11434/api/embeddings", json={
        "model": "nomic-embed-text",
        "prompt": text
    })
    return np.array(r.json()["embedding"])

def similarity(a, b):
    return np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b))

docs = [
    "Reset your password on the settings page.",
    "Our API supports OAuth2 authentication.",
    "Deploy with docker compose up."
]

vectors = [embed(d) for d in docs]
query = embed("How do I change my password?")
scores = [similarity(query, v) for v in vectors]
best = docs[np.argmax(scores)]
print(best)

Why local embeddings matter

  • Private documents stay on your machine
  • No per-token embedding charges
  • Fast for small-to-medium document sets

For larger collections, move vectors to a local vector database like Chroma or pgvector.

Working out which model to run this on? See The Codex. Packaging it as a reusable skill? See The Armory.