System flow
First the short version: what happens when a patient sends text or a photo. Then the whole bot on one whiteboard: how a question becomes a cited answer or a booking, how a clinic's PDF becomes searchable knowledge, and what each piece of the stack does.
If the patient types a message
See it on the whiteboard ›e.g. "How much is a CBC?" or "Book me with the pediatrician on Friday"
- Safety check firstSymptoms or medicine questions go straight to a staff member. The AI never answers those.
- It looks up the clinic's own documentsIt finds the few passages from the clinic's PDF that match the question.
- The AI writes an answer from those passages onlyFor prices, open slots and bookings it asks the clinic's system, so numbers are never made up.
- Everything is checked before it is sentA price that is not on the clinic's list is blocked.
- The patient gets an answer, a booking, or a personAnswers show which part of the PDF they came from.
If the patient sends a photo
See it on the whiteboard ›e.g. a picture of their HMO card or a doctor's lab request
- It checks the file is really a photoAnything else, or anything too big, is refused. A private copy is kept for staff.
- An AI that can see reads the pictureWhat kind of document it is, the important details on it, and how sure it is.
- The clinic's own rules decide the reply, not the AIHMO card: says if that HMO is accepted, with the member ID partly hidden. Lab request: lists each test with its price and a total.
- Anything risky or unclear goes to a personPrescriptions are never read out; staff take over. A blurry photo gets "please send a clearer one".
- The patient gets a clear reply in secondsStaff can see the same photo and the bot's notes.
The full whiteboard
Where patients talk to it
Web chat
The chat on the Try it page.
Live in this demoTelegram
Not live in this demo. Plugs into the same core: same answers, bookings and guardrails.
Planned channelWhat did they send?
The bot picks a path.
1. Text: a patient asks a question
This is RAG with tools. The bot retrieves the clinic's own text first, so the AI answers from facts, not from memory.
Patient types
"How much is a consultation?"
Web chatGuardrail
Symptoms or medicines? Straight to staff. The AI never sees it.
Worker codeEmbed the question
Text becomes a vector (a list of numbers that captures meaning).
Embeddings modelVector search
Find the 4 closest passages from the clinic's PDF. Weak matches dropped.
Neon pgvectorLLM + passages
The AI only sees those passages and the clinic's facts, and must cite them.
Neon AI GatewayTool calls
get_price · find_slots · book_slot · handoff. Real data, real bookings.
Cloudflare D1Checks
A price not on the list is blocked. Every message gets a reply or a person.
Worker codeAnswer + sources
Hours, services, policies, quoted from the PDF.
Exact price
Read from the price list, never guessed.
Booking made
A real slot is held, with a confirmation.
Handed to staff
Medical, unclear or a complaint.
= Retrieval (find the right passages) + Augmented (give them to the AI) + Generation (the AI writes the answer, citing them).
2. Photo: a patient sends an image
HMO cards and lab requests are read by a vision model, then checked by code.
Patient sends a photo
Saved privately first, so staff can see it too.
Cloudflare R2Is it really an image?
Checks the file itself, not its name. Too big or not an image? Refused.
Worker codeVision model reads it
What it is, the fields, how sure it is, as fixed JSON. No RAG here.
Vision LLMCode writes the reply
Not the AI. Under 70% sure counts as unreadable.
Worker codeHMO card
"Maxicare is accepted here", member ID masked.
Lab request
Each test with its price and a total.
Prescription
Never read out. Passed to staff.
Blurry or unsure
Asks for a clearer photo.
3. Behind the scenes: a clinic teaches it
Done once per clinic, in about a minute. This is what makes lane 1 possible.
Clinic uploads a PDF
Services, prices, doctors, schedules, HMOs, policies.
Cloudflare R2Workflow runs
Extract text → split into ~180-word chunks.
n8nEmbed every chunk
Each chunk becomes a vector and is stored for search.
Neon pgvectorPull out the facts
The AI fills a fixed form (structured output), validated before saving.
LLM + ZodHuman review
A person checks the facts and publishes. Slots are made from schedules.
Cloudflare D1Tech stack
- Cloudflare Workers + Hono · runs the bot, no servers
- Cloudflare D1 (SQL) · clinic data; a slot books once
- Cloudflare R2 · PDFs and photos
- Neon Postgres + pgvector · the vector database for RAG
- Neon AI Gateway · LLM, vision, embeddings; swappable
- n8n · the ingestion workflow
- TypeScript · Zod · Vitest · typed, validated, 71 tests
Words on this board
- RAG · Retrieval-Augmented Generation: look up the right passages first, then let the AI answer from them
- Embeddings · text turned into vectors so "check-up" can match "consultation"
- Vector database · stores those vectors and finds the closest ones fast
- Tool calling · the AI asks the code to do things (check a price, book a slot)
- Guardrails · rules in code the AI cannot talk its way around
- Human in the loop · a person reviews facts and takes over when the bot is unsure
Swap the documents, keep the engine
- The engine · upload, chunk, embed, retrieve, cite, guardrails, handoff, vision. Domain-free.
- The clinic skin · the facts form and the price and booking tools.
- Law firm · answers from engagement terms, books consultations, flags legal advice for a lawyer.
- Hardware store · answers from product manuals, checks stock and prices.
- HR or support · answers from handbooks and SOPs, opens a ticket for a person.
Try the botComing next: demo limits, voice notes, an n8n back office and a scored test set.