ragcreator

ragcreator

Guide

Cosine similarity

Cosine similarity scores how closely two lists of numbers point the same way: 1 means the same direction, 0 means nothing in common. A RAG search turns the question and each passage into a list of numbers and returns the passages with the highest score. It compares direction, not size, so a long passage gets no head start over a short one.

See it run on a real handbook

The question is "Can I work remotely?" and the passage is page 9 of the handbook. Each becomes a list of word counts, with plurals and endings cut off, so "remotely" and "remote" count as one word:

The page has 10 other words. Each counts 0 in the question, so they add nothing to the sum but they do make the page's list longer.

Multiply the counts word by word and add them up: 4. Divide by the length of each list, 1.414 for the question and 4.583 for the page. The cosine is 0.617.

The same sum for all five pages of the handbook, best first:

A page that shares no word with the question scores 0, even if it means the same thing. That is the limit of counting words. The sample is the free X-ray's handbook, 5 short pages. Every number here is computed when the page loads, from that text, with the X-ray's own way of reading words.

How to read the number

Near 1 means the two texts point the same way. Near 0 means they share nothing the numbers can see. What counts as a high score depends on the model, so compare passages with each other instead of against a fixed cutoff.

Why a word count is not enough

The worked example above counts words, so a passage that says the same thing in other words scores 0. An embedding gives the same arithmetic better numbers to work on, and that is what a vector database searches.

Sources

Keep going

Build the whole pipeline on your documents

Works with the AI you already use: Claude, ChatGPT, any. We do not make the model smarter. We make your pipeline visible.