Embeddings turn a piece of text into a list of numbers — a vector — so that texts with similar meaning end up close together. That is the building block for searching your own documents: embed each document once, embed the question, and return the document whose vector is closest. LocalAI exposes this as an OpenAI-compatible embeddings endpoint.
Embed a text
First install an embedding model from the gallery, then call the endpoint. The docs show the embeddings endpoint is compatible with llama.cpp, bert.cpp and sentence-transformers models:
curl http://localhost:8080/v1/embeddings \
-H "Content-Type: application/json" \
-d '{"model": "your-embedding-model", "input": "The meeting notes say the launch moves to Friday."}'
Replace your-embedding-model with the name of the embedding model you installed — the model name in the request must match an installed model, or the call fails. The response is the standard OpenAI embeddings shape with a data[0].embedding array.
Turn vectors into search
- Split each document into short passages and embed each one.
- Store the passage text next to its vector.
- Embed the question the same way and compare it with the stored vectors.
- Send only the closest passages to the chat model with the question.
Use one embedding model for documents and questions alike: vectors from different models are not comparable. If you need a ready-made version of this pattern, see the separate guide on running a LocalAI embeddings model.
| Check | What you should see | If you do not see it |
|---|---|---|
| Embedding returns | The response contains data[0].embedding | The model name is wrong, or no embedding model is installed |
| Same model both sides | Documents and the question use one model | Mixed models give meaningless similarity scores |
| Top match is relevant | The closest passage answers the question | Passages are too long — split them smaller and re-embed |
Expected result. We checked the LocalAI text-and-retrieval docs for the embeddings endpoint, its llama.cpp / bert.cpp / sentence-transformers compatibility, and the standard OpenAI response shape. We did not run LocalAI, so the request above is UNTESTED on this machine.
Limits
Embeddings measure similarity of meaning, not truth: the closest passage can still be wrong or out of date. A chat model still needs the retrieved passage in its prompt — embeddings alone do not answer questions.
Sources
Sources checked 2026-11-28.
