Blog — AI
RAG in Healthcare: From Generic Vector Stores to Patient-Isolated Knowledge
Retrieval-Augmented Generation (RAG) lets an AI model look things up before it answers, so its knowledge stays current and every claim points back to a source. In healthcare that fits naturally: guidelines, drug facts and hospital rules change constantly, and every answer must be checkable.
What RAG is, in plain words
An AI model is like a very well-read student who finished school a while ago. It knows a lot, but it cannot see your documents, and its knowledge stops at a certain date. RAG (Retrieval-Augmented Generation) fixes that by letting the model look things up before it answers, the way a student would open a textbook during an open-book exam.
Here is what happens when you ask a question:
- Prepare the library. Your documents are cut into small pieces (a paragraph or so). Each piece is turned into a list of numbers called an embedding. Pieces that mean similar things get similar numbers. The pieces and their numbers are saved in a vector database.
- Find the right pages. Your question is turned into numbers the same way. The database returns the pieces whose numbers are closest to your question, which means the pieces most likely to contain the answer.
- Hand them to the model. The best few pieces are placed in front of the model together with your question.
- Write the answer. The model answers using only those pieces and says which piece each fact came from.
Why this is better than just asking the model directly:
- It stays up to date. Change a document and the next answer uses the new version. No retraining needed.
- You can check it. Every answer points to the exact page it used, so a person can open it and confirm.
- You decide who sees what. The search happens in your own database, so your access rules apply before any text reaches the model.
The catch: if the search returns the wrong pieces, the model will still write a confident answer from them. In RAG, the quality of the search matters more than the size of the model.
How RAG helps in healthcare
Healthcare runs on written knowledge: treatment guidelines, drug information, hospital rules, and the notes in every patient’s file. That knowledge changes often, and every answer must say where it came from. That is exactly what RAG is good at.
| Use case | Who asks | What the system looks up | Why RAG is the right tool |
|---|---|---|---|
| Guideline helper | Doctors, nurses | Treatment guidelines, hospital protocols | Guidelines change every year; the answer must name the edition it used |
| Patient summary | Doctors, nurses | One patient’s notes, lab results, scans, medications | A full patient history is far too long to paste into one question |
| Medication safety check | Pharmacists, doctors | Drug information plus the patient’s current medications | Mixes shared knowledge with one patient’s data |
| Billing and coding help | Coders | Code lists, insurer rules, the visit note | The rule books are huge and differ by country and insurer |
| Insurance appeals | Office staff | Insurer policies, the patient’s history | Letters must quote the exact rule and the exact evidence |
| Patient education | Patients | Approved leaflets, the patient’s own care plan | Must stay inside checked content and that patient’s plan |
| Research | Researchers | Published studies, trial records | Too many papers to read; citations are required |
| Everyday staff questions | Everyone | HR rules, procedures, device manuals | Saves time hunting through the intranet |
Look at the third column and you will see two kinds of knowledge. The first kind is shared: guidelines, drug facts, rules. Anyone with the right job can read it. The second kind is personal: the file of one patient, which only that patient’s care team may see. Many good assistants need both in the same answer. The rest of this article explains how to keep them in separate stores and still use them together.
One more thing makes healthcare different. A wrong answer is not just annoying; a wrong dose, or a note pulled from the wrong patient, can hurt someone. So in healthcare RAG, every answer must cite its sources, the system must check who is asking before it searches, and every answer is logged together with the pieces that produced it.
Building shared vector databases for different uses
A shared vector database holds knowledge that is not about any one person: guidelines, drug facts, rules, manuals. Think of it as the hospital library. The rule is simple: one shelf per topic. Do not throw everything into one big pile, because each topic needs its own way of being cut up, its own update schedule, and its own list of who may read it.
One collection per topic
In vector-database language, a shelf is called a collection. Here is a sensible starting set:
| Collection | What goes in | How it is cut into pieces | How often it changes | Who may read it |
|---|---|---|---|---|
clinical_guidelines | National and hospital guidelines | By section, about one page each | When a new edition is published | Clinical staff |
drug_reference | Drug facts, interactions, hospital drug list | One piece per topic (dose, warnings, interactions) | Monthly, plus urgent safety alerts | Clinical staff, pharmacy |
coding_rules | Billing codes, insurer rules | One piece per code or rule | Yearly code releases, insurer updates | Billing staff |
org_policies | Procedures, HR rules, device manuals | By section, about half a page | Whenever a document changes | All staff |
research_corpus | Study summaries, internal research | One piece per summary | Weekly | Researchers |
Every piece carries a label
Searching by meaning alone is not enough. Each piece also needs small facts attached to it, called metadata, like the label on a library book:
- Where it came from: document title, link, page or section, so the answer can cite it.
- Which version: edition and date, so the system prefers the newest one and can say which it used.
- Where it applies: country or hospital site, because a dose rule in one place may differ in another.
- Who may read it: a level such as staff, clinical or patient, so a patient-facing app never retrieves an internal protocol.
- A fingerprint of the text, so when a document is re-uploaded, only the changed pieces are replaced.
How documents get in
- Turn the source (PDF, Word, web page, medical records format) into clean text, keeping headings and tables.
- Cut it into pieces along natural breaks like headings. Put the document title and section name at the top of each piece, so the piece makes sense on its own.
- Turn each piece into numbers with one embedding model per collection, and write down which model was used. Mixing models in one collection breaks the search.
- Save the pieces. If a document was withdrawn, delete its pieces.
- Run a test: a list of known questions with the expected sources. If the search gets worse, do not release the update.
Same shelf, different readers
One collection can serve many apps. You change how you search, not what is stored:
- Search two ways at once. Combine meaning-based search with old-fashioned keyword search. Drug names, codes and abbreviations are exact words that meaning-based search sometimes misses.
- Filter first, then rank. Apply the labels (site, reader level, date) as hard rules first, then rank what is left by similarity.
- Double-check the top results. Take the best 20 to 50 pieces, let a second, more careful model re-order them, and keep the best 5 to 8.
- Pick the right shelves. A small step decides which collections a question needs, so a billing question never searches the research shelf.
Building a patient vector database with real isolation
A patient’s file must never be mixed with another patient’s, not even by accident, not even in a search result that gets thrown away. So patient data gets its own store, and that store is built so that a search cannot cross from one patient to another. In technical terms, the patient ID is not a filter you add; it is a wall the search runs inside.
Three ways to build the wall
| Approach | How it works | Strength of isolation | Cost and effort | Good for |
|---|---|---|---|---|
| Label filter | One big collection; every piece carries patient_id and every search must filter on it | Weak: one forgotten filter leaks everything | Cheapest, simplest | Prototypes only |
| Namespace per patient | One collection, but the engine keeps a separate index (namespace or partition) per patient; a search is opened inside a namespace | Strong: the search never sees other namespaces | Moderate; most engines support thousands of namespaces | Most hospitals and clinics |
| Database per patient (or per care unit) | A physically separate database, schema or encrypted store per patient or per ward | Strongest: separate keys, separate backups | Highest; harder to run at scale | High-risk settings, research cohorts, legal holds |
Rules that make the wall hold
- Identity first, search second. The app proves who the user is and which patients they may see (from the hospital’s access system) before it opens any namespace. The search code receives the patient ID from that check, never from the user’s text.
- No cross-patient queries exist. There is simply no function that searches all patients at once. Population questions are answered from a separate, de-identified research store, not from this one.
- Separate encryption keys per patient or per unit. If a key is revoked, that patient’s data becomes unreadable, which also makes deletion requests easy to honour.
- Short-lived access. Each query carries a token that names the user, the patient and a reason (treatment, billing, audit). It expires in minutes.
- Log everything. Every search records who asked, about whom, which pieces came back, and what the model answered. This is the record auditors and patients can ask for.
- Test the wall. Keep automated tests that try to read patient B while logged in for patient A. They must fail every time, and the test runs on every code change.
What goes into a patient’s store
A patient’s record arrives in several shapes, and each is cut differently:
| Source | How it is cut | Labels on each piece |
|---|---|---|
| Clinical notes | One piece per note section (history, exam, plan) | Date, author, note type, encounter |
| Lab results | One piece per report, with values in a small table inside the text | Date, test name, abnormal flag |
| Imaging reports | One piece per report; the conclusion as its own piece | Date, modality, body part |
| Medication list | One piece per active prescription, refreshed on every change | Start date, status, prescriber |
| Discharge letters and care plans | By section | Date, specialty |
Two habits keep this store useful. First, store the date on every piece and let the search prefer recent pieces, because a lab result from last week matters more than one from five years ago. Second, re-embed pieces when they change; a medication list is not a document that is written once, it is a living list.
Using shared and patient stores in one answer
A question like “Is this patient’s new antibiotic safe with what they already take?” needs both stores. The flow is: check identity, open that one patient’s namespace, retrieve the medication list, then search the shared drug reference for interactions, then hand both sets of pieces to the model. The shared store never learns anything about the patient; only the small set of pieces travels to the model, and the answer cites both the patient’s list and the drug reference.
How the pieces fit together
Every question passes the identity check before any store is touched. The shared library answers with pieces filtered by the reader’s level; the patient store opens only the one namespace the user is allowed to see. The two sets of pieces meet only at the reranking step, and the model never sees more than those few pieces.
Security, compliance and keeping it running
The design above does most of the security work by shape: shared knowledge and patient knowledge never sit in the same store, and a search cannot leave its patient’s namespace. A few more rules finish the job.
- Embeddings are patient data too. The list of numbers made from a clinical note can be turned back into something close to the note. Treat embeddings with the same protection as the text: encrypted at rest, encrypted in transit, inside the same compliance boundary (HIPAA in the US, GDPR in Europe, plus local health-data rules).
- Watch where the model runs. If the embedding model or the chat model is a cloud service, patient pieces travel to it. Use a provider that signs a data-processing agreement, does not train on your data, and hosts in your region, or run the models inside your own network.
- Keep people in the loop. For clinical decisions, the assistant drafts and a clinician confirms. Show the sources next to the answer so checking takes seconds.
- Honour deletion. When a patient asks for their data to be removed, delete their namespace and its encryption key, and remove their pieces from logs after the legal retention period.
- Measure quality, not just uptime. Keep a test set of real questions with known correct sources. Track how often the right source is in the top results, and how often the model’s answer disagrees with the source. Review a sample of logged answers every week.
- Plan for drift. Guidelines change, embedding models get replaced, and a new model version means re-embedding every collection. Record the model name on every piece so you can migrate one collection at a time.
Where to start
Start with the shared store and a low-risk use case, such as staff policy questions or guideline lookup. It teaches the team chunking, labels and testing without touching patient data. Once the search quality is proven, add the patient store with namespace isolation, beginning with one unit and one question type, such as summarising a patient’s recent notes for a handover.
A practical first-quarter plan:
- Pick a vector engine that supports namespaces and label filters
- Load one shared collection and build a 50-question test set
- Connect user identity and patient permissions to the search layer
- Build the patient store for one unit, with cross-patient tests in the release pipeline
- Ship one assistant that uses both stores, with sources shown and every answer logged