# Vector and Embeddings : 101

> Source: <https://blog.devgenius.io/vector-and-embeddings-101-b8cb3e764897?source=rss----4e2c1156667e---4>
> Published: 2026-06-30 13:06:29+00:00

Every agent eventually needs to remember something — **a past turn, a doc chunk, the right tool** for a job it’s seen before. The thing doing the remembering is almost always a **vector**.

We treat embeddings as magic: “**the model understands meaning now**.” Then we wire a vector DB into retrieval, watch it return *mostly* the right thing, and ship. That holds until it doesn’t — and the failure is quiet. The agent doesn’t crash; it gets slightly **wrong context **and proceeds to be fluently, confidently wrong.

Two takeaways: why similarity is geometry, not magic, and exactly where that geometry lies to you in production.

Look at your own bookshelf. You didn’t shelve it alphabetically. The travel books drifted together, the **half-read sci-fi** formed a cluster, the work books colonized one end — each book found its neighbors by what it’s *about*. When a friend wants something like the novel they just loved, you don’t look up a category. You walk to that book and grab whatever’s next to it.

That’s an embedding space. **A vector is a book’s position** — coordinates that say where a piece of text lives. Position encodes meaning, so “nearby” means “similar,” and nearby is computable. Scale the shelf to a library and it still holds: a cookbook lands near a chemistry text because both are, underneath, about transforming matter with heat.

One catch: the coordinates aren’t **human-readable**. A sentence might become 768 numbers, none of which is “** the finance dimension.**” Only the *relationship between whole vectors* carries signal — the geometry between addresses, never the addresses.

Similarity is distance, and for text the right measure is cosine — the angle between two vectors, ignoring length. **Same direction → 1.0, perpendicular → 0**. You care that two things are *about* the same thing, not the same length. The whole of it:

``` python
import numpy as np
python
def cosine(u, v):    return float(np.dot(u, v) / (np.linalg.norm(u) * np.linalg.norm(v)))
```

Dot product on top, the two lengths on the bottom to cancel magnitude. That division is why cosine beats raw dot product, where a vector that’s merely “big” scores high against everything.

Embed three sentences and print the similarity matrix — Ollama with nomic-embed-text, fully local (ollama pull nomic-embed-text first):

``` python
import ollama, numpy as np
sentences = {    "refund":  "How do I get my money back for a cancelled order?",    "return":  "What's the process to send an item back for a refund?",    "weather": "Will it rain in Bengaluru this weekend?",}
python
def embed(t):    return np.array(ollama.embeddings(model="nomic-embed-text", prompt=t)["embedding"])
python
def cosine(u, v):    return float(np.dot(u, v) / (np.linalg.norm(u) * np.linalg.norm(v)))
vecs = {k: embed(v) for k, v in sentences.items()}for a in vecs:    print(a, [f"{cosine(vecs[a], vecs[b]):.2f}" for b in vecs])
```

refund and return share almost no words yet land close, because they *mean* the same thing. weather sits far from both. This is the retrieval primitive under your agent's ** think → act → observe** loop: embed the situation, grab the nearest vectors, stuff them into context. Good geometry → relevant context. Bad geometry → the model reasons beautifully over the wrong facts.

An embedding is lossy compression of meaning. What it discards is where retrieval quietly breaks. Five guards I check before trusting a retrieval layer:

Embeddings turn meaning into geometry so “**find me something relevant**” becomes “find me something nearby.” Powerful — but a trade: you compressed meaning to make it computable, and compression lies at the edges. Get the geometry right and the agent reasons over the right facts. Get it wrong and it’s articulate about the wrong thing — worse than a crash, because nothing tells you it happened.

Note: This blog includes AI-assisted content to help explain concepts more clearly.

*For feedback, please drop a message to **amit[dot]894[at]gmail[dot]com **or reach out to any of the links at **https://about.me/amit_raj**.*

Next in the series · **building the retrieval layer — chunking, the re-ranking pass**, and a relevance gate that lets the agent say “I don’t have this” instead of guessing.

[Vector and Embeddings : 101](https://blog.devgenius.io/vector-and-embeddings-101-b8cb3e764897) was originally published in [Dev Genius](https://blog.devgenius.io) on Medium, where people are continuing the conversation by highlighting and responding to this story.
