DEV Community

Cover image for Vectors & Similarity Search: How AI Finds Meaning Instead of Keywords
MANGESH MANDLIK
MANGESH MANDLIK

Posted on

Vectors & Similarity Search: How AI Finds Meaning Instead of Keywords

Imagine searching for:

How do I scale PostgreSQL?

Now imagine the best document in your knowledge base is titled:

Horizontal Scaling of Relational Databases

A traditional search engine might completely miss it.

The document is clearly relevant. A human would immediately make the connection.

But keyword search doesn't think like a human.

It doesn't understand that:

  • PostgreSQL is a relational database
  • Scaling and horizontal scaling are related concepts
  • Sharding, replication, and scaling often appear in the same discussions

It only sees words.

Modern AI systems work differently.

Instead of searching for words, they search for meaning.

That's where vectors and similarity search come in.

They're the reason ChatGPT can retrieve relevant documents, GitHub Copilot can find related code, and AI-powered search feels dramatically smarter than traditional keyword search.


The Missing Piece After Embeddings

In the previous article, we looked at embeddings.

Embeddings convert text into vectors — long lists of numbers that capture meaning.

For example:

"PostgreSQL Replication"
→ [0.23, -0.81, 0.44, 0.67, ...]

"Database Sharding"
→ [0.19, -0.77, 0.51, 0.61, ...]

"Pizza Recipes"
→ [0.71, 0.33, -0.28, -0.52, ...]
Enter fullscreen mode Exit fullscreen mode

The actual numbers aren't important.

What matters is where those vectors end up.

Concepts with similar meanings tend to be positioned close together.

Unrelated concepts end up further apart.

That raises an interesting question:

If meaning becomes a location, can we search by location instead of words?

That's exactly what similarity search does.


Think of It Like Google Maps

Imagine opening Google Maps and searching for a coffee shop nearby.

Google doesn't search for every coffee shop in the world.

Instead, it looks for locations that are close to your current coordinates.

Similarity search works the same way.

Except instead of cities and roads, we're dealing with ideas.

In this semantic map:

  • PostgreSQL is near replication
  • Replication is near scaling
  • Scaling is near sharding

Meanwhile:

  • Pizza recipes
  • Football scores
  • Travel itineraries

end up somewhere completely different.

The closer two vectors are, the more related their meanings tend to be.


Searching for Meaning Instead of Words

Let's revisit our query:

How do I scale PostgreSQL?

The search system first converts that query into an embedding.

Now it has a vector representing the meaning of the question.

Instead of scanning documents for exact words, it searches for nearby vectors.

The results might include:

  • PostgreSQL replication strategies
  • Database sharding techniques
  • Read replica architectures
  • Partitioning large databases

Notice something interesting.

The exact phrase:

scale PostgreSQL

might not appear anywhere.

Yet the results are still relevant.

That's the power of semantic search.


Why Keyword Search Isn't Enough

Keyword search is fantastic for certain problems.

If you're searching for:

  • Order ID 928372
  • User account mangesh
  • Error code ERR_403
  • Invoice number INV-1024

you want exact matches.

But humans rarely communicate using identical words.

We paraphrase.

We use synonyms.

We describe concepts in different ways.

Someone might search:

How can I speed up my database?

while the document says:

Improving PostgreSQL query performance

The meaning is similar.

The wording is not.

Keyword search struggles here.

Similarity search thrives.


What Is a Vector, Really?

The word vector sounds intimidating, but the idea is simple.

A vector is just a list of numbers.

For AI systems, those numbers represent learned patterns.

Think of a vector as a coordinate in a giant multidimensional map.

If two pieces of information are related, their coordinates tend to be nearby.

If they're unrelated, they tend to be further apart.

The embedding model learns those relationships during training.

By the time the vectors are created, similar concepts have naturally clustered together.


The Geometry Behind AI Search

One of the coolest things about embeddings is that semantic search becomes a geometry problem.

The system isn't asking:

Which document contains these words?

It's asking:

Which vectors are closest to this vector?

That's a fundamentally different approach.

Distance becomes a proxy for meaning.

Near vectors imply related concepts.

Far vectors imply unrelated concepts.

Search suddenly becomes less about language and more about mathematics.


Measuring Similarity

Of course, we need a way to determine whether two vectors are close together.

Several approaches exist, but the most common is Cosine Similarity.

Rather than measuring physical distance, cosine similarity measures how closely two vectors point in the same direction.

Conceptually:

Similar meanings
      ↘
       ↘
        ↘

High similarity score
Enter fullscreen mode Exit fullscreen mode

Vectors pointing in similar directions tend to represent similar concepts.

This works surprisingly well for text, code, and many other forms of data.


Why This Becomes Difficult at Scale

Now imagine storing:

  • 100 million document embeddings
  • 1,536 dimensions each

A straightforward approach would compare the query vector against every single vector.

For every search.

That's a lot of math.

Even modern hardware would struggle to deliver fast results at that scale.

We need a smarter approach.


Enter Approximate Nearest Neighbor Search

This is where things get interesting.

Most AI systems don't search every vector.

Instead, they use algorithms designed to find vectors that are probably the closest.

This technique is called:

Approximate Nearest Neighbor (ANN) Search

The tradeoff is simple:

  • Slightly less precision
  • Dramatically faster retrieval

In practice, ANN search is so effective that it powers most production vector databases today.

Users get results in milliseconds instead of seconds.


Why Vector Databases Exist

Traditional databases were built for:

  • Transactions
  • Joins
  • Aggregations
  • Structured queries

They weren't designed for questions like:

Find the 20 most semantically similar documents.

Vector databases were built specifically for that problem.

Their job is to:

  • Store embeddings
  • Build efficient indexes
  • Run similarity searches
  • Filter results using metadata
  • Return relevant matches quickly

Popular options include:

  • Pinecone
  • Qdrant
  • Weaviate
  • Milvus
  • pgvector

Each approaches the problem slightly differently, but the goal remains the same:

Find nearby meaning as quickly as possible.


Where You Already Use Similarity Search

Even if you've never built a vector database, you're probably using similarity search every day.

ChatGPT and RAG Systems

When an AI assistant retrieves documents before answering a question, similarity search is often doing the retrieval.

The system embeds:

  • The user's question
  • The stored documents

and finds the closest matches.

GitHub Copilot

Copilot searches your codebase for relevant functions, files, and examples before generating suggestions.

Enterprise Search

Tools like Notion AI, Slack AI, and Confluence AI use semantic retrieval to search large collections of internal knowledge.

Recommendation Engines

Netflix, Spotify, Amazon, and many other platforms use embeddings to find content similar to what users previously enjoyed.

Different application.

Same core idea.

Find nearby vectors.


Why This Matters for RAG

Many developers first encounter similarity search while building Retrieval-Augmented Generation systems.

RAG works because:

  1. Documents are converted into embeddings.
  2. User questions are converted into embeddings.
  3. Similarity search finds relevant chunks.
  4. Those chunks are sent to the LLM.
  5. The LLM generates a response using retrieved context.

Without similarity search, RAG would largely fall back to keyword matching.

The quality of retrieval would drop significantly.

In many RAG systems, retrieval quality matters as much as model quality.

Sometimes more.


The Bigger Idea

One of the most important shifts in modern AI is that we're increasingly moving away from exact matching.

Instead of asking:

Does this text contain these words?

we ask:

Does this information mean something similar?

Vectors and similarity search make that possible.

They allow machines to retrieve concepts rather than keywords.

That's why modern AI systems feel so much more intuitive than traditional search systems.

They're operating on meaning, not just text.


Final Thoughts

Embeddings turn meaning into numbers.

Similarity search turns those numbers into retrieval.

Vector databases make that retrieval practical at scale.

Together, they form the foundation of semantic search, RAG systems, recommendation engines, enterprise search platforms, and many of the AI products we use every day.

Once you understand vectors and similarity search, a lot of AI starts feeling less magical.

It's still impressive.

But you can finally see the engineering underneath.


Explore It Visually

Reading about vector search is useful.

Watching a query move through embeddings, vector space, ANN retrieval, and semantic search makes the whole process much easier to understand.

I've created an interactive visual walkthrough here:

https://seeitflow.com/ai/ai-foundations/vectors-similarity-search

Because some concepts click faster when you can actually see them work.

Top comments (1)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.