Software engineering often demands making critical architectural decisions before having enough data. Here is how introducing a simple lexical fallback reduced document retrieval latency from 40 seconds to six while managing technical uncertainty.
One of the uncomfortable realities of software engineering is that we are constantly expected to make decisions before we have enough information to know whether they are right.
Architecture diagrams make engineering look wonderfully deterministic. Identify the requirement, evaluate the options, choose the correct solution, build it. Reality is messier. Sometimes you know you have a problem and have a theory about how to solve it, but there is no benchmark, Stack Overflow answer, or conveniently identical implementation sitting on GitHub to prove that your idea will actually work.
Recently, I ran straight into this problem while working on document retrieval. We already had a sophisticated retrieval augmented generation system in place, similar to the architectures discussed in my post on AI Engineering Playbook Part 5: When RAG Isn't Enough - A Guide to Fine Tuning. The problem was what happened before that sophisticated solution was actually ready to serve results.
The 40-Second Gap
When a user uploaded a document, it had to move through the ingestion pipeline before it became available to the retrieval system. The document needed to be processed, chunked, embedded and indexed before RAG could properly reason over it.
That process worked, but it was taking around 40 seconds. Forty seconds might not sound catastrophic when you are looking at a background processing job, but it feels completely different when you are the person who has just uploaded a document and immediately wants to ask a question about it. The system knew the document existed and the document was sitting right there, but until the richer retrieval pipeline had finished preparing it, the user still had to wait.
That raised a fairly simple question: did we really need the clever retrieval system to be ready before the document became useful?
The Stupid Solution
The obvious answer was almost embarrassingly old fashioned: grep it.
Before embeddings, vector databases and semantic search, we searched text by looking for text. It isn't clever, it doesn't understand semantic similarity, and it doesn't reason about meaning, but it is fast.
The idea was to introduce a lightweight retrieval path that could search the document almost immediately while the full RAG ingestion continued in the background. Once the richer index was ready, normal retrieval could take over.
Architecturally, I liked the idea, and from a user-experience perspective it potentially removed most of the dead time. The problem was that I had no idea whether it would actually retrieve useful enough information to justify adding another path through the system.
Making the Uncertainty Measurable
It would have been easy to dismiss lexical search immediately. RAG exists for a reason. A user does not necessarily ask a question using the same words contained in the source document, and semantic retrieval gives us the ability to bridge that gap.
But I wasn't proposing replacing RAG. I was asking a much narrower question: could a simple retrieval mechanism be good enough during the short period where the better one wasn't available yet? As I noted in Would You Drive a Ferrari to the Corner Shop? Cut Your AI Costs with Smart Model Routing, using lightweight tools for initial tasks is often the pragmatic choice.
That distinction changed the problem. The fallback did not need to beat RAG or even match it. It needed to make the document useful sooner, often enough to justify its existence. More importantly, we didn't have to bet the product on the answer.
I implemented the new retrieval path behind a feature flag. Here is a simplified representation of how that execution path evaluated document availability:
interface RetrievalResult {
chunks: string[];
isFallback: boolean;
}
async function retrieveContext(
documentId: string,
query: string,
flags: Record<string, boolean>
): Promise<RetrievalResult> {
const isVectorStoreReady = await checkVectorIndexStatus(documentId);
if (isVectorStoreReady) {
const chunks = await executeVectorSearch(documentId, query);
return { chunks, isFallback: false };
}
// Check if feature flag allows immediate lexical search
if (flags['enable-lexical-fallback']) {
const rawText = await fetchRawDocumentText(documentId);
const chunks = executeLexicalSearch(rawText, query);
return { chunks, isFallback: true };
}
throw new Error('Document ingestion in progress. Please wait.');
}
That gave us a controlled way to introduce it, evaluate how it behaved and turn it off again if the idea proved less useful than expected. The implementation was deliberately isolated and reversible, which meant the cost of getting the decision wrong was relatively small.
When uncertainty is high but the cost of obtaining evidence is low, I would rather build the smallest experiment capable of answering the question than spend days debating what we think might happen.
From 40 Seconds to Six
The first result was immediate. The time before a newly uploaded document became searchable dropped from roughly 40 seconds to around six.
That was the easy metric. The harder question was whether being searchable actually meant being usefully searchable. A fast system that consistently retrieves the wrong information isn't an optimisation; it is simply a faster way of producing a bad result.
So we evaluated it, and the fallback achieved a 92% successful hit rate during that initial gap.
That was a strong result, but the remaining 8% matters too. This wasn't evidence that grep was somehow better than semantic retrieval, nor was that ever the purpose of the experiment. It showed that during the period where semantic retrieval was not yet available, a much simpler system could provide useful results in the large majority of the cases we evaluated.
Not Every Component Has to Be the Best Component
I think we have a tendency as engineers to evaluate systems in isolation. We ask which search technique is better, which database is faster, which framework scales further or which model scores highest.
Those questions are useful, but architecture is rarely about finding the universally superior component. It is about finding components that satisfy particular constraints at particular points in a system.
The grep path did not need to be the best retrieval system; it needed to be available quickly and provide useful results while the better retrieval system was still being prepared. RAG didn't need to win the race to first retrieval; it needed to provide the richer semantic capability once ingestion had completed.
They were solving different problems at different stages of the same workflow. Once I stopped asking one mechanism to satisfy every requirement, the architecture became much simpler.
Reversible Decisions Are Cheap Decisions
There is a broader lesson here that has very little to do with grep or RAG. We often treat technical uncertainty as something that has to be eliminated before implementation begins, when sometimes implementation is the cheapest way of removing that uncertainty.
There are obviously decisions where this would be reckless. If you are choosing where millions of customer records will live, designing a security boundary, or making an architectural decision that will take six months to reverse, 'let's just try it' isn't much of an engineering strategy.
But not every decision has that blast radius. Some experiments are cheap, isolated and reversible. Feature flags make that boundary even more useful because they allow us to separate deploying an idea from committing the product to it.
That was the important part of this experiment. I didn't implement the fallback because I knew it would work; I implemented it because I didn't know whether it would work, and we had a low-risk way of finding out.
The result happened to be a 92% successful hit rate and a reduction in the time before a document became searchable from roughly 40 seconds to six. More importantly, we no longer had to debate whether the idea should work because we had evidence showing what it actually did.
That is the part of engineering I increasingly find more interesting than choosing technologies: knowing when to analyse, when to prototype, when to contain risk, and when to measure. Senior engineering is not always about already knowing the answer. Sometimes it is about designing the safest and cheapest way to find it.
