Your First Embedding
Sentence transformers.
Let's make a real embedding. We'll use a small, free model called all mini LML six v two, from the sentence transformers library. It runs on your own computer, with no API key.

- A small free model
- Runs locally
- No API key
Embedding a sentence
We load the model, on the CPU. Encode turns a list of sentences into vectors. Normalise embeddings scales each vector to length one, which makes comparing them easy. Run it. One sentence becomes three hundred and eighty four numbers.
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("all-MiniLM-L6-v2", device="cpu")
vectors = model.encode(["How long does charging take?"], normalize_embeddings=True)
print("shape:", vectors.shape)
print("first five numbers:", vectors[0][:5].round(3))shape: (1, 384) first five numbers: [ 0.049 0.068 -0.048 0.085 0.037]
Choosing a model
Small local models are free, private, and fast. API models, like Gemini's, are often more accurate, especially for long or technical text, but each call costs a little, and your text leaves your computer. Always embed your chunks and your questions with the same model.
| key | value |
|---|---|
| Local | free, private |
| API | often more accurate |
| Same model | for chunks and questions |
| Size | 384 to 3072 numbers |
Summary
Sentence transformers turns text into vectors locally. Always use the same model for chunks and questions. Next, measuring how close two meanings are.
Key takeaways- SentenceTransformer
- encode
- normalize_embeddings