Skip to content

About

LLM-powered chatbot for browsing a personal book library. Retrieval-strategy benchmarks, eval harness, and hardening breakdown shared here for your own exploration.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Adso Shelf: a chatbot for browsing my library

Adso Shelf is an LLM-powered chatbot that answers questions about my book collection: what I've read, what I rated highly, what it'd recommend on a given topic. It's styled as a slightly pompous medieval librarian monk named Adso, and it's live at davidwhipps.com/shelf, pulling from my actual library.

This repo is the Adso Shelf half of my personal site, pulled out on its own. The idea behind it is basically a conversation starter: instead of a static "here's my Goodreads" page, visitors can actually ask questions about my full catalogue and get real answers back. What's here is three different ways of grounding a chatbot in a personal dataset, benchmarked against each other with real numbers instead of vibes, plus the eval harness and hardening work that came out of taking it from "works on my machine" to "safe to leave running on the public internet." It won't run standalone as-is. See Provenance for what got left behind and why.

What it does

A drawer-style chat UI (AdsoChatDrawer.tsx) talks to a streaming API route (chat.ts) backed by Claude Haiku through the Vercel AI Gateway. Adso Shelf is only allowed to answer from the actual catalogue: no inventing titles, no inventing ratings. It's also supposed to stay in character when people try to jailbreak it or get it to spit out its own system prompt. Mostly it does.

Three ways to ground a chatbot, tested against each other

Here's the problem I actually wanted to solve: my library is around a thousand books. Too much to always cram into context, but I still wanted Adso to answer specific questions correctly, not confidently make something up. So adso.ts has three swappable variants (flip ADSO_VARIANT and go) sharing the same prompt/tool pipeline, so I could test them apples-to-apples through the same eval harness:

Variant Approach
A Stuff the whole catalogue into context, no tools
B Lean prompt + a query_books structured-filter tool
C B, plus search_notes: semantic search over embedded notes/descriptions

I ran each against a 44-case golden set spanning five buckets (recommendations, voice, refusals, prompt injection, plain factual lookups), judged by an LLM scorer (scorers.ts) through Evalite. Full breakdown and the judge's actual reasoning is in docs/experiment-results.md, but here's the short version:

C won. 96% accuracy, 12x cheaper and twice as fast as just stuffing the whole catalogue in.

Variant Score Mean latency Mean input tok Est. cost/q
A (context stuffing) 80% 6400ms 107,865 $0.0638
B (structured tool) 95% 3367ms 4,639 $0.0053
C (+ semantic search) 96% 3208ms 4,709 $0.0053

Honestly the cost gap didn't surprise me much. What did was how much A's quality fell apart once the catalogue got big enough: at a ~101K-token stuffed prompt, the voice score cratered to 50%, and it leaked its own system prompt on one of the injection attempts. Not just slower and pricier. Actually worse at the job.

Keeping it from getting expensive or weird

A chat endpoint sitting on top of a paid model, open to the internet, is basically an invitation to run up my bill or get it to say something dumb. I put together five layers to deal with that, written up properly in docs/hardening-runbook.md:

  1. Per-request caps on message length and conversation turns (checkCaps() in adso.ts)
  2. Vercel BotID to block obviously automated callers
  3. WAF rate limiting per IP
  4. A hard monthly cap on AI Gateway spend. Worst case, the widget just stops working instead of racking up a bill
  5. Prompt-injection resistance, covered by its own bucket in the eval suite

Where the data comes from

The catalogue comes from a Goodreads-to-JSON CLI I built called Adso, not to be confused with Adso Shelf, the chatbot in this repo (the character borrows the CLI's name). scripts/sync.ts embeds and compacts that export into data/books.json and data/embeddings.json. data/README.md has the full update process if you're curious. This is genuinely my library: real ratings, real notes, left in as working sample data in case anyone wants to fork this and point it at their own shelf.

Provenance

This is carved out of a bigger Astro site, not something you can npm install and run today:

  • src/pages/api/chat.ts uses Astro's APIRoute convention and assumes it's running inside an Astro project with the @astrojs/vercel adapter.
  • The chat drawer was originally mounted as an Astro island via @astrojs/react, and its styling assumes Tailwind is available on the host page.
  • telemetry.ts wires up OpenTelemetry and Langfuse tracing; see the env vars below.
  • Env vars, from .env.example: AI_GATEWAY_API_KEY (required), LANGFUSE_* (optional, for tracing), ADSO_VARIANT (defaults to A if unset), PUBLIC_ADSO_BOTID (opt-in bot detection).

If you want to actually run this: drop src/lib, src/components, src/pages/api/chat.ts, and data/ into your own Astro + Vercel project, wire the drawer into a page, set the env vars above, and you're most of the way there.

About

LLM-powered chatbot for browsing a personal book library. Retrieval-strategy benchmarks, eval harness, and hardening breakdown shared here for your own exploration.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages