I Asked an AI if Love and Hate Are Similar. It Said Yes.
From the publisher’s feed, collected in the ZeroLabs newsroom.
Day 10 — Welcome to embeddings. Where meaning is just maths.In Day 9 I built a RAG app. Every chunk of text got converted into 768 numbers before being stored. I called them embeddings, explained they “capture meaning”, and moved on.But I kept thinking — what does that actually mean? 768 numbers. How do numbers capture meaning? How does the model know that “happy” and “joyful” are similar? Nobody told it that.So I built another app. This one does one thing: take two pieces of text and tell you how similar they are. A score between 0 and 1.Then I tested it with some examples that genuinely surprised me.Spoiler — love and hate scored 0.80. By the end of this post you’ll understand exactly why.What Are Embeddings?Words go in. Numbers come out. That is what embeddings do. | Image: AI GeneratedAn embedding is what you get when you convert text into a list of numbers.Not random numbers. Numbers that carry meaning.Look at the image above. Words like “concept”, “language”, “perception” flow into the brain on the left. Numbers — 42, 3.14159, binary sequences — flow out on the right.That is exactly what an embedding model does. It takes your words and converts them into a list of numbers. In our app, each piece of text becomes exactly 768 numbers. Not more, not less. Always 768.But here is what makes it powerful — these are not random numbers. They are carefully positioned numbers that capture the meaning of the text.Similar words get similar numbers. “Happy” and “joyful” end up with very similar number lists. “Happy” and “pizza” end up with very different ones.The model learned these number positions by reading billions of sentences during training. It never explicitly learned that happy = joyful. It just saw them used in similar contexts so many times that they ended up with similar numbers.That is the whole idea. Words become numbers. Similar meanings become similar numbers. Compare the numbers. Find the meaning.The App I BuiltPOST /nearest in action — the app ranks sentences by meaning, not keywords. | Screenshot: Author’s ownSimple premise. Two routes:POST /similarity — compare two texts, get a score POST /nearest — give a query and a list, get them ranked by similarityNo paid APIs. No cloud. Runs on Ollama with the nomic-embed-text model locally.Project structure:similarity-app/├── server.js ← API routes├── src/│ ├── embedder.js ← converts text to vectors via Ollama│ └── similarity.js ← cosine similarity mathsThree files. That is a complete semantic search engine.The Code — Three Key Partsembedder.js — embedMany using Promise.allasync function embedMany(texts) { return Promise.all(texts.map(embed));}This one line is smarter than it looks. Instead of embedding texts one by one — waiting for each to finish before starting the next — it fires all requests simultaneously. If you have 10 texts to embed, they all go to Ollama at the same time. Much faster.similarity.js — cosine similarity in three stepsfunction dotProduct(a, b) { return a.reduce((sum, val, i) => sum + val * b[i], 0);}function magnitude(v) { return Math.sqrt(v.reduce((sum, val) => sum + val * val, 0));}function cosineSimilarity(a, b) { return dotProduct(a, b) / (magnitude(a) * magnitude(b));}I split it into three named functions on purpose. Most implementations write it as one dense formula. Breaking it into dotProduct, magnitude, and cosineSimilarity makes each step readable.Step 1 — multiply each pair of numbers and sum them up.Step 2 — find the “length” of each vector.Step 3 — divide to get a score between 0 and 1The closer to 1, the more similar the meaning. That’s it.server.js — the nearest endpointconst [queryVec, ...candidateVecs] = await embedMany([query, ...candidates]);const results = rankBySimilarity(queryVec, candidateVecs, candidates);Embed the query and all candidates in one call. Rank them. Return sorted results. The destructuring [queryVec, ...candidateVecs] is a clean way to separate the first item from the rest — the query from the candidates.What I Actually Tested — And What Surprised MeThis is the part I found most interesting. I ran six tests and some results genuinely stopped me.Test 1 — Same meaning, different words{ "text1": "I am happy", "text2": "I am joyful" }→ Score: 0.8743Makes sense. Synonyms score high. The model knows happy and joyful are used in similar contexts. No surprise here.Test 2 — Opposite meanings 🤯{ "text1": "I love cats", "text2": "I hate cats" }→ Score: 0.8064Love and hate scored 0.80. The app doesn’t lie. | Screenshot: Author’s ownThis one stopped me.Love and hate are opposites. You would expect a low score. Instead — 0.80. Almost as similar as happy and joyful.Why? Because embeddings care about topic and context, not sentiment. Both sentences are about cats and emotional feelings. The model sees them as closely related — because they are both about the same thing, even if the emotion is opposite.This is a real limitation of basic embeddings. They are not good at understanding sentiment. If you need to detect whether something is positive or negative, you need a different approach — sentiment analysis, not cosine similarity.Test 3 — Completely unrelated{ "text1": "Machine learning is transforming healthcare", "text2": "The pizza was delicious and crispy"}→ Score: 0.4053Low score as expected. AI and pizza have nothing in common in embedding space. This is what the score is supposed to look like for unrelated topics.Test 4 — Technical vs plain English{ "text1": "RAG retrieves relevant chunks using cosine similarity", "text2": "RAG finds the most relevant part of your document before answering"}→ Score: 0.5905This surprised me too. Both sentences describe the same thing — RAG. But one uses technical jargon and one uses plain English.Score: only 0.59. Moderately related, not highly similar.The jargon — “chunks”, “cosine similarity”, “retrieves” — creates enough distance in embedding space that the model treats them as related but not the same. This matters in practice. If you build a search system, the way users phrase their questions may not match how your documents are written. You need to account for that.Test 5 — Personal one{ "text1": "My favourite colour is pink", "text2": "She loves the colour pink"}→ Score: 0.915Very high. Different phrasing, same meaning, high score. This is exactly what made my RAG app work in Day 9 — the question “what is your favourite colour” matched the chunk “my favourite colour is pink” despite being worded differently.Test 6 — King vs Queen 🤯🤯{ "text1": "King", "text2": "Queen" }→ Score: 1.0Perfect score. One word each. Completely different words. Different genders. And yet — identical similarity score.How? Because in the billions of sentences the model trained on, King and Queen appear in almost identical contexts. Royal family. Chess. Playing cards. The model has seen them used so similarly, so many times, that in embedding space they end up in virtually the same location.This is the famous property of embeddings — meaning emerges from context. The model was never told King and Queen are related. It figured it out from patterns.What Embeddings Are Actually Used ForOnce you understand what embeddings do — convert meaning into numbers that can be compared — the applications become obvious:Semantic search — find documents by meaning not keywords. Search “heart attack” and find articles about “cardiac arrest” even if those exact words aren’t there.RAG — exactly what we built in Day 9. Find the most relevant chunks using embedding similarity.Recommendation systems — Netflix recommending shows, Spotify recommending songs. Find content similar to what you already liked.Duplicate detection — find near-identical content even when the wording is different.Clustering — group similar documents together automatically without labels.One Thing I Keep Thinking AboutThe King and Queen result stayed with me.The model was never taught that King and Queen are related. Nobody wrote a rule. Nobody created a lookup table. It just read enough human text that the relationship emerged naturally from patterns.That is how all of this works. Not rules. Not databases. Just patterns, at scale, producing something that looks like understanding.Whether that counts as real understanding is still an open question. But a score of 1.0 between King and Queen from a model that learned purely from reading text — that is remarkable either way.What I Learned TodayEmbeddings convert text into lists of numbers that capture meaningSimilar meanings end up with similar numbers — that’s how the model groups related conceptsCosine similarity measures the angle between two vectors — closer to 1 means more similarEmbeddings care about topic and context — not sentiment. Love and hate scored 0.80 because they’re both about the same topicTechnical jargon and plain English describing the same thing can score surprisingly low — 0.59King and Queen scored 1.0 — meaning emerged purely from patterns in training dataEmbeddings power semantic search, RAG, recommendations, and duplicate detectionPromise.all makes embedding multiple texts simultaneously much faster than sequential callsThe CodeFull project on GitHub: github.com/PriyankaMali-13/AI/tree/master/similarity-appClone it. Run the six tests I ran. See what surprises you.I’m Priyanka — backend engineer, chatbot builder, and someone learning AI from first principles. Writing everything down as I go. Follow along if that sounds useful.#365DaysOfAI #Embeddings #SemanticSearch #AI #Ollama #NodeJS #LLM #LearningInPublicI Asked an AI if Love and Hate Are Similar. It Said Yes. was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.