Chapter 4. Semantic Search
As you’ve seen, lexical (or keyword) search looks at the terms of a query and matches those terms to terms in its index. Lexical search is powerful in its own right, especially when users have a good idea of exactly what they want to find. If you know that you want to buy Zinus Ricardo Sofa Couch with tufted cushions in Lyon blue, a site like Amazon.com can easily retrieve that couch for you based on the lexical match between that query and the product’s title and description.
But what if you’ve never heard of that particular couch? Maybe you just know that your décor favors cool colors, you have a fireplace, and you want to spend some quiet nights by that fireplace reading books. You might search Amazon for a cozy place to curl up by the fire, but the results will be disappointing, since none of the terms cozy, curl up, place, and fire appear in the title or description for the Zinus couch.
While the terms are not there, what the couch offers and what you mean when you type a cozy place to curl up by the fire match closely. Semantically, couches are related to coziness, fireplaces are related to coziness, and couches are related to curling up. The words don’t match, but their meanings do.
Vectors generated by LLMs encode semantic information from blocks of text. In semantic search, the search application uses an LLM to create a vector for each document in the corpus (Figure 4-1). When a user runs a search, the application encodes the text of that search ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access