liveBook · Manning

Lexical search

As explained in AI Agents and Applications

Lexical search retrieves content primarily by matching literal words or terms.

Lexical search retrieves document chunks by matching query words to words in the content. Unlike dense retrieval, which compares embeddings for semantic similarity, it focuses on word-level similarity and precise keyword matches. section 6.2.2 section 10.1

A sparse retrieval pipeline works by:

  • Tokenizing each chunk and building an inverted index that maps tokens to the chunks containing them. section 10.1
  • Tokenizing the query in the same way, looking up its terms, then ranking matching chunks with methods such as BM25 or TF-IDF. section 10.1
  • Using keyword matches for precise queries, Boolean constraints such as “must” and “must not,” and results whose matches are easy to explain. section 10.1

Lexical and semantic retrieval can be combined in hybrid search, with Reciprocal Rank Fusion merging their ranked results. BM25 depends on inverted-index data structures; LangChain’s BM25Retriever works on in-memory document lists but does not scale to millions of documents. section 10.8 section 10.8

How AI Agents and Applications covers it

How deep it goes
Explains tokenization, inverted-index lookup, and BM25 or TF-IDF ranking, without detailing ranking algorithms.
Examples
Illustrates Boolean constraints with “must” and “must not” and contrasts keyword matching with semantic retrieval.
What you can do after
Understand how matching query terms to indexed chunks enables precise retrieval and explainable results.
How it connects
Connects sparse retrieval to inverted indexes, BM25, TF-IDF, dense retrieval, and hybrid search.

Also explained in

Compare how 8 books explain lexical search →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI Agents and Applications. The section links point to the parts of the book it draws on.