Back to Docs
RECIPE
Book recommender
Build a personalized book suggestion engine using collaborative filtering and content-based signals. Deploy as a serverless API on Vercel with Upstash KV for caching.
1
Collect ratings
Ingest user-book rating pairs into a sparse matrix. Use implicit signals like page views and time-on-page as fallback.
2
Train embeddings
Run alternating least squares on the user-item matrix. Store latent vectors in Upstash KV for sub-10ms retrieval.
3
Serve top-K
Compute cosine similarity between user and item vectors. Return top-10 recommendations with confidence scores.
Cold-start strategy
For new users with zero ratings, fall back to a popularity-weighted random sample from trending books. Warm the cache every 6 hours via a Vercel cron job hitting your /api/recommendations/trending endpoint.
API shape
GET /api/recommendations?userId=abc&limit=10
{
"items": [
{
"bookId": "isbn_978...",
"title": "Dune",
"score": 0.94,
"reason": "Readers like you enjoyed this"
}
],
"generatedAt": "2026-01-15T14:30:00Z"
}