esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • AI papersPages
  • Interview KitPages
  • Book a callContact
Let’s talk

I’ll build the agent for it.

Design Semantic Search

How to design semantic search over a large document archive: indexing, search by meaning, keyword mix, access checks and tests, explained simply for your AI interview.

In short

Semantic search finds documents by meaning, even when the words differ. Text becomes lists of numbers called embeddings, the nearest ones win, and a good design adds keyword search, checks each user's access before ranking, and tests on real questions.

12 min readIntermediateCommon · estimateFacts checked 27 November 2026

Say it out loud

Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.

Semantic search finds documents by meaning. I turn each chunk of text into an embedding, which is a list of numbers, and store it in a vector index. A question gets the same treatment, and the index returns the closest chunks. I mix in keyword search for codes and names, re-sort the top 50, and check each user's access before ranking. Then I test on real questions and track how often the right page appears in the top 10.

What is semantic search, in plain words?

Keyword search looks for the same letters. Semantic search looks for the same meaning. The idea rests on OpenAI's text embeddings, which measure the relatedness of text strings, so texts with a similar meaning get lists of numbers that sit close together.

Think of a senior claims handler. A caller says "my cellar flooded after the pipe burst". She knows it is the same claim as "water damage from a burst pipe" in the rulebook, though not one word matches. Semantic search gives software the same habit, across 300,000 documents at once, which is what the insurer needs.

Key words

Embedding
A list of numbers that stands for the meaning of a piece of text.
Vector index
A store that holds embeddings and finds the closest ones quickly.
Chunk
A piece of a document, a few hundred words, that gets its own embedding.
Hybrid search
Keyword search and vector search run together, and their results are merged.
Reranker
A stronger model that re-sorts a short list of results before anyone sees it.

How does the search find the right chunks?

A search is a measurement. Each chunk and each question become points in a space with many directions, and the search returns the points closest to the question. OpenAI's guide explains it this way: "The distance between two vectors measures their relatedness. Small distances suggest high relatedness and large distances suggest low relatedness."

How a search finds the right chunks

When a document changes

Source documents

rules, wordings, guides

Who may read it

access tag on every chunk

Cut into chunks

a few hundred words each

On each question

Staff question

from a claims adjuster

Embedding model

turns text into numbers

Vector index

finds the nearest chunks

Re-sort top 50

a stronger model orders them

Answer with source

links the page it used

  1. 1Each file is read and tagged with who may see it.
  2. 2The tagged file is cut into chunks of a few hundred words.
  3. 3Each chunk becomes a list of numbers, stored once.
  4. 4The staff question becomes a list of numbers too.
  5. 5Each chunk's numbers are stored in the vector index, so they can be searched.
  6. 6The index passes its 50 closest chunks on to be re-sorted.
  7. 7The best few are shown with a link to their source.
Indexing runs once per change, and each question takes the query path. Both meet at the embedding model. The index returns the nearest chunks, keyword search runs beside it, and a stronger model re-sorts the merged top 50 before the answer shows its source.

Why embed each chunk once, instead of asking a language model to read the question against every page? Because that is far too slow at this size. For 10,000 sentences, the SBERT paper measured the effort of finding the most similar pair: 65 hours with BERT, about 5 seconds with SBERT, its embedding version.

The index also avoids checking every chunk. Large indexes use an approximate method, such as HNSW, which builds a layered web of nearby points and walks it toward the answer. The HNSW paper says this approach "allows a logarithmic complexity scaling." Approximate means a few true neighbours can be missed in exchange for speed, so the team tunes that setting on its test set.

Worked example. Say the archive makes 1.2 million chunks, that is 300,000 documents at about four chunks each. Each chunk has 1,536 numbers, the default length for OpenAI's text-embedding-3-small model in its guide, checked in November 2026. At 4 bytes a number, the raw vectors take about 7.4 GB before index overhead. The team uses Amazon OpenSearch Service, whose k-NN feature (nearest-neighbour vector search) stores and searches these vectors, so it does not run its own index, and the effort goes to access rules and tests.

Why mix keyword search with vector search?

Vector search finds meaning, but it can be weak on exact text. Microsoft's Azure AI Search documentation puts the fix in one line: hybrid search "combines the strengths of vector search and keyword search."

  • “Some scenarios, such as querying over product codes, highly specialized jargon, dates, and people's names, perform better with keyword search because it can identify exact matches.”

    Microsoft, Azure AI Search

  • Keyword only

    Exact words

    Finds 'SEC-4.2' every time. Misses the same rule written as 'exceptions to security controls'.

  • Vector only

    Meaning

    Finds the exception page from a plain question. Can return near misses for codes, because meaning-based matching does not reliably tell one code from a similar one.

  • Hybrid

    Both, merged

    Runs both searches at once. The two ranked lists are merged, so exact codes and plain questions both land near the top.

The merge is simple. Azure AI Search combines the two lists with Reciprocal Rank Fusion (RRF). In plain words, a page scores well if it ranks high in either list, and better if it ranks high in both. A staff member who types 'SEC-4.2 exception' gets the page with that code from the keyword side, and the page titled "Exceptions to security controls need CISO sign-off" from the vector side, both near the top. CISO means chief information security officer.

The reranker comes last, and it has a limit. Azure's semantic ranker re-sorts only the top 50 results from the first search. It cannot rerun the query over the whole archive, so if the right page is missing from those 50, no reranker can bring it back.

Tip

Tune the first search for recall, which means finding the right page somewhere in the list. Let the reranker sort the short list. Vectors sound modern, but product codes, names and dates still need exact matches.

How do you keep results inside each user's access?

This is where many first designs go wrong. OWASP's 2026 list warns that in systems that serve many customers or teams from one index (called multi-tenant), similarity search often runs across the whole index before the access check, which can reveal what exists in another customer's or team's documents even when every file is tagged correctly.

  • “Enforce tenant scoping inside the index query, not as a post-retrieval filter, and validate it server-side.”

    OWASP, LLM09:2026

So each chunk carries its access tag when it is indexed, and every query carries the user's identity. Azure's docs confirm the search engine can apply the filter in either order: "The search engine can process the filter before or after executing the vector query." The design choice is the order, and the rule is to filter first.

Filter inside the search, before ranking

Adjuster, Leeds

claims team, not fraud

Search first, filter later

Search everything

fraud files included

Filter first

Keep allowed chunks

checked before ranking

Restricted text ranked

reranker and answer see it

Only allowed text

the reranker never sees the rest

Fraud file quoted

a claims adjuster sees it

Claims files only

nothing restricted is shown

  1. 1Without a filter, the search runs over every file.
  2. 2With a filter, the first step is the user's own access.
  3. 3The restricted text goes on to the reranker and the answer.
  4. 4Only chunks this user may read reach the ranking step.
  5. 5A fraud file is quoted to a claims adjuster.
  6. 6The answer cites claims files only.
Two routes for the same adjuster. Searching everything and filtering later lets restricted text reach the ranking step and the answer. Filtering first keeps it out, so the answer only cites files the adjuster may read.

OWASP also says access control belongs at the chunk level, because a mostly public document can hold one confidential paragraph. Then log every search with the user, the query and the chunk ids returned, so a leak can be traced.

How do you know the search works?

Measure on real questions with known right answers. Ask claims experts for about 300 real questions, each with the page that answers it. Run keyword search alone and the hybrid design on the same set, then count how often the right page is in the top 10 results. That share is called recall at 10.

  1. 1

    Build the test set

    300 real staff questions, each with its right page, checked by two experts.

  2. 2

    Run each design

    Keyword only, vector only, and hybrid with rerank, on the same questions and the same access rules.

  3. 3

    Read every miss

    For each question where the right page was lost, find the step that lost it.

  4. 4

    Change one thing

    Run the whole set again, so you know which change helped.

Made-up numbers for illustration: keyword search puts the right page in the top 10 for 71 questions in every 100, and the hybrid design for 88. The 12 misses are where the work is. Many come from chunks cut in the middle of a clause, so the team changes the chunking and runs the set again.

Tip

A single score hides the failures. Show the misses to the claims team each week, because they know which wrong answers would cost the company money.

What does the interviewer want to hear?

A strong answer covers

  • A plain definition: search by meaning, using embeddings and nearest neighbours.
  • The two paths: index once, then embed the question and search.
  • Why keyword search stays: product codes, names and dates need exact matches.
  • Access checks inside the search, before any ranking.
  • Measured on real questions, with recall at 10 and the misses read by hand.
  • Honest limits: approximate search can miss, and a reranker cannot find what was missed.

Common traps

  • Trap"Vectors understand meaning, so we can drop keyword search."

    BetterExact codes, names and dates often need exact matches. Keep keyword search and merge both lists.

  • Trap"We filter the results after the search."

    BetterRestricted text can reach the reranker and the answer model first. Filter inside the search, before ranking.

  • Trap"Our demo looked great, so it works."

    BetterDemos use easy questions. Test on real questions with known right answers, and count the misses.

Can you spot the flaw?

Spot the flaw

A design review for the insurer's search lists four steps. Which one leaks restricted text?

Quick check

Staff search for 'SEC-4.2 exception' and the page with that code does not come up near the top. Which change is most likely to help?

Can you answer these from memory?

Flash cards · tap a card to flip it

1 / 6

What will they ask next?

  1. Q346What framework do you use for LLM system design answers?9 min
  2. Q348Design company document Q&A.13 min
  3. Q352Design a work copilot that never leaks data the user can't access.12 min
  4. Q356Design rate limiting.12 min
  5. Q347Design a customer-support chatbot.13 min

Learn it in depth

Last updated on 27 November 2026

Designing search over your company's documents?

I design and build AI products and agents, including the search behind them, with access rules and tests in place. Book a short call and tell me what your documents and users look like. No promises, no numbers.