Objective
Individual Case Safety Report (ICSR) volume grows 20–30% a year, and a large fraction are duplicates or closely related reports of the same event — the same reaction, described in different words, arriving through different channels. Keyword matching misses them because the words differ ("muscle pain" vs "bilateral leg aches"). This recipe catches them by meaning, so a reviewer sees the whole cluster instead of processing the same case three times.
Everything runs in the same database that holds the cases — no export to a separate vector store.
Step 1: A tiny ICSR table with an embedding column
The VECTOR(384) column holds the 384-dimensional embedding of each report narrative. EMBED()
computes it inline at insert time using the built-in all-minilm model.
DROP TABLE IF EXISTS pv_icsr;
CREATE TABLE pv_icsr (
case_id TEXT PRIMARY KEY,
product TEXT,
reaction TEXT,
narrative TEXT,
emb VECTOR(384)
);
INSERT INTO pv_icsr VALUES
('US-2026-001','Atorvastatin','myalgia',
'Patient reported muscle pain in both legs after two weeks on atorvastatin.',
EMBED('Patient reported muscle pain in both legs after two weeks on atorvastatin.')),
('US-2026-002','Atorvastatin','muscle pain',
'Male patient, bilateral leg muscle aches, began about 14 days into atorvastatin therapy.',
EMBED('Male patient, bilateral leg muscle aches, began about 14 days into atorvastatin therapy.')),
('US-2026-003','Atorvastatin','headache',
'Mild transient headache, resolved without intervention.',
EMBED('Mild transient headache, resolved without intervention.'));