Objective
A clinical decision-support answer is only safe if it is grounded in a citable source. This recipe does the retrieval half: given a clinical question, find the most relevant guideline or chart passage by meaning, so the answer (and its citation) trace to a real record rather than to the model's priors. Everything runs self-hosted — the embeddings compute where the PHI already lives.
Step 1: A small guideline corpus with embeddings
DROP TABLE IF EXISTS clinical_kb;
CREATE TABLE clinical_kb (
doc_id TEXT PRIMARY KEY,
source TEXT,
passage TEXT,
emb VECTOR(384)
);
INSERT INTO clinical_kb VALUES
('G-114','Sepsis bundle',
'For suspected sepsis, obtain blood cultures before antibiotics and start broad-spectrum antibiotics within one hour of recognition.',
EMBED('For suspected sepsis, obtain blood cultures before antibiotics and start broad-spectrum antibiotics within one hour of recognition.')),
('G-233','VTE prophylaxis',
'Assess VTE risk on admission; offer pharmacologic prophylaxis to high-risk medical inpatients without contraindication.',
EMBED('Assess VTE risk on admission; offer pharmacologic prophylaxis to high-risk medical inpatients without contraindication.'));
Step 2: Retrieve the passage that grounds the question
SELECT doc_id,
source,
COSINE_SIMILARITY(
emb,
EMBED('How soon should antibiotics be given when sepsis is suspected?')
) AS sim
FROM clinical_kb
ORDER BY sim DESC
LIMIT 1;
Result — the sepsis question retrieves the sepsis-bundle guideline as its grounding source:
| doc_id | source | sim |
|---|---|---|
| G-114 | Sepsis bundle | 0.76 |
Why it matters
The retrieved passage is the citation a clinician verifies and the anchor that keeps a generated answer honest — the grounding step behind hallucination control, running inside your HIPAA scope. Record the suggestion and the clinician's action on a tamper-evident CDS lineage table, and see the agent form in clinical Q&A grounded in your documents.