Embeddings and a RAG teaser
Embeddings turn text into fixed-length float vectors for semantic search, clustering, and RAG. Dimension count is model-specific (often about 384–1024). Officially, /api/embed returns L2-normalized (unit-length) vectors, so cosine similarity is the usual metric.
Do not embed with a chat model: it is slow and not trained as a retriever. Pick an embedding model on ollama.com/library and ollama pull it.
Pull a current embedding model
The capabilities page currently highlights embeddinggemma, qwen3-embedding, and all-minilm. You will still see these in the wild:
Names and tags change. Confirm on Library, then:
CLI can emit a JSON array of floats:
Index and query must use the same embedding model or the spaces will not line up.
REST: /api/embed
Batch:
Optional fields: truncate, dimensions (if the model supports it), keep_alive.
Windows PowerShell:
OpenAI-compatible: POST http://localhost:11434/v1/embeddings with model and input.
Official libraries
Smallest retrieval intuition
- Split documents (by heading or about 300–800 tokens).
embedeach chunk; store vectors with the raw text (Chroma, FAISS, pgvector, …).- Embed the user question with the same model.
- Take the top-k cosine hits, stuff them into a prompt, then
chat/generate.
Sketch:
For unit vectors, cosine equals a dot product. This is teaching code; production needs a real ANN index and metadata filters.
Hook into LangChain RAG
The full pipeline (Loader → Splitter → VectorStore → Retriever → Agent) lives in this site’s LangChain tutorial:
- RAG
- Tool-using Q&A: Practical examples
You can swap OpenAI embeddings for Ollama embeddings and drive chat with ChatOllama or ChatOpenAI aimed at /v1, keeping data on-box. Dify knowledge bases that select an Ollama embedder follow the same “one model for index and query” rule—see Integrations and Dify.
Watch-outs
- Changing the embedder means re-embedding the whole corpus.
- Judge Chinese quality on your documents, not only English leaderboards.
- Embedders occupy VRAM too; watch
ollama psif a 30B chat model shares the GPU.