UGLYPEAR AI completes its business upgrade: High-Performance Document Compression × RAG Data Engineering PlatformLearn about the New Business →

Keyword Search vs Semantic Retrieval, a Developer's Field Notes

If you build internal tooling, you've probably shipped a wiki, a docs site, or a "just ask in Slack" bot that quietly failed. The failure mode is almost always the same: people type a question the way humans ask, and the system answers the question "which documents contain these exact words?" That's not what was asked, and after the third wrong result people stop using it.

The cost of that failure is real. McKinsey has estimated that knowledge workers spend roughly 19% of their work week — about an hour and a half a day — just searching for and gathering information. Asana's Anatomy of Work research puts the time to refocus after an interruption at around 23 minutes, with people switching between roughly 35 different apps in a day. Multiply that across a team and bad retrieval is a measurable tax.

This post is a principle-level tour of semantic retrieval — the approach that tries to match meaning instead of strings — aimed at developers who want to understand the moving parts before they build or buy anything. No vendor internals, no stack prescriptions. Just the concepts and the trade-offs.

Keyword search vs semantic search

Keyword (or lexical) search is a set of tricks for finding documents that share tokens with your query. It works well when the author used the same vocabulary you did, and poorly when they didn't. Its strengths are transparency and predictability: you can see why a result matched because the words are right there.

Semantic search tries to answer "which documents are about the same thing as this question?" It does that by representing both the question and each document as a fixed-length vector in a space where proximity means topical similarity. A query about "how a freelancer gets VPN access" can land near a doc titled "external vendor remote network provisioning" even though they share no words.

The mental model that helped me: keyword search is a spell-checker for exact letters; semantic search is a translator for intent.

How it works at the principle level

You don't need to know model names to understand the shape of the system. The pipeline looks like this:

  1. Represent the corpus. Every document (or passage) is turned into a vector. This step is usually done once, when content is added or changed.
  2. Represent the query. The same representation is applied to the user's question at ask time.
  3. Find neighbors. The system looks for the stored vectors closest to the query vector, using a similarity measure.
  4. Return or ground an answer. The top matches are shown, or passed to a generator that synthesizes a response with citations.

Two principles worth internalizing:

  • Coverage is a prerequisite, not a tuning knob. If a document was never represented, it is invisible to step 3 no matter how good the matching is. A corpus that covers merely a portion of its documents will systematically miss answers sitting in the unrepresented slice. This is a recurring silent failure in real deployments.
  • Granularity matters. Representing a 200-page PDF as one vector loses the thread; representing every sentence can create noise. Many practical systems represent passages or chunks, then resolve to the source page for the human.

A note on the search itself: finding nearest neighbors over a large vector set is not something you want to do by brute force. In practice you use an index that trades a little recall for a lot of speed, which is why retrieval latency stays in the seconds rather than the minutes as the corpus grows.

The token and retrieval economics of RAG

RAG — retrieval-augmented generation — is the pattern where you retrieve relevant context and feed it to a generator so the answer is grounded in your own documents. The economics are why it exists:

  • You can't stuff the whole corpus into a prompt. Context windows cost tokens, and the more irrelevant text you include, the more you pay per question and the more you dilute the signal. Retrieval is the filter that keeps the context window small and on-topic.
  • Relevance filtering saves money and improves answers. A good retriever means fewer, better passages reach the generator, which means shorter, cheaper, more accurate responses.
  • Latency is a budget, not a constant. Every stage — represent the query, search the vector store, assemble context, generate — adds time. The retrieval stage in particular can dominate if the corpus is large or the index isn't tuned. The win condition is "answer in seconds," because a tool that takes minutes trains people to stop using it.

A useful framing: retrieval is where you spend compute to save tokens and to protect answer quality. Under-invest there and you pay for it three ways — in cost, in latency, and in trust.

A selection framework: when to use which

Newcomers often ask "which one should I pick?" The honest answer is that the two are not mutually exclusive, and the choice depends on what your queries look like. A simple decision lens:

  • Pure keyword is enough when your users phrase requests like titles and the vocabulary is stable — policy lookups, part-number searches, legal clause citation.
  • Semantic earns its keep when phrasing varies, synonyms are common, or the "right" answer shares no words with the question — onboarding questions, how-to lookups, tribal-knowledge retrieval.
  • A hybrid is the default worth building for a general knowledge base: lexical for precision on known terms, semantic for recall on natural language. You rank and merge rather than bet on one.

The differentiator for a private deployment is almost never the headline model; it's coverage, phrasing tolerance, and where your data lives. Pick the layer you'll actually maintain.

How do you know retrieval is actually good?

This is the part newcomers skip. You need an evaluation harness, not a vibe. The lightweight version: assemble a set of questions where you already know the correct source passage, then check whether the system surfaces that passage in the top results. Mix the phrasings — casual and formal — because people won't ask like your titles read. When every question in that set reaches its target passage, you have evidence rather than hope.

Common failure modes

A few ways these systems go wrong in practice, none of which show up in a demo:

  • The coverage gap. As noted, unrepresented documents are invisible. The classic symptom: you ask about something you know is in the wiki and get nothing, because that file was added before representation was turned on. Backfilling coverage is unglamorous and absolutely necessary.
  • Staleness. Documents change. If the representation isn't refreshed when content changes, the system answers from a memory of text that no longer exists. Build the refresh into the write path, not as a manual afterthought, or drift will quietly erode trust.
  • Over-broad chunks. If passages are too large, a match pulls in a whole section when only one sentence was relevant, which dilutes whatever consumes the context downstream. Too small, and you lose the surrounding meaning. The right size is a tuning problem specific to your content.
  • No phrasing tolerance. A system that only understands formal queries forces users to learn its language. That's just keyword search with extra steps. Test with the sloppiest queries your teammates actually type, not the polished ones you'd put in a title.
  • Ignoring permissions. Retrieval that surfaces a document the asker isn't allowed to see is worse than no answer. Permission checks belong in the retrieval step, not bolted on at display time, or you'll leak by accident.

A real recent improvement, shared honestly

I'll share one concrete before-and-after from a recent pass on a retrieval layer, because abstract principles are easier to trust once you've seen a number move.

The change was unglamorous: full representation coverage was backfilled across the entire corpus, including older material that had been skipped. Combined with better handling of casual query phrasing, the practical result was that plain-language questions started landing on the right page. In a regression set we ran — mixing casual and formal phrasings of the same questions — every one reached its target passage. End-to-end answer latency, which had been measured in several hundred seconds at the worst, came down to roughly a dozen.

I'm not going to present that as a universal figure. Corpus size, hardware, and query mix all move it. The point is directional: closing the coverage gap and tolerating natural phrasing did more for usefulness than any fine-tuning of the matching step.

Privacy is the permission slip

For a company knowledge base, the documents are assets a team is rightly cautious about. That's why a private, local-first deployment isn't a niche preference — it's frequently the condition under which such a tool is allowed to exist at all. If the data has to leave the network to be useful, many teams simply won't adopt it, and rightly so.

The good news is that retrieval quality and data sovereignty aren't in tension. You can have both: run the whole thing where the data already lives, and treat "stays inside our network" as a baseline requirement rather than a premium feature. The engineering notes at https://www.uglypear.com/en/products/ show how a local-first build fits together without naming a specific stack.

One practical tip before you start: don't over-engineer the generator. The retrieval step is where the leverage is. A humble setup that finds the right passage and shows it to the user often beats an elaborate generation pipeline built on top of weak retrieval. Plenty of teams get stuck debating models while their corpus sits half-represented; the coverage gap is doing more damage than the model choice ever will. Get the documents in front of the right question first; spruce up the wording later.

Where to start

If you want to experiment, start small and measurable:

  • Pick one painful, frequently-asked question category.
  • Represent the relevant corpus fully — don't skip the old stuff.
  • Test with the phrasing real people use, not the phrasing you'd put in a title.
  • Measure question-to-answer time and whether the right page surfaces.

For related write-ups aimed at different readers — the business case, the adoption story — the pieces at https://www.uglypear.com/en/blog/ take the same ideas from other directions.

The technology is less mysterious than the marketing suggests. Match meaning, cover the whole corpus, keep the data where it belongs, and much of the "magic" takes care of itself.

Try it now

Ready to test these ideas against your own corpus?

  • See the products: https://www.uglypear.com/en/products/
  • Browse the blog: https://www.uglypear.com/en/blog/
  • Visit the homepage: https://www.uglypear.com/en/

FAQ

Q: Does semantic retrieval replace keyword search entirely?

A: Not necessarily, and often it shouldn't. Lexical search is still the right tool for precise, vocabulary-stable lookups like part numbers or clause citations. The practical default for a general knowledge base is a hybrid: lexical for precision on known terms, semantic for recall on natural-language phrasing, then rank and merge.

Q: How do I estimate the token cost of RAG?

A: Token cost scales with what you put in the prompt. Every irrelevant passage you retrieve adds tokens you pay for per question and dilutes the signal. The discipline is to retrieve only the few passages that are actually relevant, which keeps the context window small and the per-question cost down. Retrieval is the filter that protects both cost and answer quality.

Q: What's the cheapest way to evaluate retrieval quality?

A: Build a small regression set: a list of questions where you already know the correct source passage, mixing casual and formal phrasings. Check whether the system surfaces that passage in the top results. When every question reaches its target, you have evidence instead of a vibe — no benchmark infrastructure required.

Q: How large should my chunks be?

A: There's no universal size; it's a tuning problem specific to your content. Too large and a match drags in a whole section when one sentence was relevant; too small and you lose surrounding meaning. Most practical systems represent passages or chunks and then resolve back to the source page for the human to read.

Q: Can I run this without sending data off-premises?

A: Yes. A local-first or private deployment runs the representation and retrieval entirely where your data already lives, with no outbound calls required. For many teams that's not a premium option — it's the baseline requirement under which the tool gets approved at all.