---
title: "LLMs are fantastic search engines, so I built one"
type: concept
source: https://www.jemoka.com/posts/kbhllms_are_text_matchers/
confidence: high
status: active
---

For the past 20 years, semantic indexing sucked.
For the most part, the core offerings of search products in the last while is divided into two categories:
Full-text search things (i.e. every app in the face of the planet that stores text), which for the most part use something n-grammy like Okapi BM25 to do nice fuzzy string matching Ranking/Recommendation things, who isn&rsquo;t so much trying to search a database as they are trying to guess the user&rsquo;s intent and recommend them things from it And we lived in a pretty happy world in which, depending on the application, developers chose one or the other to build.
There&rsquo;s something really funny to do with this idea of &ldquo;search&rdquo;. Take, for instance, Google. Its a &ldquo;search&rdquo; engine&mdash;but really it recommends people information that is probably relevant; PageRank, the company&rsquo;s claim to fame, isn&rsquo;t even textual analysis of any type at all: it is a measure of relevance, based on centrality arguments about where the average web surfer may end up.
By framing systems like Google as an act of recommendation, we can see why it is so widely adopted: it, really, brings the best of the Internet to the user&mdash;a catalogue of sorts&mdash;based on text which the user provides as input data regarding their interest. It is, importantly, not a capital-s Search engine.
And perhaps this explains why this doesn&rsquo;t work:
Figure 1: Oh my lord scary books.
Wouldn&rsquo;t it be nice for a query like this to return us actual, non-scary books?
If you think about it, back in the olden days (i.e. 2019), there really isn&rsquo;t a way to reconcile this difference between search and recommendation engines. Textual-based search systems were fantastically fast and gave you the exact things you needed&mdash;great for filing &ldquo;that file named this&rdquo;&mdash;but categorically useless when it comes to parsing large amounts of data that the user doesn&rsquo;t know the exact terminology for.
Recommendation engines, on the other hand, often required special indexing or behavioral modeling for what &ldquo;an average user of this type&rdquo; would like, which is great for leading the user to discover certain things they wouldn&rsquo;t otherwise find, but makes hilarious mistakes like the above because, well, they aren&rsquo;t doing much linguistic analysis.
So, what if we can simultaneously do the guessing game for user behavior&mdash;a la &ldquo;recommendation engines&rdquo;&mdash;but still use a fundamentally text-based approach to perform searching&mdash;a la a &ldquo;search service&rdquo;?
LLMs are text matchers Transformers are Text Matchers Fundamentally, the Transformer (the basis of all of those lovely large-language models (LLMs)) is a &ldquo;sequence transduction model&rdquo;&mdash;they are (and were originally invented as) a translation model of sorts. And I find it easy and productive to think of LLMs in that mindframe: although their output may look like human-like &ldquo;reasoning&rdquo;, LLMs&rsquo; fundamental job is to match one bit of text (context) against another (output).
LLMs are Internet Text Matchers The actual thing that is making the whole of the world go crazy right now, though, is the fact that LLMs, transformers trained on the internet, seem to be able to handle text-to-text &ldquo;translation&rdquo; tasks of a much more general nature:
&ldquo;given a food, translate it into its recipe&rdquo; &ldquo;given this text, translate it into the same written with a pirate voice&rdquo; &ldquo;given the comment, translate it to the code that follows&rdquo; You see, instead of carefully supervised translations a la the original Transformer, GPT+friends is simply chopping off the entirety of the input encoding process and letting the decoder ramble on its own. Hence, its outputs are functionally text matches of the context against the training data: that is, these LLM models effectively are text-matchers between the whole of the internet and your input.
And hence, the promise Let&rsquo;s recap real quick.
Transformers are text matchers LLMs, which are transformers, are text matchers against the text on the internet And here&rsquo;s the corollary to both of these statements:
Transformers match text LLMs, which are transformers, is trained (and biased) towards the things people would typically be looking for on the internet That is, though LLMs fundamentally match text, they know what&rsquo;s on the internet and how people talk about (and try to look for) them.
The point above is, to me, a very profound idea. LLMs essentially achieve what we were hoping to edge towards in the last 20 years&mdash;closing the gap between recommendation (what people want) and search (text matching) systems into one uniform interface.
And, praise be, LLMs seems to be highly directable at this task as well: they excel at few-shot and zero-shot training tasks; meaning, if you just give the Transformer a few examples of how to &ldquo;translate&rdquo; a piece of its input, it will happily do it with some accuracy following your example.
Aside: Stop Building Gosh Darn Chatbots Fortunately, people not named yours truly has also noticed these exciting capabilities of LLMs.
What confuses me, though, is the fact that everybody and their pet duck is building a chat bot or &ldquo;answering&rdquo; service of some description: capitalizing on the fact that LLMs have trained knowledge of text on the internet, but completely disregarding the fact that LLMs fundamentally are best at &ldquo;matching&rdquo; existing text in its context and not hallucinating new text&mdash;as these &ldquo;answer services&rdquo; want to do.
What gives? Wattenburger has this fantastic take on why chat bots are not the best interface for LLMs. To me, the most salient observation&mdash;one which stems from her wonderful arguments about chat bot&rsquo;s poor observability and iteration cycle&mdash;is that the generated text from these current LLM &ldquo;search&rdquo; services (called &ldquo;retrial augmented generation&rdquo;) is just so darn long.
When we look information on a site like Google, I believe our goal is generally to shove the desired information in our head as quickly as possible and know where we can go to learn more; if we wanted to read a 300 word summary about it (as Perplexity AI, Mendable, Phind etc. is want to give us) we can just go look up the source ourselves.
To me, the duty of a search platform, LLM or not, is to get the user on their merry way as quickly as possible&mdash;information in head or link in hand&mdash;not for the user to navigate a possibly-hallucinated rant about the topic they are looking for, followed by 3 source citations.
Making a LLM Search Engine And so we face a rather daunting task. To make a better search service with LLMs, we have to:
Leverage LLM&rsquo;s fantastic text matching capabilities Allow LLMs to inject their trained biases into what&rsquo;s relevant to the user in order to act as a good recommendation engine Do so in as little words as possible written by the LLM These three bullet points has consumed much of my life for the past 6 months, culminating in a reference implementation of such a &ldquo;LLM search engine&rdquo; called Simon. Let me now tell you its story.
Fulfilling a search query, Part 1/3 Our first goal is to figure out
Side quest: Actual Text-to-text Recommendation Now You Try
