Skip to content
Optimal Lab

AI Engineering · interactive

Embeddings and similarity search

Text becomes a direction in space. Closer directions are more alike. Pick a question, or click the plot, and see which notes come back.

Top match: Islamabad is the capital

Query in vector space

x -0.09 · y 1.00

Adjust the query and k, then run the search.

  • Islamabad is the capital 1.00
  • Karachi is a port city 0.91

Step 1 of 4

  1. 1

    Turn the question into a vector

    The question is a point. Its direction is what we compare, not the words themselves.

    What is the capital?

  2. 2

    Score every stored note

    Cosine similarity is 1 when two directions match, and near 0 when they do not.

    • Islamabad is the capital1.00
    • Karachi is a port city0.91
    • A cricket match lasts a day0.26
    • Soak rice, then layer the biryani0.17
  3. 3

    Keep the closest ones

    Top-k is how many notes you take back. The rest stay in the index.

    • Islamabad is the capital
    • Karachi is a port city
    • A cricket match lasts a day
    • Soak rice, then layer the biryani
  4. 4

    Hand those notes onward

    Search stops here. RAG is what pastes the retrieved chunks into a prompt for the model.