O&O ConsultingBook a free call

Home / Insights / AI in Practice

Semantic Search and Vector Databases

Searching by meaning instead of keywords, and the engineering that makes it fast.

O&O Consulting · · 2 min read

A globe representing searching across information

Type "how do I get my money back" and a keyword engine may miss a page titled "Refund policy". Semantic search is designed to connect the two.

Embeddings and distance

A model maps each passage and each query to a vector. Passages with related meaning lie near one another, commonly measured by the angle between vectors (cosine similarity). Searching means finding the vectors closest to the query.

Sentence-level models such as Sentence-BERT made this practical by producing one comparable vector per text, so that millions of documents can be embedded once in advance.

Two approaches to searchIllustrative diagram, not data
Keyword searchMatches exact wordsFast and predictableMisses synonymsSemantic searchMatches meaningHandles paraphraseCan miss exact codes
Keyword searchMatches exact wordsFast and predictableMisses synonymsSemantic searchMatches meaningHandles paraphraseCan miss exact codes

Diagram by O&O Consulting.

Making it fast

Comparing a query with every stored vector becomes slow at scale. Approximate nearest neighbour indexes organise vectors so that only a fraction need checking. One popular method, hierarchical navigable small world graphs, builds layered networks that can be traversed quickly toward the closest points. Vector databases package such indexes with filtering, updates and access control.

Hybrid retrieval

Classical ranking functions such as BM25 reward rare words that match exactly and remain strong baselines. Semantic methods handle paraphrase. Running both and merging the results usually covers more cases than either alone.

Choices that matter

  • Chunking: passages that are too long blur topics; too short lose context.
  • Embedding model: choose one suited to your language and subject matter, and re-embed everything if you change it.
  • Measurement: collect real queries with known correct documents and track how often the right one appears near the top.

Limitations and open questions

Similarity is not relevance or truth. A passage may be on the right topic and say the opposite of what is needed, since negation can be poorly captured. Embeddings can also leak information about the underlying text, so they should be protected like the documents themselves.

References

  • Reimers, N. and Gurevych, I. (2019). "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks." arxiv.org/abs/1908.10084
  • Malkov, Y. and Yashunin, D. (2016). "Efficient and robust approximate nearest neighbor search using Hierarchical Navigable Small World graphs." arxiv.org/abs/1603.09320
  • Robertson, S. and Zaragoza, H. (2009). "The Probabilistic Relevance Framework: BM25 and Beyond." doi.org/10.1561/1500000019

This article is general information, not financial, legal or investment advice. AI research and rules change quickly; check the cited sources for the current position.