Taxonomy Query Enrichment
Every non-blocked query passes through a taxonomy enrichment pipeline that injects structured hospital knowledge into the retrieval and generation stages. This page documents the query-time enrichment flow — from entity extraction through taxonomy resolution, ontology lookup, injection gating, the conditional doctor-list injection (Stage 5c), and prompt augmentation — explaining how structured knowledge-graph data complements vector search to produce grounded, entity-aware responses.
Two pages cover "enrichment", at different levels. The Query Enrichment Pipeline is the canonical reference for the enrichment cascade — the three layers (SNOMED synonym, treats/offers, Latin→Dutch) that append bridging vocabulary to the query string. This page is the broader taxonomy resolver flow that the cascade sits inside: entity extraction, the 12-resolver chain, the injection gate, Stage 5c, and prompt augmentation. Step 3 below is where the two meet.
This is the query-time view of the Taxonomy. Resolvers 7–10 fall back to SNOMED CT when the deterministic chain misses, and Stage 5b is the Value Framework reranker. See the Core Concepts flow for how all three subsystems compose on a single query.
For the ingestion-time taxonomy population see the Population Lifecycle and Seeding Pipeline. For the taxonomy data model see Knowledge Graph Overview. For the overall query pipeline context see Query Processing Pipeline.
Trade-offs
| Decision | Chosen | Alternatives considered | Rejected because |
|---|---|---|---|
| Resolver chain shape | 12 specialised resolvers, first-match wins | Single fuzzy resolver; LLM-only resolution; one resolver per entity type | A single fuzzy resolver collapses precision (cardilogie → cardiologie and radiologie), an LLM-only resolver pays for a model call on every query for what is mostly cheap database lookups, and one-resolver-per-type misses cross-type aliases (e.g., a single-word query that could be a department alias OR a condition alias). The 12-resolver chain runs the cheap precise resolvers first and falls through to the fuzzy fallback only as a last resort. |
| Injection gate | Four-rule gate: structural intent → inject; sparse vector → inject; low similarity → inject; default → suppress | Always inject; never inject; LLM-decided gate | Always-inject dilutes strong vector contexts with redundant taxonomy text and can hurt answer faithfulness; never-inject costs the structural-question accuracy that the taxonomy is the authoritative source for. An LLM-decided gate adds a per-query LLM call to a path that doesn't otherwise need one. The four-rule gate is deterministic and fast, and its rules cover the cases the data shows matter. |
| Stage 5c (synthetic doctor-list injection) | Triple-gated: intent is a doctor or department lookup AND list-signal phrase AND department hint | Always-inject the full doctor list; never inject; cross-encoder re-rank that promotes doctor pages | Always-inject blows the context budget for single-doctor queries; never-inject was the pre-fix shape and produced an incomplete dermatologist list. A cross-encoder re-rank cannot discover doctors that the first-stage retrieval missed entirely. The triple gate fires only for the specific failure mode (list questions about a department's doctors) and is a no-op otherwise. |
Enrichment Pipeline Overview
Step 1: Entity Extraction
During intent classification, the Tier 2 LLM extracts structured medical entities alongside the intent. These entities drive all downstream taxonomy operations.
The extracted-entities structure contains:
| Field | Example |
|---|---|
| condition | "hartkloppingen" |
| department | "Cardiologie" |
| treatment | "chemotherapie" |
| examination | "MRI" |
| doctor | a doctor's surname |
| campus | "Sint-Jan" |
For colloquial or indirect queries (e.g., "Wie kan helpen met hartproblemen?"), the LLM extracts the implicit entity ("hartproblemen" as a condition) even though no medical term appears explicitly. See ADR-0030 for the design rationale.
Step 2: Taxonomy Resolution (12-Resolver Chain)
The extracted entities pass through the taxonomy resolver, which runs a chain of responsibility — twelve resolvers executed in priority order. The first resolver to match wins. This design enables precise resolution even for ambiguous, misspelled, or multi-language input.
Resolver Descriptions
| # | Resolver | Purpose | Example |
|---|---|---|---|
| 1 | Enrichment Trigger | Detect navigational enhancement phrases | "meer informatie over..." |
| 2 | Campus Exact | Match campus names and aliases | "Sint-Jan", "Genk" → Campus Sint-Jan |
| 3 | Dept Skipgram | Order-independent multi-word matching | "intensive zorgen" matches "Intensieve Zorgen" |
| 4 | Dept N-gram | Consecutive 2/3-word pair matching | "spoed opname" → Spoedgevallen |
| 5 | Dept Single Alias | Broadest single-word alias match | "cardio" → Cardiologie |
| 6 | Dept Alias Map | Exact department name lookup | "Orthopedie" → Orthopedie |
| 7 | Condition Exact | SNOMED → condition aliases → raw keywords | "suikerziekte" → Diabetes Mellitus |
| 8 | Dept from Condition | Condition-to-department routing | Diabetes Mellitus → Endocrinologie |
| 9 | Treatment Exact | SNOMED → treatment alias resolution | "hartfilmpje" → ECG |
| 10 | Examination Exact | SNOMED → examination alias resolution | "bloedonderzoek" → Labo |
| 11 | Specialty Exact | Specialty name lookup | "orthopedisch chirurg" |
| 12 | Fuzzy Fallback | Misspelling detection (high similarity cutoff) | "cardilogie" → Cardiologie |
SNOMED CT Integration
Resolver 7 (Condition Exact) can optionally fall back to SNOMED CT synonym expansion when the deterministic alias map misses. The synonym-expansion mechanism itself (alias map → SNOMED Dutch descriptions → IS-A concept expansion) is documented canonically in Query Enrichment → Layer 1; the underlying ontology integration is in SNOMED CT Terminology.
Step 3: Query Enrichment
After taxonomy resolution, the resolved canonical terms are appended to the search query (e.g. "hartkloppingen" → "hartkloppingen (Palpitaties, Cardiologie)") so that both the embedding and the keyword search see the bridging vocabulary, improving recall against the canonical-Dutch corpus.
This is the same enrichment cascade documented canonically — the three enrichment layers (SNOMED synonym expansion, taxonomy treats/offers routing, Latin-to-Dutch translation), worked examples, and the project's self-reported results — on the Query Enrichment Pipeline page. This page covers only how the step sits within the taxonomy resolver flow.
Step 4: Sequential Retrieval
Three operations execute sequentially (the database driver does not support concurrent queries on the same session):
4a. Vector Search (Enriched Query)
Standard pgvector cosine similarity search using the enriched query. Returns document chunks ranked by semantic similarity. See Hybrid Search for the full retrieval architecture.
4b. Taxonomy Search (Intent-Routed SQL)
The taxonomy query service routes to intent-specific handlers that traverse the taxonomy relationships:
| Intent | Traversal |
|---|---|
| Doctor lookup | doctors → their departments → department campuses |
| Department or service lookup | departments → campuses → doctors |
| Condition information | conditions → departments that handle them → doctors |
| Treatment or examination information | treatments/examinations → departments that offer them |
| Booking or contact | departments → campuses (with contact information) |
Each handler returns a structured result (for example: a department for a condition, with its campuses and doctors), which is converted to a natural-language content string and merged with the vector results.
4c. Ontology Lookup
Running as part of the sequential retrieval chain, the ontology lookup:
- Entity linking: maps extracted entity mentions to their taxonomy database entries
- Relationship retrieval: fetches relationships (part of, treated by, has facility, and so on) for the linked entities
- Context formatting: produces an ontology block that is prepended to the prompt context
The ontology block is prepended to the assembled context, giving the LLM explicit knowledge of entity relationships.
Step 5: Taxonomy Injection Gate
Not all queries benefit from taxonomy data. When vector search returns strong, relevant results, injecting taxonomy data can dilute the context with less relevant structured information. The injection gate applies four rules in order:
| Rule | Condition | Action | Rationale |
|---|---|---|---|
| 1. Structural intent | Intent is doctor lookup, department lookup, condition information, treatment information, or symptom description | Inject | Taxonomy is the authoritative source for organizational data |
| 2. Sparse vector results | Vector returned fewer chunks than a configured minimum | Inject | Graph fills the retrieval gap |
| 3. Low similarity | Best vector similarity score below a configured threshold | Inject | Rescue scenario — vector results are weak |
| 4. Default | Strong vector results with sufficient similarity | Suppress | Avoid diluting rich vector context |
When suppressed, taxonomy results from Step 4b are excluded from the context window. Only vector chunks proceed to the LLM.
Stage 5c: Synthetic Department-Doctor-List Injection
Stage 5c is a post-retrieval, pre-context-assembly step that fires only when all three of the following hold:
- The classified intent is a doctor lookup or a department/service lookup.
- The user query contains a list-signal phrase (e.g., alle, welke artsen, wie werkt er, list all, tous les médecins).
- A department or specialty hint can be resolved either from the classifier's extracted entities (department, service, or doctor) or from a pattern sweep over the rewritten query.
When all three gates pass, the stage queries the taxonomy for all doctors associated with the resolved department, builds a synthetic chunk listing them, and inserts it into the retrieved-chunks set before context assembly. This guarantees the LLM has the full roster available so the system prompt's "list all members" exception rule can fire faithfully — the LLM cannot list doctors it never saw in the context.
The stage was introduced as a regression fix for an incident on 2026-05-09 (a quality defect, not a safety event): a 6-turn voice conversation about dermatologists was capped at the same two names because vector retrieval surfaced individual doctor brochure pages without the shared department roster, and re-ranking could only reorder what retrieval returned. The synthetic-chunk approach guarantees the roster is in the context regardless of which doctor brochures retrieval picked up.
When any of the three gates is unsatisfied (e.g., a single-doctor lookup with no list signal), Stage 5c is a no-op. When it does fire, the cost is one indexed taxonomy query plus the synthetic chunk's contribution to the assembled context (a single short paragraph; well within budget).
Interaction with post-answer enrichment
When Stage 5c fires, all department doctors are already visible to the LLM, so the post-answer taxonomy enrichment step (described below) finds zero "new" doctors and appends nothing. The two mechanisms are complementary: Stage 5c is the proactive path for queries the gate identifies as list questions; post-answer enrichment is the safety net for multi-part queries whose intent classification didn't trigger Stage 5c.
Stage Execution Order
For an examiner tracing a live query, the post-classification stages execute in this order. All of the steps except the retrieval itself are small database or in-memory operations; no per-step latency figures are published here.
| Stage | Purpose |
|---|---|
| 5a Entity extraction (via intent classification) | Extract structured entities from the query (part of the intent LLM call) |
| Step 2 Taxonomy resolution (12-resolver chain) | Resolve user terms to canonical entities |
| Step 3 Query enrichment | Append canonical terms to the search query |
| Step 4 Sequential retrieval (vector + BM25 + taxonomy) | Gather candidate chunks |
| Stage 5b Value Framework affinity rerank | Multiply scores by the intent-by-category matrix (always on) |
| Stage 5c Synthetic doctor-list injection | Append a synthetic chunk with the full department roster (no-op unless all three gates pass) |
| Step 5 Taxonomy injection gate | Decide whether taxonomy results enter the context |
| Step 6 Routing hint injection | Prepend "condition X falls under department Y" directive |
| Step 7 System prompt augmentation | Append the graph-context instructions |
Step 6: Routing Hint Injection
When taxonomy resolves a condition→department mapping, a routing hint is prepended to the assembled context. This is a strong directive that ensures the LLM always mentions the correct department:
--- ORGANISATIE-INFORMATIE ---
De aandoening "Palpitaties" valt onder de dienst Cardiologie.
Je MOET deze dienst vermelden in je antwoord.
The routing hint is injected regardless of the injection gate decision — even if taxonomy results are suppressed, the organizational routing information is always present. This prevents the LLM from naming incorrect departments when the vector context alone is ambiguous.
Step 7: System Prompt Augmentation
When taxonomy data is present in the context (either via injection gate or routing hint), the system prompt receives additional graph-context instructions (paraphrased):
The following structured information was retrieved from the hospital knowledge graph.
- ALWAYS include relevant department names and organizational information.
- When a condition is discussed, you MUST mention which department(s) handle it.
- For department routing (which department handles a condition), treat the graph data as AUTHORITATIVE.
- Graph-derived information with a [number] marker — use it to cite.
- Graph-derived information without a [number] marker is supplementary and should NOT be cited with numbers.
These instructions ensure the LLM prioritizes taxonomy-derived organizational data over potentially conflicting vector search results. The "AUTHORITATIVE" directive is critical — it means when the taxonomy says Cardiologie handles Palpitaties, the LLM will state this even if a vector chunk from an outdated brochure suggests otherwise.
End-to-End Worked Example
User query: "Waar kan ik terecht met hartkloppingen?"
This example traces one query. For the same flow walked across five contrasting queries — taxonomy-TREATS department routing, a doctor-list (Stage 5c) question, a medical-dosing safety-gate decision, a cross-language rewrite, and a SNOMED synonym expansion — all with values captured live from the pilot, see A Query, End-to-End.
| Stage | Input | Output |
|---|---|---|
| Intent Classification + Rewriting | Raw query | One LLM call (ADR-0030) emits all three: intent = condition information, entity condition = "hartkloppingen", and a rewritten query "Welke afdeling van ZOL behandelt hartkloppingen?" (canonical Dutch — this becomes the search query the rows below operate on). See Query Rewriting. |
| Taxonomy Resolution | entity "hartkloppingen" | condition="Palpitaties", department="Cardiologie" (Resolver 7→8) |
| Query Enrichment | "hartkloppingen" | "hartkloppingen (Palpitaties, Cardiologie)" |
| Vector Search | Enriched query | Chunks about palpitations, heart rhythm, a Cardiologie brochure |
| Taxonomy Search | condition→department lookup | Cardiologie, with its campuses and doctors |
| Ontology Lookup | entity IDs | Palpitaties treated by Hartritme-onderzoek; Cardiologie has facility Hartcentrum |
| Injection Gate | Rule 1: structural intent | INJECT (condition information) |
| Routing Hint | condition→dept | "De aandoening Palpitaties valt onder de dienst Cardiologie." |
| System Prompt | Taxonomy context present | + graph-context instructions appended |
| LLM Response | Full context | "Bij hartkloppingen kunt u terecht bij de dienst Cardiologie van ZOL..." |
Configuration
Two administrator-adjustable settings control the injection gate: the minimum number of vector results before taxonomy is suppressed (default 3), and the minimum vector similarity before taxonomy is used as a rescue (default 0.35). Both can be changed at runtime.
Post-Answer Taxonomy Enrichment
In addition to pre-retrieval enrichment (Sections 1–6 above), the pipeline performs a post-answer enrichment step after the LLM generates its response. This addresses a specific gap: multi-part queries (e.g., "Wat zijn de bezoekuren? Bij wie kan ik terecht bij kinderpsychiatrie?") may be classified with a non-structural intent such as navigational, causing the pre-retrieval taxonomy injection gate to suppress graph data. The LLM answers from vector search alone, potentially missing relationship data.
How It Works
The guard node was added after a display defect: a department entity named for a nursing-ward code was matched on the bare word "afdeling" and then won the display tiebreak over the real Endocrinologie. A department name now must carry a specialty token (an alphabetic word of at least four characters that is not a generic suffix such as "afdeling" or "dienst") to enter the lookup or the display; otherwise enrichment is skipped rather than printing a ward code.
The "department scan" step can route through a shared resolver with four structural tiers: normalise/fold → exact match → token-subset match → alias match. It replaces per-surface substring heuristics with a single deterministic source of truth shared by chat, voice, and scheduling. It is behind a switch that is off by default pending a regression evaluation; when off, the legacy substring/word-overlap path is used unchanged.
After the LLM generates the response:
- Department scan: All published department names are checked against the response text (case-insensitive).
- Relationship lookup: For each matched department, the published works-in relationships are queried.
- Deduplication: Doctor names already mentioned in the response are filtered out.
- Append: Remaining doctors are appended as a clearly marked supplement:
---
*Aanvullende informatie uit de ziekenhuistaxonomie:*
Artsen verbonden aan Kinderpsychiatrie: (names of the department's doctors from the published taxonomy).
Design Principles
| Principle | Implementation |
|---|---|
| Additive only | Designed to be purely additive: it does not modify existing answer text |
| Verified data only | Uses published taxonomy (operator-approved, version-controlled) |
| Non-blocking | Failures are caught and logged; they never block the answer |
| Badge activation | When enrichment fires, the "Verified with hospital data" badge is shown |
| Multi-part safe | Works regardless of intent classification, since it runs post-generation |
This pattern is particularly valuable for the ZOL use case where patients ask complex, multi-faceted questions that span navigational and structural concerns in a single query.
References
- Lewis, P., et al. (2020). Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks. NeurIPS 2020.
- Karpukhin, V., et al. (2020). Dense Passage Retrieval for Open-Domain Question Answering. EMNLP 2020. — Foundation for the dense bi-encoder retrieval lane that runs alongside the taxonomy resolution chain.
- Sarmah, B., et al. (2024). HybridRAG: Integrating Knowledge Graphs and Vector Retrieval. — Formalises the hybrid KG + vector pattern this page documents. (Sarmah et al. 2024)
- Soman, K., et al. (2024). OntologyRAG: Ontology-enhanced retrieval-augmented generation. (Soman et al. 2024)
- SNOMED CT Terminology — terminology source for resolvers R7/R8/R9/R10.