Browse all previoiusly published AI Tutorials here.
Table of Contents
Vector-Based Search Algorithms (Dense Retrieval)
Hybrid Retrieval Methods (Lexical + Vector)
Pure Keyword-Based Search (Sparse Retrieval)
Comparative Summary
focusing on vector-based search, hybrid retrieval methods, and pure keyword-based search.
Modern large language model (LLM) applications increasingly rely on advanced retrieval algorithms to supply relevant context and knowledge. Key approaches include vector-based semantic search, hybrid retrieval (combining dense and lexical methods), and pure keyword-based search. Each has different implications for scalability, efficiency, and accuracy in real-world domains like enterprise knowledge bases, legal corpora, and scientific literature. Below, we review each approach, cite recent research (2024–2025), and compare open-source implementations and proprietary solutions.
Vector-Based Search Algorithms (Dense Retrieval)
Vector search uses high-dimensional embedding vectors to represent queries and documents, retrieving by nearest-neighbor similarity rather than exact keyword matching. This semantic retrieval can capture conceptual relevance beyond literal term overlap (Bridging Legal Knowledge and AI: Retrieval-Augmented Generation with Vector Stores, Knowledge Graphs, and Hierarchical Non-negative Matrix Factorization). Typically, LLM or transformer models (e.g. Sentence-BERT or domain-specific encoders) convert text into dense vectors; search is then performed with approximate nearest neighbor (ANN) algorithms (like HNSW graphs or IVF indexes) to avoid brute-force scans of huge vector collections.
Scalability & Efficiency: ANN algorithms are crucial for scaling dense retrieval. Methods like HNSW (Hierarchical Navigable Small World) graphs dramatically accelerate vector search by exploring a multi-layer small-world network of vectors, balancing speed with slight recall trade-offs (Retrieval-Augmented Generation: Challenges & Solutions). This enables billion-scale indexing – for example, enterprises like Netflix use ANN-based indexing to handle billions of embedding vectors efficiently . Recent benchmarks show that with optimizations, vector search can remain fast even at web scale: using quantization and optimized data structures, Elastic achieved sub-100 ms search on 138M vectors (1024 dimensions) with a ~75% reduction in RAM usage without compromising retrieval quality (Designing for large scale vector search with Elasticsearch - Elasticsearch Labs). Such results indicate that dense vector search, paired with distributed indexing and hardware optimizations, can be made highly scalable in practice. However, memory footprint is a consideration – storing high-dimensional embeddings for millions of documents can be resource-intensive, often requiring ANN indexes (and compression) to keep latency low.
Accuracy: Semantically rich embeddings often improve recall and relevance for natural language queries. Dense retrievers excel at finding relevant documents that do not explicitly share surface words with the query (Bridging Legal Knowledge and AI: Retrieval-Augmented Generation with Vector Stores, Knowledge Graphs, and Hierarchical Non-negative Matrix Factorization). For instance, in the legal domain, dense embedding models (e.g. SBERT-based) significantly outperformed keyword methods on case law retrieval benchmarks like LeCaRD , showing the value of vector search for conceptually complex queries. Likewise in scientific research, specialized embedding models can retrieve relevant papers that traditional search misses – one 2024 study found that an LLM-based retriever had much higher recall@5 on academic questions than Google Scholar or other keyword engines (HERE). At the same time, dense retrieval has limitations. It may miss exact matches for rare terms (e.g. codes or names) and can be less robust to domain shifts. Recent experiments with LLM-based retriever models indicate that sparse lexical methods can outperform dense methods on out-of-domain queries, suggesting dense retrieval alone might struggle with recall in unfamiliar distributions (Scaling Sparse and Dense Retrieval in Decoder-Only LLMs). This highlights that while vector search improves semantic relevance, it sometimes trades off exact precision – motivating the use of hybrid techniques in critical applications.
Use Cases: Vector search has rapidly gained adoption in enterprise and research settings. Enterprise search systems are embracing dense retrieval to power chatbots and assistants that answer queries using internal documents (The State Of Retrieval-Augmented Generation (RAG) In 2025 And Beyond - Aya Data). By 2023, many enterprises had turned to retrieval-augmented generation (RAG) with vector databases to boost LLM answer accuracy and keep responses up-to-date without retraining models . Open-source tools like FAISS, Annoy, or HNSWlib (and vector databases like Milvus, Weaviate, or Qdrant) enable scalable vector similarity search; these are often integrated with LLM frameworks (e.g. LangChain) for building QA bots. Proprietary solutions also abound: for example, Pinecone and Google’s Vertex AI Matching Engine offer managed vector search, and traditional engines like ElasticSearch/OpenSearch have added dense vector fields. In legal retrieval, vector search helps find conceptually relevant cases or statutes even when exact keywords differ – improving recall of relevant precedents (as noted with SBERT on LeCaRD) . In scientific literature search, semantic embeddings (such as the SPECTER model that uses paper text and citations) capture research topic similarity beyond keyword overlap, enabling discovery of related work; these embeddings can be indexed in a vector store to allow researchers to find papers by concept. Overall, vector-based search provides a powerful semantic layer, but to ensure high precision and robustness, it is often paired with or augmented by more classic retrieval methods.
Hybrid Retrieval Methods (Lexical + Vector)
Hybrid retrieval combines dense vector search with sparse keyword search, aiming to leverage the strengths of both. In practice, this can mean running a query through a keyword engine (e.g. BM25) and an embedding-based search, then fusing the results or re-ranking combined candidates. Another approach is a hybrid index that stores both neural embeddings and inverted term indexes, scoring documents by a weighted sum of semantic and lexical relevance. The goal is to retrieve documents that are either lexically or semantically relevant (or both), thereby improving recall and precision simultaneously (What’s Shaping GenAI in 2025).
Accuracy Benefits: Hybrid retrieval is widely recognized for boosting retrieval performance. By merging semantic matching with exact term matching, hybrid methods can surface relevant results even when query terms do not explicitly appear in the document . Industry experts point to Hybrid RAG as a key solution for improving accuracy and reliability in enterprise LLM applications . Recent legal AI research also underscores this – dense models find conceptually similar cases, while lexical matching ensures critical terms (like specific legal phrases or citations) aren’t missed (Bridging Legal Knowledge and AI: Retrieval-Augmented Generation with Vector Stores, Knowledge Graphs, and Hierarchical Non-negative Matrix Factorization). Indeed, benchmarks in legal IR have demonstrated the effectiveness of hybrid approaches that integrate both lexical and dense retrieval, achieving higher accuracy in tasks like precedent retrieval and statute matching . Overall, hybrid retrieval tends to outperform either method alone in diverse settings by covering each method’s blind spots. Zhao et al. (2024) note that sparse and dense methods have complementary strengths (Retrieval-Augmented Generation: Is Dense Passage Retrieval Retrieving?), and combining them often yields the most robust results. Many real-world systems now default to a hybrid strategy to maximize recall: e.g. using BM25 to ensure no obvious document is skipped, plus embedding search to catch semantic variants, and then merging or re-ranking the results.
Scalability & Efficiency: Running two searches per query has overhead, but practical implementations mitigate this. One common pattern is a two-stage retrieval: use an efficient keyword search to shortlist candidates (e.g. top 100 by BM25), then apply a vector similarity re-rank on that subset. This drastically reduces the number of expensive embedding comparisons while benefiting from semantic ranking on the top results. Conversely, one can do a vector search first and then filter or verify the results with keywords for precision. Modern search engines and databases increasingly support hybrid indexing natively. For example, ElasticSearch 8+ and OpenSearch allow storing both dense vectors and text, enabling combined scoring in one query. A recent survey of vector databases shows that many systems (Milvus, Weaviate, Qdrant, etc.) support “Vec.+Ftx.” modes – i.e. both vector and full-text queries in the same engine (When Large Language Models Meet Vector Databases: A Survey). This integrated approach means a single system can handle hybrid search, often by maintaining an ANN index alongside an inverted index. While maintaining dual indexes can increase storage, these systems are designed to scale horizontally. Thus, hybrid retrieval can be nearly as scalable as its components: for instance, Weaviate or Vespa can serve hybrid queries across millions of documents with low latency, and Amazon reports its Kendra enterprise search (proprietary) achieved high retrieval accuracy through a hybrid index (vector + keyword) on diverse corporate data (Introducing Amazon Kendra GenAI Index – Enhanced semantic search and retrieval capabilities | AWS Machine Learning Blog) . The trade-off is added complexity in tuning and infrastructure, but frameworks increasingly make it seamless (e.g. cloud services offering out-of-the-box hybrid search with pre-optimized parameters ).
Applications: Many enterprise search platforms now tout hybrid retrieval as a best practice. Enterprise data is often a mix of structured fields and unstructured text, and queries can range from natural language questions to exact ID lookups – a hybrid engine can handle both. Proprietary solutions like Amazon Kendra GenAI explicitly use hybrid indexes (combining keyword and vector search) to improve accuracy on enterprise Q&A . This ensures that, for example, a query for a policy number yields that exact document (via keyword match) even if the number is rare, while also bringing in semantically related FAQs that don’t contain the exact phrasing. In legal document retrieval, hybrid pipelines are emerging to augment traditional boolean searches with semantic suggestions. Lawyers might perform keyword queries with specific legal terms, and a hybrid system can additionally suggest cases that discuss the same concept in different words. Recent work integrates knowledge graphs with vector stores for legal RAG, effectively a hybrid of structured (graph/keywords) and unstructured retrieval to improve coverage and interpretability (Bridging Legal Knowledge and AI: Retrieval-Augmented Generation with Vector Stores, Knowledge Graphs, and Hierarchical Non-negative Matrix Factorization). This “best of both worlds” approach is shown to enhance legal research by bridging the gap between strict boolean search and purely semantic search . In scientific literature search, hybrid methods can combine citation-based networks or metadata filters with embedding-based text search. For instance, an academic search engine might use keyword search constrained to a field (author names, venues) together with semantic similarity on abstracts. The SPECTER model (Cohan et al. 2020) is effectively a hybrid approach: it leverages citation graph information (structured signal) to produce paper embeddings , merging bibliographic connectivity with content semantics. Such approaches ensure that literature searches return papers that are not only textually relevant but also connected in the citation network (improving relevance and trust). Across domains, hybrid retrieval is prized for accuracy gains: it reduces false negatives by catching semantic equivalents and false positives by requiring lexical corroboration, yielding more reliable results for LLMs to consume (What’s Shaping GenAI in 2025).
Open-Source & Proprietary Solutions: Open-source search engines have led the way in hybrid retrieval support. Vespa (Yahoo/Oath) was an early engine allowing combined text and vector ranking. Apache Lucene (and its derivatives Solr/Elasticsearch/OpenSearch) introduced hybrid scoring in recent versions, so developers can blend BM25 scores with embedding cosine similarity. Dedicated vector DBs like Milvus and Weaviate offer boolean filters and full-text search alongside ANN, effectively supporting hybrid queries within one system (When Large Language Models Meet Vector Databases: A Survey). On the proprietary side, most cloud providers and enterprise vendors now emphasize hybrid capabilities: Amazon Kendra’s new RAG index, mentioned above, combines both retrieval types (Introducing Amazon Kendra GenAI Index – Enhanced semantic search and retrieval capabilities | AWS Machine Learning Blog); Microsoft’s Azure Cognitive Search likewise provides “semantic ranking” which reranks keyword results using transformer embeddings. Even web search engines are hybrid – for example, Google Search incorporates neural semantic signals but still heavily uses keyword indexing, ensuring queries with exact terms (like quotes or rare keywords) are satisfied. This convergence of dense and sparse retrieval in products underscores that hybrid search is considered essential for the scalability and accuracy needs of real-world LLM applications . Notably, when queries demand precise matches (e.g. a regulatory ID or error code), a purely semantic approach can fail (“two steps back” in user experience), so combining it with reliable lexical lookup is necessary .
Pure Keyword-Based Search (Sparse Retrieval)
Keyword-based search relies on sparse term vectors and inverted indexes – the classic IR approach typified by TF-IDF and BM25 ranking. Documents are retrieved if they contain the query terms (or boolean combinations of terms), and are ranked by statistical relevance measures. This lexical matching was the cornerstone of search engines for decades and remains a baseline in many systems due to its robustness and efficiency. Even as LLMs introduce semantic search, pure keyword retrieval often underpins components of modern pipelines (for filtering, candidate generation, or as a fallback for certain query types).
Scalability: Sparse retrieval is highly mature and scalable. Inverted index technology (e.g. Apache Lucene) can handle web-scale corpora (billions of documents) across distributed shards, providing sub-second query times. The indexing structure allows very fast lookups: a query’s terms directly map to posting lists of documents, so only those candidates are considered. This means search time grows mainly with the number of query terms, not the total corpus size. As a result, enterprise search infrastructure built on Lucene/Elastic can scale nearly linearly by adding nodes, easily coping with ever-growing data. Open-source engines like Elasticsearch/OpenSearch are widely used for enterprise knowledge bases and log search, demonstrating strong horizontal scalability. They also support frequent index updates and fine-grained access control, important for dynamic enterprise data (Introducing Amazon Kendra GenAI Index – Enhanced semantic search and retrieval capabilities | AWS Machine Learning Blog) . In practice, keyword search has enabled real-time search on indexes with tens of billions of terms using moderate hardware, something dense methods are still catching up to. Memory footprint is also efficient – storing an inverted index (with compression) is often lighter than storing dense vectors for the same text. Thus, purely lexical search remains the most proven solution for large-scale retrieval problems.
Efficiency: The efficiency of keyword search is hard to beat for short queries. Because it avoids any heavy neural computation at query time, even a single CPU can serve many queries per second on a modest index. Scoring functions like BM25 are simple linear computations over term frequencies and precomputed IDF weights. These can be optimized with caching and early termination (skipping evaluation for documents once it's clear they can’t make the top-k). Moreover, inverted indexes naturally support field-specific search, filtering, and boolean logic with minimal overhead – operations that can be costly to replicate in pure vector search. For example, restricting a search to documents from 2023 or to a specific author can be done via an indexed metadata field lookup, almost instantaneously, whereas a vector search would need a separate filtering mechanism. This advantage makes keyword search highly cost-effective and predictable in performance. Even as hybrid systems introduce dense re-ranking, they often rely on an initial BM25 retrieval precisely because of its speed and low resource usage. In summary, sparse retrieval offers excellent query throughput and low latency, which is why it’s still used as a backbone in many LLM-augmented systems (with semantic methods applied only to a small set of candidates).
Accuracy and Limitations: Pure keyword search excels when the query terms align well with the terms in relevant documents. In domains with standardized vocabulary or where users know the right jargon, lexical search gives very precise results with few false positives. For instance, in the legal domain, attorneys often perform boolean keyword searches (e.g. specific statute numbers, case names, or phrases like “proximate cause”) to retrieve documents; such queries rely on exact matches and are handled perfectly by sparse indexes. In fact, proprietary legal research systems (Westlaw, LexisNexis) have long optimized keyword search with controlled vocabularies and metadata. Scientific literature search in digital libraries (PubMed, IEEE Xplore) also heavily uses keyword and fielded search (title, abstract, author filters) to let researchers pinpoint papers. However, the limitation is that lexical methods fail to retrieve relevant content expressed in different words. If a user’s query is phrased differently from the relevant text (synonyms, paraphrase), a strict keyword match misses it entirely. This vocabulary mismatch problem is where dense retrieval has an edge. Additionally, sparse retrieval doesn’t inherently capture semantic closeness – documents either have the keywords or not, so there is no notion of “conceptual similarity” beyond overlapping terms. This can hurt recall. For example, a biomedical search for “heart attack” would not find documents only mentioning “myocardial infarction” unless synonyms are explicitly expanded. Efforts like query expansion, synonym lists, or learning to rank can mitigate this, but they add complexity. Recent research confirms that sparse vs. dense trade-offs remain nuanced: in a 2025 study with LLM-based retrievers, the authors found sparse models were more robust on diverse queries and even achieved higher overall accuracy in some settings (Scaling Sparse and Dense Retrieval in Decoder-Only LLMs). This suggests that despite the surge of dense methods, a well-tuned lexical approach (potentially enhanced by learned expansions or prompts) can compete strongly with semantic search, especially for precision-oriented tasks. In practice, many systems therefore still include a keyword component to guarantee exact matches. Notably, when accuracy is defined by exactness and coverage – e.g. compliance checks, legal discovery – keyword search provides confidence that if a term exists in the corpus, it will be retrieved. (By contrast, a vector search might miss it if the embedding doesn’t encode that specific detail strongly.) Thus, pure keyword search offers a reliable baseline and often serves as a safety net in LLM applications to ensure critical information isn’t overlooked.
Use in Real-World Systems: Despite the buzz around vectors, classical search engines are deeply embedded in real-world pipelines. Enterprise applications often still use keyword search for things like intranet search, document management systems, or email search, where users expect keyword query interfaces. Open-source Lucene is the foundation of many commercial products (e.g. IBM Watson Discovery and older SharePoint search leveraged Lucene under the hood). Proprietary solutions in enterprise search (Microsoft SharePoint, AWS Kendra, Google Workspace search) historically started with keyword-centric approaches and have only recently added semantic re-ranking. For instance, AWS Kendra introduced an intelligent ranking that uses semantic search to re-rank results from a keyword query (Semantically ranking a search service's results - Amazon Kendra) – essentially layering vector semantics on top of a keyword core. In the legal sector, tools like Westlaw and LexisNexis built their reputation on powerful boolean search with curated legal thesauri. They allow attorneys to perform very granular keyword queries (down to specific document fields or citation references) – something neural methods alone cannot reproduce with the same level of controllability. These systems are now experimenting with LLMs, but usually by integrating semantic suggestions into a primarily keyword workflow. In scientific research, traditional search portals (like arXiv, Web of Science, Google Scholar) still rely on keyword and metadata search as the primary mechanism, supplemented by citation metrics. Researchers often start with simple keyword searches and then refine. The enduring use of pure keyword search in these domains stems from its precision, transparency, and scalability. Users often prefer a known-simple system for initial retrieval, then maybe apply LLM-based analysis on those results. In summary, while keyword-based search may appear “legacy,” it remains indispensable. It provides a strong backbone for hybrid systems and a fail-safe for cases where semantic vectors might err. As one recent survey put it, the challenge for modern IR is “balancing sparse and dense retrieval methods” to get the best of both (Introducing Amazon Kendra GenAI Index – Enhanced semantic search and retrieval capabilities | AWS Machine Learning Blog) . Pure keyword search continues to offer unmatched reliability at scale, which is why it’s still a core component of advanced LLM-driven search solutions.
Comparative Summary
Scalability: Keyword search is the long-standing champion of scale, with proven ability to handle enormous corpora on commodity hardware. Vector search can approach similar scale using ANN indexes and distributed architectures, though often at the cost of increased memory and engineering complexity. Hybrid retrieval inherits scalability from both: when built on scalable engines (Lucene + ANN), it can serve large workloads, albeit with more moving parts. Modern systems like Elastic, Vespa, and cloud services demonstrate that hybrid search can scale effectively with the right optimizations (e.g. sharded hybrid indexes, parallel query execution). Open-source and proprietary offerings are converging to provide scalable hybrid search out-of-the-box (When Large Language Models Meet Vector Databases: A Survey).
Efficiency: In terms of query latency and throughput, sparse retrieval is extremely efficient per query, while dense retrieval is more computationally intensive (due to vector math). However, ANN algorithms and hardware acceleration have narrowed the gap – millisecond-level vector search is achievable on indexes into the millions. For many applications, a hybrid approach (lexical pre-filter + vector rerank) provides a sweet spot: it uses cheap keyword filtering to cut down the search space, then a focused vector computation, resulting in fast yet semantically enhanced results. Batch processing and caching can further improve efficiency for all methods (e.g. reusing embeddings, caching posting lists). The efficiency trade-off also depends on the query: short, specific queries are quick on keyword systems; broad or descriptive queries benefit from semantic retrieval, which might do more work but also retrieve fewer irrelevant results (saving time that would be spent wading through noise). Overall, all three approaches can be tuned to meet real-time application requirements, but pure keyword systems are simplest to optimize for speed, whereas vector/hybrid systems require more careful index tuning (dimension reduction, pruning, etc.) to maintain low latency.
Accuracy: Dense vector search boosts recall and finds contextually relevant information that pure keyword search may miss, which directly improves LLM response quality (reducing hallucinations by providing the right context). Yet, dense search might introduce loosely related info if not constrained – hence precision can suffer in some cases. Sparse keyword search offers high precision for queries with clear terms, but can have low recall if the query and document language diverge. Hybrid retrieval tends to deliver the best overall accuracy, combining high recall with high precision: it ensures that if a relevant document exists (even with different wording), the semantic component can fetch it, and if an exact match exists, the lexical component will catch it. Empirical studies and enterprise experiences in 2024–2025 overwhelmingly favor hybrid setups for critical tasks (What’s Shaping GenAI in 2025). For example, an enterprise QA system using hybrid RAG will answer correctly more often, as it can find information that a pure BM25 or pure embedding approach alone might miss. In specialized domains, the optimal mix can vary – e.g. legal search might weight lexical higher (due to exact citations and terminology importance), whereas a customer support chatbot might lean more on semantic matching. Importantly, the latest research reflects a recognition that no single method is universally superior: the highest performing systems frequently ensemble or fuse multiple retrieval signals (Bridging Legal Knowledge and AI: Retrieval-Augmented Generation with Vector Stores, Knowledge Graphs, and Hierarchical Non-negative Matrix Factorization) . Thus, advanced LLM applications are moving toward adaptive retrieval, using vector, keyword, or both as needed. Proprietary implementations like Kendra’s GenAI Index and open frameworks like LangChain’s retrievers embody this trend by offering hybrid retrieval as a default for improving LLM accuracy.
In conclusion, advanced search algorithms for LLMs span a spectrum from lexical to semantic. Vector-based search introduces powerful semantic understanding, keyword-based search provides dependable exact matching, and hybrid methods strive to unify them for optimal performance. The impact on real-world systems is evident: enterprises are deploying hybrid semantic search to unlock insights from internal data with both scale and accuracy, legal professionals are beginning to benefit from AI that understands context yet doesn’t miss key terms, and scientific researchers are aided by tools that combine semantic similarity with traditional relevance cues. Open-source tools and research from 2024–2025 have greatly expanded what’s possible in this space, while proprietary solutions are quickly incorporating those advances. The result is that retrieval for LLMs is becoming more scalable, efficient, and accurate – enabling LLM-driven applications to reliably work with ever-growing volumes of knowledge.