school Tutorials > Vector Similarity
Tutorial RAG Embeddings Vector Search Demo Mode No Paid API

Understanding Vector Similarity

Learn how embeddings, cosine similarity, dot product, and Euclidean distance are used in RAG and semantic search.

Ready to see vector similarity applied in a real system? Learn how RAG uses vector search to retrieve relevant document chunks →  ·  Why similarity scores matter in RAG pipelines →

school What are we learning here?

In modern AI applications like ChatGPT and custom enterprise search engines, software doesn't just look for exact word matches. Instead, it understands the meaning of your query. This is called Semantic Search, and it relies entirely on vector math.

tag Text as Vectors
AI models convert sentences and paragraphs into lists of numbers (vectors) representing semantic features.
compare_arrows Meaning Closeness
Sentences with similar meanings point in similar directions or are positioned close together in high-dimensional vector space.
database RAG & Vector Search
Retrieval-Augmented Generation (RAG) uses vector databases to fetch document chunks that match the query meaning, before feeding them to an LLM.

Predefined Dataset Sandbox: This page uses curated, predefined examples to stay free and fast without needing paid API tokens. Under the hood, it queries a real API to retrieve actual vector similarity values for these pairs. Use the sandbox below to see how these metrics respond!

architecture Interactive Similarity Sandbox

Select a comparison example below to dynamically calculate similarity scores across different metrics.

Selected Comparison
- vs -

insights Semantic Similarity Analysis

psychology

No Predefined Pair Selected

Select a curated demo pair from the explorer list on the left, or click the Random Preset button to populate values.

build Try exact supported pair (Advanced) expand_more

warning Only predefined pairs are supported. Random text will return an unsupported demo pair message.

menu_book Vector Similarity Terms

A quick guide to the main concepts used in this demo.

warning_amber
Important: This is educational demo mode

This sandbox uses predefined vector examples so it can stay free. It does not compare arbitrary text and does not call paid embedding APIs. The goal is to teach how vector similarity metrics behave.

explore Start with these key concepts:

Embedding Key Concept

An embedding is a vector created from text by an AI model.

Example: "dog" and "puppy" should get vectors that are close to each other.
Why it matters: Embeddings let software compare meaning, not just exact words.
Cosine Similarity Key Metric

Measures whether two vectors point in a similar direction.

Example: A score close to 1 means very similar. Around 0 means weak relation. Negative means opposite direction.
Why it matters: This is often the easiest metric for understanding semantic similarity.
Vector Search Application

Vector search finds items whose vectors are close to a query vector.

Example: A search for "backend developer" may find "Spring Boot engineer".
Why it matters: This is how many AI search and recommendation systems work.

list All Vector Similarity Terms (A-Z)

Quick Jump: Vector Embedding Dimension Cosine Similarity Euclidean Distance Dot Product Semantic Similarity String Similarity Vector Search RAG Query Vector Document Vector Chunk Nearest Neighbor High-Dimensional Demo Dataset
Vector expand_more

Explanation: A vector is a list of numbers that represents something, like a word, sentence, or document.

Example: "car" might become something like [0.2, 0.8, -0.1, ...]

Why it matters: Vector databases compare these number lists to find similar meaning.

Embedding expand_more

Explanation: An embedding is a vector created from text by an AI model.

Example: "dog" and "puppy" should get vectors that are close to each other.

Why it matters: Embeddings let software compare meaning, not just exact words.

Dimension expand_more

Explanation: A dimension is one number inside the vector.

Example: A 3D vector has 3 numbers. Real embeddings can have hundreds or thousands of dimensions.

Why it matters: This demo uses simplified vectors, but real embedding systems use much larger ones.

Cosine Similarity expand_more

Explanation: Measures whether two vectors point in a similar direction.

Example: A score close to 1 means very similar. Around 0 means weak relation. Negative means opposite direction.

Why it matters: This is often the easiest metric for understanding semantic similarity.

Euclidean Distance expand_more

Explanation: Measures how far apart two vectors are.

Example: A smaller distance means the vectors are closer.

Why it matters: Useful when you care about physical distance in vector space.

Dot Product expand_more

Explanation: Measures alignment and strength between two vectors.

Example: Positive means generally aligned. Around zero means weak alignment. Negative means opposite tendency.

Why it matters: Some vector search systems use dot product for fast similarity scoring.

Semantic Similarity expand_more

Explanation: Semantic similarity means similarity in meaning, not spelling.

Example: "car" and "vehicle" are semantically similar, even though the words look different.

Why it matters: This is the core idea behind embeddings and vector search.

String Similarity expand_more

Explanation: String similarity means the words look similar as text.

Example: "cache" and "cash" look similar, but they do not mean the same thing.

Why it matters: This demo should show that spelling similarity is not the same as meaning similarity.

RAG (Retrieval-Augmented Generation) expand_more

Explanation: RAG means Retrieval-Augmented Generation. It retrieves relevant documents before asking an AI model to answer.

Example: User asks a question, the system finds related chunks, then the AI uses them in the answer.

Why it matters: Vector similarity is often used to find the relevant chunks.

Query Vector expand_more

Explanation: The vector created from the user's search or question.

Example: "How does JWT authentication work?" becomes a query vector.

Why it matters: The system compares this vector against document vectors.

Document Vector expand_more

Explanation: The vector created from a stored document, paragraph, or chunk.

Example: A paragraph about JWT tokens gets converted into a document vector.

Why it matters: Documents with vectors close to the query vector are likely relevant.

Chunk expand_more

Explanation: A chunk is a smaller piece of a larger document.

Example: A long article can be split into 20 smaller chunks.

Why it matters: RAG systems usually search chunks, not whole documents.

Nearest Neighbor expand_more

Explanation: The nearest neighbor is the closest vector to the query vector.

Example: If "vehicle" is closest to "car", it may be returned first.

Why it matters: Vector databases use nearest-neighbor search to find relevant results.

High-Dimensional Vector expand_more

Explanation: A vector with many dimensions.

Example: This demo may use 8 dimensions, but real embeddings can use hundreds or thousands.

Why it matters: The UI is simplified, but the concept is the same.

Demo Dataset expand_more

Explanation: This tool uses predefined educational examples, not live AI embeddings.

Example: Only supported pairs like "car vs vehicle" or "Java vs JavaScript" can be compared.

Why it matters: The site stays free and does not call paid AI APIs for every user.

hub How this works in a real RAG system

An end-to-end view of retrieval-augmented generation using vector databases.

1

content_cut Split Documents

Large documents are divided into smaller, logical text chunks (paragraphs or sections) so search results can point to highly specific passages.

2

psychology Convert to Embeddings

An AI embedding model processes each text chunk, turning it into a high-dimensional vector containing numeric representations of the chunk's meaning.

3

storage Store in Vector DB

These vector embeddings are stored along with their original text inside indexing databases (like Pinecone, Qdrant, or Weaviate) optimized for quick lookup.

4

search Vectorize User Query

When a user enters a question, the application passes that text to the exact same embedding model to obtain a real-time 'query embedding' vector.

5

compare Nearest Neighbor Search

The vector database runs cosine similarity or dot product calculations to identify and retrieve the database chunks closest to the query vector.

6

chat LLM Completion

The app builds a prompt combining the user question and the retrieved text passages, prompting the LLM to write an accurate, context-grounded answer.

spellcheck Why spelling is not meaning

AI embeddings analyze conceptual relationships, not alphabetical alignment.

Traditional search systems (like SQL LIKE queries or basic text filters) match exact characters. If terms share several letters, character-matching algorithms consider them similar. But meaning-based embeddings focus on context and relationships.

close High Spelling Similarity, Low Semantic Similarity

Words look almost identical text-wise, but describe completely unrelated things:

  • cache vs cash: temporary storage device vs physical paper money
  • Java vs JavaScript: compiled backend OOP language vs client-side web scripting language
  • model vs modal: machine learning system model vs overlay UI modal popup
  • route vs root: URL router pathname path vs root system user administrator
  • docker vs doctor: container engine runtime vs medical health professional
Sandbox Experiment

Try spelling-similar preset comparisons

We have predefined these exact pairs in our sandbox dataset. Filter the list to see how cosine similarity drops to near zero for spelling-similar words with separate meanings.

local_library Learn More

A curated list of reliable, official learning articles and documentation.

OpenAI Embeddings Guide open_in_new

Official guide explaining semantic vector embeddings, dimensionalities, API usage, and distance metrics.

Google ML Crash Course open_in_new

Translate complex high-dimensional spaces to lower ones using Google's introductory machine learning curriculum.

Pinecone Vector Embeddings open_in_new

A deep, developer-friendly guide detailing vector embedding algorithms, applications, and indexes.

Weaviate: Embeddings Explained open_in_new

Clear explanation of vector semantic structures, vector spaces, and how AI representations differ from raw strings.

Qdrant Vector Search Concepts open_in_new

Detailed system documentation describing how similarity metrics operate inside a production-grade vector database.

info
What this demo does not do

This application is an educational demo utilizing predefined example pairs from a server dataset. It does not calculate embeddings for arbitrary user text input in real-time, nor does it make calls to paid external services like OpenAI or Cohere APIs. In real production search applications, you would run a dedicated embedding model (such as text-embedding-3-small) to generate vectors, then index them into a production vector database.

grid_on Manual 2D Math Playground expand_more

grid_on Interactive Visualizer Space

Vector A Vector B
A (4.0, 3.0) B (2.0, -3.0)
Real embeddings are high-dimensional. This chart is a simplified visual explanation.

insights Live Metric Interpretations

Cosine Similarity Similar
0.800
Vectors point in a very similar direction.
cos(θ) = (A · B) / (||A|| ||B||)
Dot Product Aligned
14.00
Positive alignment: vectors point in a similar general direction.
A · B = ∑ A_i B_i
Euclidean Distance Moderate
6.32
Moderate spatial distance between vector heads.
d = √ ∑ (A_i - B_i)²
psychology

How this relates to RAG and embeddings

In real Retrieval-Augmented Generation (RAG) systems, text and unstructured data are converted into high-dimensional vector embeddings. Vector databases compare these vectors using similarity or distance metrics to retrieve the most semantically relevant content. This sandbox is a simplified 2D visual version of what happens in high-dimensional embedding search.

database Vector Embeddings

Models (e.g. text-embedding-3) transform text chunks into lists of float coordinates. Direction represents semantic meaning, while length represents frequency or magnitude.

compare_arrows Similarity vs. Distance

Cosine Similarity is standard for text comparison because it isolates semantic direction. Euclidean Distance measures absolute geometric separation.

lightbulb Real-world intuition

🎯

Query vs Relevant Document

High cosine similarity (close to 1.0) indicates that the query vector and the document vector point in a very similar semantic direction. The document is highly relevant.

Query vs Unrelated Document

A cosine similarity around 0.0 means the vectors are orthogonal (perpendicular). There is no measurable semantic alignment between the search query and the target content.

Opposite Meaning or Direction

Negative cosine similarity values (approaching -1.0) mean the vectors point in opposing directions in this simplified space, representing contradictory meaning or topics.