Book a free call

How to Implement Semantic Search Step by Step

Semantic search matches meaning, not just words. Here is how to implement it: prepare content, build embeddings, load a vector index, and test on real questions.

Hertiv engineering teamReviewed by a senior engineer
5 min read
How to Implement Semantic Search Step by Step
On this page

Short answer

Semantic search is search that matches meaning instead of matching exact words. A query for how to cancel a subscription finds a help article titled ending your plan because the two phrases mean the same thing, even though they share almost no words.

Semantic search is search that matches meaning instead of matching exact words. A query for 'how to cancel a subscription' finds a help article titled 'ending your plan' because the two phrases mean the same thing, even though they share almost no words.

It works by turning text into numbers called embeddings. Each document and each query becomes a list of numbers that places it in a space where nearby points have similar meaning. Search then means finding the nearest points to the query.

Keyword search still has a place. Exact names, codes and numbers are often better found by matching characters. Most real systems combine both and rank the merged results. That combination is the basis of RAG development, where search grounds the answers an AI gives.

Teams usually notice the gap when keyword search starts failing: users type a question in plain words and get no results, even though the answer is in the documents. That is the sign that meaning-based search would help, because the words in the question and the words in the answer no longer overlap.

What are the parts of a semantic search system?

A semantic search system has five parts, and each one can be changed without rebuilding the others. That separation is what makes the system maintainable.

Part What it does Common choice
Content store Holds the source documents Your existing docs or database
Chunker Splits documents into short passages Paragraph or section splits
Embedding model Turns passages into numbers Hosted API or open model
Vector index Finds nearest passages fast Managed index or self-hosted store
Ranker Orders results for the user Vector score plus keyword score

The chunker is the part teams underestimate. A passage that mixes three topics matches nothing well, while a passage cut mid-sentence loses the point. Good chunks follow the document's own structure.

Choosing an embedding model is a trade-off between quality, cost and control. A hosted API is quick to start and needs no servers, while an open model you run yourself keeps the data inside your own environment. Test both on your own questions before deciding, because a model that scores well on public tests may not score well on your documents.

How do you prepare your content?

You prepare content by cleaning it, splitting it and giving each passage enough context to stand alone. Search quality follows content quality; no embedding model fixes stale or duplicated documents.

Cleaning means removing navigation text, old versions and near-duplicates. If five versions of the same policy exist, the search returns all five and the user cannot tell which one applies.

Each passage should answer one thing and carry its source with it: the document title, the section and the date. A result without a source is a claim the user cannot check. Getting this right is a data engineering task as much as a search task.

Versioning matters as much as cleaning. When a document changes, its old passages must leave the index, or search will return answers that no longer apply. Give every passage a version and a date, and rebuild the embeddings for a document whenever the document itself changes.

How do you implement semantic search, step by step?

You implement semantic search in small steps, testing the result at each one, rather than building the whole pipeline and hoping the first test passes.

  1. Pick one collection of documents with a clear owner and a real set of questions.
  2. Clean and chunk the collection into passages that each answer one thing.
  3. Choose an embedding model and generate embeddings for every passage.
  4. Load the embeddings into a vector index that can return the nearest passages.
  5. Build a simple search page that shows the passage and its source.
  6. Test on real questions and fix the worst misses before adding features.

Keep the first version simple. A plain list of passages with sources beats a polished interface that returns the wrong passages.

Example: a support site with 40,000 articles

Example (hypothetical): a software company has a support site with 40,000 help articles. Support staff answer the same questions again and again because customers cannot find the article that answers them.

The team splits each article into passages of about 200 words. Articles average 3 passages each, so the collection becomes 120,000 passages. Each passage is turned into an embedding and loaded into a vector index.

The team tests the search on 200 real questions from past tickets. In the first test, 170 questions return the right article in the top 3 results, and 30 miss. The team reads the 30 misses and finds that 18 of them use product names that changed last year, so it updates those articles and re-tests.

After the update, the team runs the same 200 questions again. This time 188 return the right article in the top 3, and 12 miss. The team fixes the 12 one by one: four need a new article, five need a synonym added, and three are questions the support site was never meant to answer, so they are routed to a human instead.

You measure semantic search with a fixed set of real questions and known good answers. Without that set, every change is a guess and every debate about quality is anecdotal.

Track two numbers: how often the right passage appears in the top 3 results, and how often users click a result and stop searching. The first measures the system; the second measures whether it helped.

Improve the worst misses first. Most misses come from content problems: stale articles, missing synonyms, passages that mix topics, not from the model. Fix the content before you change the model. The cost side of the same build is covered in how much semantic search costs to build.

Hybrid ranking helps with the misses that content fixes cannot reach. A query with an exact product code should match the code first, while a query in plain words should match meaning first. Combining the vector score with the keyword score gives both kinds of query a fair result, and the mix can be tuned as the test set grows.

What are the common mistakes?

The most common mistakes are skipping the test set, chunking badly, and hiding the sources.

  • No evaluation set, so nobody knows if changes help
  • Passages that mix topics or cut sentences in half
  • Results shown without a source link
  • Indexing everything, including drafts and old versions
  • Choosing the model before cleaning the content

Key takeaways

  • Semantic search matches meaning; keyword search matches characters
  • Clean, well-chunked content matters more than the model you pick
  • Build in small steps and test on real questions at each step
  • Measure with a fixed question set and fix the worst misses first
  • Always show the source with the result so users can check it

Frequently asked questions

What is the difference between semantic search and keyword search?

Keyword search matches the exact words in the query. Semantic search matches meaning, so it finds a document even when it uses different words. Most real systems combine both: keyword search for exact names and codes, semantic search for meaning.

Do I need a vector database for semantic search?

You need a way to store embeddings and find the nearest ones fast, which is what a vector index does. That can be a dedicated vector database, a managed search service, or a library inside your own application, depending on how much data you have.

How many documents do I need before semantic search is worth it?

It helps once the collection is too large to browse, which for most teams is a few hundred documents. With a handful of pages, a simple list or keyword search is enough. The value grows as the collection grows.

Can semantic search work without AI?

No, in the usual sense. Semantic search depends on embeddings, which come from a trained model. The model can be a hosted API or an open model you run yourself, but some model has to turn the text into numbers.

How do I know if my semantic search is good enough?

Test it on a fixed set of real questions with known good answers. If the right passage appears in the top 3 results for most questions, and users stop searching after clicking, it is good enough to ship. Improve from there.

Is semantic search the same as RAG?

No. Semantic search finds the relevant passages; RAG uses those passages to ground the answer a language model gives. Semantic search is one part of a RAG system, and it works on its own as a search feature too.

Found this useful? Share it.
Hertiv engineering team

Written from projects we build for clients: AI and agent systems in production. Every post is reviewed by a senior engineer before publishing and updated when practice changes.

About HertivHow we work

Planning semantic search or RAG for your own documents? Talk to Hertiv.

A senior engineer replies within one business day. Or see our RAG Development service.

Book a free call

Keep reading

All posts

Tell us what you want to build

A senior engineer reads every request and replies within one business day with questions, a rough range, or a call link.

  • NDA on request before any details
  • You own all code, models and IP
  • US, UK and EU time-zone overlap

Your email app should open with your message ready to send. If it does not, write to [email protected].

Prefer email? Write to [email protected]
Estimate costBook a call