Objective
"Show me patients like this one" powers cohorting, case comparison, and outcome review. Structured filters miss the clinical resemblance that lives in the narrative. This recipe finds patients whose presentation is clinically similar to an index case by meaning — inside your environment, so no PHI leaves.
Step 1: Patient presentation summaries with embeddings
DROP TABLE IF EXISTS patient_summary;
CREATE TABLE patient_summary (
patient_id TEXT PRIMARY KEY,
summary TEXT,
emb VECTOR(384)
);
INSERT INTO patient_summary VALUES
('P-001','65M with exertional chest pain, dyspnea, and troponin elevation; history of hypertension.',
EMBED('65M with exertional chest pain, dyspnea, and troponin elevation; history of hypertension.')),
('P-002','29F with migraine, photophobia, and nausea; no focal deficits.',
EMBED('29F with migraine, photophobia, and nausea; no focal deficits.'));
Step 2: Retrieve patients similar to an index presentation
SELECT patient_id,
COSINE_SIMILARITY(
emb,
EMBED('Older man with chest pressure on exertion, shortness of breath, and elevated cardiac enzymes.')
) AS sim
FROM patient_summary
ORDER BY sim DESC
LIMIT 1;
Result — the cardiac index case matches the cardiac patient, not the migraine one:
| patient_id | sim |
|---|---|
| P-001 | 0.67 |
Why it matters
Semantic patient similarity powers cohort discovery, similar-case review, and outcome comparison — over the same store that holds the records, inside your HIPAA scope. Combine it with grounded clinical retrieval for evidence, and log any decision it informs to a tamper-evident CDS lineage.