Skip to main content

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.

Scope vs. Query Enrichment Pipeline

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.

Part of the Knowledge & Retrieval Steering triad

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​

DecisionChosenAlternatives consideredRejected because
Resolver chain shape12 specialised resolvers, first-match winsSingle fuzzy resolver; LLM-only resolution; one resolver per entity typeA 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 gateFour-rule gate: structural intent → inject; sparse vector → inject; low similarity → inject; default → suppressAlways inject; never inject; LLM-decided gateAlways-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 hintAlways-inject the full doctor list; never inject; cross-encoder re-rank that promotes doctor pagesAlways-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:

FieldExample
condition"hartkloppingen"
department"Cardiologie"
treatment"chemotherapie"
examination"MRI"
doctora 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​

#ResolverPurposeExample
1Enrichment TriggerDetect navigational enhancement phrases"meer informatie over..."
2Campus ExactMatch campus names and aliases"Sint-Jan", "Genk" → Campus Sint-Jan
3Dept SkipgramOrder-independent multi-word matching"intensive zorgen" matches "Intensieve Zorgen"
4Dept N-gramConsecutive 2/3-word pair matching"spoed opname" → Spoedgevallen
5Dept Single AliasBroadest single-word alias match"cardio" → Cardiologie
6Dept Alias MapExact department name lookup"Orthopedie" → Orthopedie
7Condition ExactSNOMED → condition aliases → raw keywords"suikerziekte" → Diabetes Mellitus
8Dept from ConditionCondition-to-department routingDiabetes Mellitus → Endocrinologie
9Treatment ExactSNOMED → treatment alias resolution"hartfilmpje" → ECG
10Examination ExactSNOMED → examination alias resolution"bloedonderzoek" → Labo
11Specialty ExactSpecialty name lookup"orthopedisch chirurg"
12Fuzzy FallbackMisspelling 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:

IntentTraversal
Doctor lookupdoctors → their departments → department campuses
Department or service lookupdepartments → campuses → doctors
Condition informationconditions → departments that handle them → doctors
Treatment or examination informationtreatments/examinations → departments that offer them
Booking or contactdepartments → 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:

  1. Entity linking: maps extracted entity mentions to their taxonomy database entries
  2. Relationship retrieval: fetches relationships (part of, treated by, has facility, and so on) for the linked entities
  3. 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:

RuleConditionActionRationale
1. Structural intentIntent is doctor lookup, department lookup, condition information, treatment information, or symptom descriptionInjectTaxonomy is the authoritative source for organizational data
2. Sparse vector resultsVector returned fewer chunks than a configured minimumInjectGraph fills the retrieval gap
3. Low similarityBest vector similarity score below a configured thresholdInjectRescue scenario — vector results are weak
4. DefaultStrong vector results with sufficient similaritySuppressAvoid 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:

  1. The classified intent is a doctor lookup or a department/service lookup.
  2. The user query contains a list-signal phrase (e.g., alle, welke artsen, wie werkt er, list all, tous les médecins).
  3. 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.

StagePurpose
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 enrichmentAppend canonical terms to the search query
Step 4 Sequential retrieval (vector + BM25 + taxonomy)Gather candidate chunks
Stage 5b Value Framework affinity rerankMultiply scores by the intent-by-category matrix (always on)
Stage 5c Synthetic doctor-list injectionAppend a synthetic chunk with the full department roster (no-op unless all three gates pass)
Step 5 Taxonomy injection gateDecide whether taxonomy results enter the context
Step 6 Routing hint injectionPrepend "condition X falls under department Y" directive
Step 7 System prompt augmentationAppend 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?"

See it across four queries

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.

StageInputOutput
Intent Classification + RewritingRaw queryOne 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 Resolutionentity "hartkloppingen"condition="Palpitaties", department="Cardiologie" (Resolver 7→8)
Query Enrichment"hartkloppingen""hartkloppingen (Palpitaties, Cardiologie)"
Vector SearchEnriched queryChunks about palpitations, heart rhythm, a Cardiologie brochure
Taxonomy Searchcondition→department lookupCardiologie, with its campuses and doctors
Ontology Lookupentity IDsPalpitaties treated by Hartritme-onderzoek; Cardiologie has facility Hartcentrum
Injection GateRule 1: structural intentINJECT (condition information)
Routing Hintcondition→dept"De aandoening Palpitaties valt onder de dienst Cardiologie."
System PromptTaxonomy context present+ graph-context instructions appended
LLM ResponseFull 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​

Specialty-token guard (2026-05-29)

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.

Shared department resolver (2026-06-09)

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:

  1. Department scan: All published department names are checked against the response text (case-insensitive).
  2. Relationship lookup: For each matched department, the published works-in relationships are queried.
  3. Deduplication: Doctor names already mentioned in the response are filtered out.
  4. 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​

PrincipleImplementation
Additive onlyDesigned to be purely additive: it does not modify existing answer text
Verified data onlyUses published taxonomy (operator-approved, version-controlled)
Non-blockingFailures are caught and logged; they never block the answer
Badge activationWhen enrichment fires, the "Verified with hospital data" badge is shown
Multi-part safeWorks 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​