Back

Search a Table in Plain Words

By Pablo Fernandez8 min read

People type sentences into search boxes whether you let them or not. In LabSys, the internal app I build for a pharma company, the catalogue table had a perfectly good search: words, references, typos. Type "articles from one supplier with no price" into it and you got an empty list, because no article is called that.

Every word they needed was already a filter. The supplier was a column with a filter, the price was a column whose empty cells you could ask for, and both lived three clicks away in a menu. The sentence was the right query. The box just couldn't read it.

Handing the sentence to a language model looks like the obvious fix, and that is where it gets uncomfortable. A model takes two or three seconds, which is a long time to stare at a search box. And a model will happily invent a supplier that isn't in the table, or read "not from that supplier" as "from that supplier". A search that is slow and sometimes wrong is worse than the plain one it replaced. So the question this post answers is narrow: how do you make a sentence turn into filters fast enough to feel like typing, without ever letting the model make one up?

Here it is working. LabSys reads Spanish and its data isn't mine to show, so this is a replay on a made-up coffee catalogue, in English, with LabSys's own search box, chips and glow. The filters are the ones its two readings give for sentences like these, and the clock is its real one.

Filters14 of 14 coffees
CoffeeRoasterOriginProcessRoasted€/kgWeb
Yirgacheffe Lot 7AlborEthiopiaWashed04/11/202638Visible
Guji HighlandTueste NorteEthiopiaNatural12/11/202641Visible
Sidama Red CherryCerro AltoEthiopiaWashed21/10/202636Visible
Huila Pink BourbonAlborColombiaWashed09/11/202629Visible
Nariño NaturalCasa MolinaColombiaNatural15/11/2026Hidden
Cauca HoneyTueste NorteColombiaHoney30/10/202631Visible
Nyeri AACerro AltoKenyaWashed02/11/202644Visible
Kirinyaga NaturalCasa MolinaKenyaNatural17/11/2026Visible
Cerrado ClassicAlborBrazilNatural11/11/202622Visible
Mogiana ChocolateTueste NorteBrazilNatural18/10/202624Hidden
Huehuetenango ReserveCasa MolinaGuatemalaWashed06/11/202639Visible
Antigua HoneyCerro AltoGuatemalaHoney13/11/202633Visible
Geisha Lot 12Cerro AltoPanamaWashed16/11/202696Visible
Geisha NaturalAlborPanamaNatural08/11/2026Hidden
Instant reading (Jev, a decision model)Waiting for a sentence
Full reading (Gemini, replaces it)Waiting for a sentence
A replay on a made-up coffee catalogue, with LabSys's own search box, chips and glow. The filters are the ones its two readings give for sentences like these; the timings are its measured ones.

The model only gets to pick

The first decision makes the rest possible: the model never writes a query. It gets a closed list of options built from the table, picks among them, and core-api checks every pick before the page applies it. The page then runs the same column filters a person would tick by hand. The idea comes from JevFilter, which turns a search sentence into filters your API already accepts instead of generating SQL.

The options are the table's real columns with their real values. A column with up to 80 distinct values (supplier, process, status) is listed whole. A column of dates or numbers is marked as one, so the model can give a range ("roasted this month" becomes the 1st to the 30th). A column with too many values to list, like product names, is open: the model gives words, and core-api looks them up among the actual values.

Then core-api checks the answer. A listed value has to be one of the list. A range has to have days or numbers at its ends. And an open column's words have to appear in what the person typed:

natural-search.service.ts
// Only words that are in the sentence: in a column too big to list, the model
// must not swap a name it was given for another it knows.
const said = squash(text);
const words = (f.search.trim() ? [f.search] : f.values)
  .map((w) => w.trim())
  .filter((w) => w && squash(w) && said.includes(squash(w)));

That last rule exists because it happened. In a column of thousands of names, the model was given one brand name and returned a better-known brand it had seen in training. With the check, a word that isn't in the sentence finds nothing, and a filter that finds nothing is dropped. The worst the model can do now is miss a filter, and a missed filter leaves its words in the box as plain search, which is what the box did before.

"naturals without a price" │ ▼┌─────────────────────┐ options: each column and its real values│ model picks │◀── (kept ahead, never computed per sentence)└──────────┬──────────┘ ▼┌─────────────────────┐ in the list? a real range?│ core-api checks │ words in the sentence?└──────────┬──────────┘ no: dropped ▼Process: Natural Price: (empty) the page's own column filters
A sentence never reaches the database as text: the model picks from the table's own values, and core-api keeps only what checks out.

The values in that list are why this can be fast at all. Computing every distinct value of 40 columns over the whole catalogue takes seconds, so LabSys doesn't do it when someone types: the values are computed ahead and kept in Redis until the data under them changes. That cache is its own story: 350,000 Rows in One Fast Table.

Two readings at once

Picking from closed lists makes the model honest. It doesn't make it quick. Gemini 2.5 Flash, reading the whole sentence with every column, answered in 2.6 s at the median. So every sentence is read twice, at the same moment, by two different kinds of model.

The first is a decision model: Jev, through Vercel AI Gateway. A decision model doesn't write text. It answers a multiple-choice question in one pass and gives a probability for each option (I wrote about that kind of model when I ran one on a VPS). Here each listed column is one question: which of its values does the sentence ask for, or none?

natural-search.service.ts
const { answers } = await experimental_decide({
  model: env.AI_GATEWAY_DECISION_MODEL, // typesafe-ai/jev
  state: { busqueda: text },
  questions, // one per listed column: its values, plus "none"
  abortSignal: AbortSignal.timeout(TIMEOUT_MS),
});
for (const o of options) {
  const a = answers[o.id];
  if (!a || a.choice === NONE || (a.probabilities?.[a.choice] ?? 0) < DECIDE_SURE) continue;
  const v = o.values[Number(a.choice.slice(1))];
  if (v) out[o.id] = [v];
}

It answers in about a third of a second, and a value is kept only when the model is at least 80 % sure of it. It can't do ranges, empty cells, open columns or leftover text, but the filters people type most often are list values, and those appear as chips almost as soon as typing stops.

The second reading is the full one, with Gemini. It handles everything the first can't: "roasted this month" as a range, "without a price" as the price column's empty cells, a product name left in the box as plain search. When it answers, it replaces the first reading's chips. You can watch the swap in the "Geisha, Cerro Alto" take above. The instant reading recognises the roaster and empties the box, then the full one puts "geisha" back as text, and the list narrows to one coffee.

typing ──────────┤ 450 ms ├─┬──────────────────────────────────▶ time │ ├─ instant (Jev) ──┤ ~0.3 s: list values as chips │ └─ full (Gemini) ──────────────────┤ 1.6 s median: ranges, empty cells, text, replaces it
Both readings are asked the moment typing stops; the instant one fills the gap until the full one replaces it.

A negation never goes to the instant reading. A choice among values reads "not from Albor" as Albor, which is the exact opposite of what was asked, so any sentence containing a negation word waits for Gemini, which has an exclude flag for it. The chip then says "no Albor". Two of the four takes in the demo work this way, and the instant lane says so.

Two readings bring a race with them. If someone types a sentence, pauses, then keeps typing, the first sentence's answers are still on their way. The page remembers the last sentence it asked about and drops any answer to an older one, and the full reading only replaces the instant one while the box still holds what the instant one left there.

Taking a second off the full reading

The full reading started at 2.6 s at the median and 5.7 s at worst. Three settings took it to 1.6 s and 2.5 s:

natural-search.service.ts
const { output } = await generateText({
  model: env.AI_GATEWAY_MODEL, // google/gemini-2.5-flash
  temperature: 0,
  providerOptions: { gateway: { caching: "auto" }, google: { thinkingConfig: { thinkingBudget: 0 } } },
  output: Output.object({ schema }),
  system, // the table's columns and their real values, the same from one sentence to the next
  prompt: text,
});
  • No thinking first: Gemini 2.5 Flash reasons before answering by default. With a budget of zero it gave the same filters on my test sentences, and that one change is the drop from 2.6 s to 1.6 s.
  • The table goes in the system prompt: the columns and their values are the long part of the request and barely change between sentences, so the provider can cache them instead of reading them again each time.
  • Temperature 0: not for speed but for trust. With the default, a sentence that named a column was read as a filter one time and not the next. Now the same sentence over the same data gets the same chips, and core-api keeps the last 500 answers keyed by the sentence and the data's version, so a repeated sentence costs nothing.

The schema is deliberately plain: strings, not enums of column ids. An earlier version listed 40 columns as an enum, and the model provider refused the schema for having too many states. The checks in core-api do the job the enum was doing.

A box that only glows when it understood

Most of the work went into making the box behave like the old one whenever the model has nothing to add. A sentence is two words or more, with letters. A bare product name is read too, comes back with no filters, and the box stays exactly as typed, with no button to press and no "AI" mode to switch on.

While a sentence is being read, the list shows that it is loading instead of "nothing matches", because the plain search for a whole sentence almost always finds nothing, and flashing an empty table for a second and a half reads as a failure. When filters do come back, they become ordinary chips. The box glows, and a note after the chips repeats the sentence with an Undo that puts back the filters and text from before. Removing any chip that the sentence set also ends smart mode, so the glow never claims the sentence is in charge when it isn't.

The glow is the one piece I didn't write for LabSys. I first made it as a pull request to Hypercode, a glow around its message box in the style of Apple Intelligence, and brought it over unchanged: six colours at 70 %, a 1px rim masked to the edge over a blurred halo behind it, the hue going round once every 10 seconds. It fades in when the filters land and out when they go, and it stays still for anyone who asks their system for reduced motion.

What the model is for

Seen from the database, nothing new happened. LabSys's tables already had every one of these filters, and the queries that run are the ones a person gets by ticking boxes. The model's whole job is to save the clicks, which is also why it can be allowed in at all: it picks from what exists, core-api checks the pick, and the person sees exactly what was picked as chips they can remove. That is the trade. It can miss things, and when it does, the sentence falls back to plain text search. It can't make things up, because it never gets the chance.

Related articles

Hybrid Email Search

BM25 scores words, trigrams only say yes or no, vectors give a cosine. Mailingest throws the numbers away and fuses the three lists by rank.

Vector Search on S3

I forked VecPuff to keep one bit per dimension resident, so search over vectors in S3 fetches one in full only when the cheap guess is too close to call.

350,000 Rows in One Fast Table

Virtualizing 350,000 rows is the easy part. The counts and filter lists around them took seconds, until Postgres started saying which columns changed.