Eurekly.

03 / Semantic search

Meaning, represented as numbers.

An embedding represents an item as a vector: an ordered list of numbers. Learned embeddings can make useful relationships easier to compare.

Search beyond matching words

A query like “How can I recover my password?” may be related to a passage titled “Resetting account access” even though the words differ. A text embedding model can map both into a shared space. A search system compares vectors to find candidate passages. See Google’s introduction to embedding spaces.

  1. Text
  2. Embedding model
  3. Vector comparison
  4. Candidate passages
Similarity search compares a query with stored vectors before returning candidate passages.

A transparent numerical example

Take a query vector q = [1, 0]. Compare candidate A = [0.8, 0.6] and candidate B = [0, 1]. All three vectors have length 1. Their cosine similarity is their dot product divided by the product of their lengths.

cos(q, A) = (1 × 0.8 + 0 × 0.6) / (1 × 1) = 0.8

cos(q, B) = (1 × 0 + 0 × 1) / (1 × 1) = 0

By this measure, A points more closely in the query’s direction. These are hand-chosen teaching numbers, not actual text embeddings. Real models typically use many more dimensions, and individual coordinates usually do not have simple named meanings.

The measure matters

Cosine similarity compares direction. A raw dot product also depends on vector length; Euclidean distance compares endpoints. Use the measure recommended for the embedding model and compare vectors produced by a compatible model. Cosine is undefined for a zero vector.

Put it to work

For study notes, embed passages and a question with a compatible model, retrieve candidates, then read the best matches. A high similarity score does not certify truth, freshness or permission to access a document. Access filtering and source checking remain separate responsibilities.

Try paraphrasing the same question, then asking an unrelated one. Check whether the retrieved passages are still helpful. Continue with RAG to see how retrieved evidence can support an answer, or revisit LLM fundamentals.

← All topics