SuggestAPISuggestAPI

Blog • Engineering • November 9, 2026 • Cole Hartwell

How We Made SuggestAPI Recommendations Better and Faster

We replaced a FastAPI service with a Rust one, then changed how it counts. The speed part was straightforward. The quality part took three attempts and one unglamorous conclusion.

Nightly count tables feeding an in-memory inferd service that answers similar, next, and for-user recommendations.

Summary. We replaced a FastAPI recommendations service with a Rust one that serves precomputed artifacts, then found raw session counts beat the learned vectors.

Recommendations are one of those features where the demo is easy and the engineering is not. Our first implementation answered requests through a FastAPI service: load the user’s context from the database, run the model in Python, return a list. It worked, and it was slow enough that we stopped calling it in places where we wanted it.

So we rebuilt the serving path on inferd, a small Rust service that answers from precomputed artifacts held in memory. Then we went after the ranking itself, which turned out to be the harder half of the job.

What changed, in two parts

The first change is mechanical. inferd doesn’t train anything at request time. A nightly job writes three artifacts per index — a list of similar items, a next-item table, and optionally item vectors — and the service loads them and answers one endpoint, POST /v1/recommend, in similar, next, or for_user mode. No model inference, no database round trip, no Python in the hot path.

The second change is where the interesting failure was. Moving to precomputed artifacts fixed the latency, but the ranking we ported across wasn’t the best one available to us. The thing that beat it was much simpler, and it took two tries to get there.

How we measure quality

We score three tasks, each returning a top 10:

  • Next item. Given an item, rank the items that follow it within five steps.
  • Similar item. Given the first item of a session, rank the rest of that session.
  • For user. Given the first two distinct items, rank the rest of the session.

Each task is graded with two numbers. Hit rate asks a blunt question: did anything the user actually engaged with make the top 10? NDCG@10 also cares where it landed, so a system that puts the right item first scores better than one that buries it at position nine. A cell reading 55.3% / 0.231 is 55.3% hit rate and 0.231 NDCG@10.

Our benchmark runs on 2,000 items across 40 categories, with 2,000 users and 9,120 sessions over roughly 30 days. The newest 20% of sessions are held out; everything else is training.

We also ran popularity and two models from the open-source implicit library, BPR and ALS, at default settings. Neither model beat the cosine path on similar-item or for-user — the best of the two, BPR on for-user, reached 29.4% against 37.3%. Counting beat both.

What the switch actually bought

Served through inferd, all three modes improve on the holdout:

ModeFastAPI, served todayinferd, cosine (before)inferd, raw counts (now)
Next item32.2% / 0.14744.0% / 0.17855.3% / 0.231
Similar item26.2% / 0.07242.7% / 0.12962.7% / 0.219
For user19.5% / 0.05837.3% / 0.13756.5% / 0.219

Next-item coverage comes out at 99.5%. These match the in-process holdout numbers, which tells us the export and the service aren’t adding noise between the offline experiment and the answer a caller receives.

The middle column is the part worth dwelling on. The first version of inferd kept the vectors and scored candidates by cosine similarity. That already beat the FastAPI service on similar-item and for-user by a wide margin, and on next item it went from 32.2% to 44.0%. Good enough to stop thinking about, if we had wanted to stop.

The last column is what happens when the vectors come out. Scoring by raw session counts instead — how often two items actually appear together, with no learned representation in between — lifted similar-item from 42.7% to 62.7% and for-user from 37.3% to 56.5%, and pushed next item to 55.3%. Same artifacts, same service, less machinery.

Why raw counts beat the learned vectors

This is the part we got wrong first, so it’s worth explaining properly.

Item2vec trains vectors so that items used in similar contexts end up near each other in space. Raw counts just record which items appear in the same session. The first is a learned approximation of the second: if the model does its job, cosine similarity between two vectors should recover roughly what the count table already knows.

On about 7,000 short sessions, the approximation doesn’t come back sharp enough to pay for itself. The vectors smooth over co-occurrence patterns that the counts keep intact, and with sessions this short there isn’t enough signal to smooth over without losing detail.

We checked whether we were starving the vectors rather than mislearning from them. Rerunning with min_count = 1 still scored 25.8% on similar-item, so sparse vocabulary wasn’t the problem. We also retuned epochs: on a validation split, two epochs beat the default of five, and fifteen or thirty were worse than both. Cutting to two lifted similar-item hit rate to 28.4% — real, and nowhere near what counting gets.

That’s the unglamorous conclusion. The learned representation was extra machinery producing a worse copy of a table we could build in one pass.

The next-item threshold

The next-item table only proposes an item after a pair has been seen enough times. That minimum count is a single number, and it trades coverage against precision:

Minimum countNext-item hit rateCoverage
3.0 (the FastAPI setting)32.2%70%
2.040.2%—
1.051.8%99%

Coverage climbs from 70% to 99% across that range, because at 1.0 even a single co-view gets the pair into the table.

We measured all three through the baseline’s own training and lookup code. At 3.0, the table can answer for seven items in ten, and the other three fall back to something else. That filter was costing more than it protected: every step down the threshold bought a large jump in hit rate, and the raw-count path takes it further, to 55.3% at 99.5% coverage.

The trade is still real. One-off transitions in this benchmark happen to be correct, so a threshold of 1.0 looks better here than it would on a stream where a single co-view is as likely to be a misclick as a preference.

The speed results

Serving from memory instead of recomputing per request is where most of the gain came from. These are end-to-end medians through each service’s own stack:

ModeFastAPI baseline, medianinferd, medianRatio
Next item3.75 ms0.057 ms~66x
Similar item4.50 ms0.056 ms~80x
For user (item2vec, exact)4.81 ms0.248 ms~19x
For user (co-occurrence)n/a0.065 ms~74x vs FastAPI for-user

Read the last row against the 4.81 ms for-user call it replaces, since the baseline has no co-occurrence mode to compare against. The interesting row is the third. Exact for-user over item vectors is the only mode where inferd still has meaningful work to do at request time, and it shows, at about 19x against 66 to 80x everywhere else. Moving that mode onto counts took it from 0.248 ms to 0.065 ms, which is why we stopped treating vector search latency as the constraint on this endpoint.

Where this leaves us

The two changes compound. Similar-item and for-user hit rates more than doubled against the FastAPI service, next-item rose by more than half, and the slowest mode left costs about a fifth of a millisecond. The ranking behind all three is a count table we rebuild in a single nightly pass, and it is measurably better than what it replaced.

Put discovery in front of the catalog you already run

SuggestAPI routes search and recommendations without replacing the store or the search engine behind them.