← All case studies
Case study 01 · Applied AI
Mihir AI: a secured, grounded portfolio assistant
Hybrid retrieval over a corpus I control, built to run on free tiers and treated as a security surface from the first commit.
Context
Personal build; public chat is not offered on this site
My role
Sole designer and engineer
Stack
TypeScript, Cloudflare Workers, Workers AI, Llama 3.1 8B, BGE embeddings
The situation
A portfolio usually makes visitors hunt for answers. I wanted one that could answer focused questions about my work, from a source I control, without turning into a liability.
A public AI endpoint with storage and email is an attack surface. It also had to cost effectively nothing to run, and every answer had to be traceable to something I wrote.
What I did
I designed and built all of it: the chat widget, the Cloudflare Worker API, the indexing scripts, the security layers and the evaluation harness. The first version put my whole profile in the prompt; I later moved it to hybrid retrieval behind a feature flag.
Approach
- 01Five Markdown source files are split on headings into 21 chunks, embedded with BGE base (768 dimensions) and stored in D1 alongside an FTS5 keyword index.
- 02Each question runs vector search and BM25 keyword search. Results are fused with Reciprocal Rank Fusion (k = 60), then optionally reranked by the LLM, falling back to the fused order if the rerank fails.
- 03Llama 3.1 8B on Workers AI answers from the top five passages and must cite chunk IDs. The server drops any cited ID that was not actually retrieved.
- 04Security runs before any model call: HMAC-signed CSRF tokens, per-session message caps, per-IP and global rate limits, Turnstile after sustained use, and a prompt-injection filter.
- 05Hybrid retrieval shipped behind a RAG_ENABLED flag, with the original profile-in-prompt path kept as a rollback.
Request path
01
Question arrives
POST /api/chat
02
Security gate
HMAC CSRF · KV limits · Turnstile
03
Injection screen
Deterministic filter
04
Hybrid retrieval
BGE vectors + FTS5 BM25 → RRF
05
Rerank
Llama 3.1 · optional
06
Generate
Llama 3.1 8B FP8 · Workers AI
07
Validate citations
Server-side check · D1
Explore each stage in the Lab →
Results
Recall@5 of 1.0 and MRR of 0.98 with hybrid retrieval and reranking, on a controlled evaluation set over a small corpus.
Designed for low operating costs using Cloudflare free-tier services; usage limits still apply.
Documented publicly, including what the system does not guarantee.
Tradeoffs & limits
With 21 chunks, a linear scan is simpler and cheaper than a vector database. That changes if the corpus grows.
Citation checks filter the structured metadata, not the reply text. An uncited claim is not blocked today.
The widget does not show sources yet, even though the API returns them.
Technologies
TypeScriptCloudflare WorkersWorkers AILlama 3.1 8BBGE embeddingsD1 + FTS5KVTurnstileVanilla JS