Query Enrichment Pipeline
Hospital website content is written in everyday Dutch ("te traag werkende schildklier"), but patients arrive with Latin medical terminology ("hypothyreoïdie"), colloquial terms ("rugpijn"), or clinical abbreviations ("AVM"). Retrieval from an unenriched query embeds the patient's surface form against a corpus that doesn't share their vocabulary, with predictable consequences for recall.
Query enrichment runs in the RAG service — between intent classification and retrieval — and applies three enrichment layers in cascade. The cascade does not modify the user's question; it appends canonical terms in parentheses so that both the embedding and the BM25 tsvector see the bridging vocabulary.
This page covers the pre-retrieval term-bridging cascade SNOMED synonyms, taxonomy "treats" routing, and Latin→Dutch translation appended to the search query. The broader structured-knowledge injection flow — entity resolution, ontology lookup, the conditional doctor-list injection (Stage 5c), and prompt augmentation — is documented in Taxonomy Query Enrichment.
Why enrichment exists
The feature was identified as a regression during the pilot evaluation on 2026-03-20: the SNOMED synonym expansion that existed in the Neo4j-based pipeline had been silently lost during the migration to the PostgreSQL taxonomy on 2026-03-07. Three questions in the project's golden evaluation set failed because medical terminology queries could not find their Dutch equivalents in the taxonomy. The cascade documented here was the structural response.
This is also the canonical example of the project's silent-failure discipline (a failure that produces no error must still be made visible). The post-mortem closed not just the recall regression but also added size logs to every collection-returning function in the enrichment path, and a contract test for the handoff between the intent classifier's extracted entities and the enrichment service's resolved-term injection.
Trade-offs
| Decision | Chosen | Alternatives considered | Rejected because |
|---|---|---|---|
| Where to enrich | Append canonical terms in parentheses to the user query before embedding/BM25 | Replace user query with canonical term; append after embedding (re-embed twice); enrich only at re-rank | Replacement loses the user's surface form, which the LLM still wants for paraphrase fidelity in the answer. Re-embedding twice doubles the cost of the dense path on every query. Late enrichment (at re-rank) is too late — the recall failure is upstream of re-rank. Pre-retrieval append leaves the original token in place and adds the canonical neighbour as a free signal for both the dense and sparse paths. |
| Layer order | SNOMED → taxonomy TREATS → per-word fallback | Run all layers, take union | The layers are in quality order (SNOMED is most precise, per-word fallback is most permissive). First-match short-circuits to keep the appended canonical-term list focused. Union-of-all produced noisy enriched queries (several canonical terms appended) that hurt BM25 precision. |
| Synonym source | SNOMED CT Belgian Edition (a large set of active Dutch descriptions) | Curated alias map; Wiktionary; Wikipedia redirects | A curated map cannot keep pace with clinical vocabulary; Wiktionary lacks medical depth; Wikipedia redirects are too noisy. SNOMED CT is the international standard for clinical terminology with native Dutch coverage. See SNOMED CT Terminology for ingestion and resolution detail. |
| Hospital-agnosticism | Latin → Dutch translation lives in the LLM intent-classifier prompt, not in code | Hardcoded term mapping in code | A code-level mapping must be maintained per hospital; the LLM-prompt approach is hospital-agnostic — the model uses its medical knowledge natively. The prompt instruction is a single sentence. |
Architecture
Layer 1 — SNOMED synonym expansion
Purpose: bridge Latin or scientific medical terms to the Dutch names used in the hospital taxonomy.
Algorithm:
- Look up the exact query in the SNOMED Dutch descriptions (see SNOMED CT Terminology).
- For each match, find taxonomy entities sharing the same SNOMED concept.
- If the entity name differs from the query token, inject it as a search enrichment.
Worked example:
- Query: "hypothyreoïdie"
- SNOMED match: the hypothyreoïdie concept
- Published taxonomy entity with the same concept: "Hypothyroïdi" (a published condition entity)
- Enriched query:
"hypothyreoïdie (Hypothyroïdi)"
Fallback within Layer 1: if exact match fails, the resolver tries a fuzzy match against SNOMED descriptions. This catches compound terms — lumbale discushernia matching a query for discushernia.
Layer 2 — taxonomy TREATS / OFFERS expansion
Purpose: when the user asks about a condition, append the department names that treat that condition so retrieval lifts the relevant department-overview pages.
Algorithm:
- Take the condition extracted by the intent classifier.
- Look up the published taxonomy relationships (treats / offers / performs) that point at that condition.
- Append the resolved department names to the search query.
Worked example:
- Query: "ik heb last van epilepsie"
- Intent classifier extracts the condition "epilepsie"
- Taxonomy: Neurologie TREATS Epilepsie; Neurochirurgie TREATS Epilepsie
- Enriched query:
"ik heb last van epilepsie (Neurologie, Neurochirurgie)"
This ensures department overview pages rank higher in retrieval — not just condition-explanation pages — so the LLM gets the routing answer the patient actually needs.
Layer 3 — Latin-to-Dutch translation (LLM)
Purpose: for inputs Layers 1 and 2 cannot resolve, the intent classifier's reformulated query carries Latin → Dutch translation.
The intent classification prompt includes the rule:
"When the user uses Latin or scientific medical terms, ALWAYS include the common Dutch equivalent in the reformulated query. Hospital websites use Dutch, not Latin. Use your medical knowledge to translate."
This is hospital-agnostic: there are no hardcoded term mappings. The LLM uses its medical knowledge natively, which means no per-tenant maintenance.
Relationship to Stage 5c (synthetic doctor-list injection)
When Layer 2 resolves a condition to a department, downstream Stage 5c may also fire if the intent is a doctor lookup AND the query contains a list-signal ("alle", "welke artsen", "wie werkt er"). In that case the resolved department from Layer 2 is the same hint Stage 5c uses to fetch the full doctor roster. See Taxonomy Query Enrichment and Query Pipeline §Stage 5c.
Empirical impact (self-reported)
These figures are self-reported: they come from the project's own golden evaluation question set, scored by the project itself, comparing a build before enrichment (pilot version 2, 268 questions) with a build after it (pilot version 7, 299 questions), both run during the pilot evaluation in spring 2026. The golden-question score measures entity recall and must-refuse behaviour only; it is not evidence of answer correctness or grounding, and no independent party has reproduced it.
| Metric | Before (268 questions) | After (299 questions) |
|---|---|---|
| SNOMED terminology category | 22 of 25 passed | 33 of 33 passed |
| Condition-department routing | 36 of 38 passed | 46 of 46 passed |
The question count changed (268 to 299) because new failure cases were added to the golden set between the two runs; the comparison is across different set sizes, not the same set. The category-level results use the same per-question pass/fail check. A re-run after the later embedding-model migration has not been done.
Performance
Enrichment consists of two small database lookups per query; the translation layer happens inside the existing intent-classification call and adds no separate call. Its cost is small next to the language-model calls in the pipeline. No dated latency measurement is published for it here.
Known limitations
- "dyslipidemie" — a SNOMED concept exists but no published taxonomy entity carries this concept (no ZOL page about dyslipidemie). This is a content gap, not a code issue. The resolver returns no enrichment; retrieval falls back to vector-only.
- "hernia nuclei pulposi" — the Belgian SNOMED edition maps this term to a different concept ID than
discushernia. Layer 3 (LLM translation) handles this case because the model knows the two are synonyms, even though the SNOMED graph does not link them. - Compound-word boundary — bloeddrukverlagend (blood-pressure-lowering) does not match Hypertensie through SNOMED alone. The compound is not in the SNOMED descriptions as a single term. Layer 3 (LLM translation) recovers most of these cases; an explicit Dutch-compound splitter has not been needed at pilot scale.
Shared department resolver (2026-06-09)
Department-name matching in post-answer enrichment (and the voice and scheduling surfaces) can route through a shared resolver with four structural tiers — normalise, exact, token-subset, alias — replacing per-surface substring heuristics. It is behind a switch that is off by default pending a regression evaluation. This change does not affect the three enrichment layers above; it affects only how department names are matched against query text during post-answer enrichment.
References
- @chen2024bgem3 — historical context for the Layer 1 vector-search baseline; BGE-M3 is now the ColBERT-only model after ADR-0048.
- SNOMED CT Terminology — terminology ingestion, the 12-resolver chain, and the FINDING_SITE routing extension.
- Taxonomy Query Enrichment — the broader 12-resolver chain that runs alongside the cascade documented here.
- ADR-0019: Contextual Embeddings — how canonical questions and chunk context are embedded.
- Lewis, P., et al. (2020). Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks. NeurIPS 2020.