Mapping Tools
These tools support mapping review when a single best result is not enough. They gather evidence, add context, and make candidate comparisons explicit.
When to use these tools
Use the mapping tools when you want to:
- compare exact, normalized, full-text, and embedding retrieval side by side
- build a candidate packet for a reviewer or downstream mapping service
- ask for broader parent concepts when a hit is too specific
- assemble one context object for a chosen concept
- expand simple concept expressions
- evaluate predicted mappings against a reference set
How they fit together
concept_ground vs mapping tools
Start source-term searches with concept_candidate_bundle. Use concept_ground for a fast lead from the first matching resolver tier.
The mapping tools are better when you want to inspect evidence and make an explicit selection.
| If you want... | Prefer... |
|---|---|
| A fast lead from the first matching tier | concept_ground |
| Multiple retrieval channels in one packet | concept_candidate_bundle |
| Deterministic normalized matching before ranked retrieval | concept_search_normalized |
| Rich context for a selected concept | concept_mapping_context |
concept_search_normalized
Deterministic normalized equality search over concept labels, with optional synonym matching and explicit normalization metadata in the response.
{
"query": "Type-II diabetes mellitus",
"domain": "Condition",
"include_synonyms": false,
"normalization_profile": "verbatim",
"remove_stop_phrases": true
}
Useful response fields:
normalized_querynormalization_stepsresults[*].matched_textresults[*].matched_text_normalizedresults[*].match_mode
concept_candidate_bundle
The default source-term search builds one evidence packet by combining:
- exact search
- normalized search
- full-text search
- embedding search
- optional standard mappings
- optional hierarchy preview
- optional relationship summary
{
"query": "type 2 diabetes",
"domain": "Condition",
"include_normalized": true,
"include_fulltext": true,
"include_embedding": true,
"include_standard_mappings": true,
"include_hierarchy_context": true
}
Representative response sections:
channelsreports which searches ran and how many candidates they foundstandardized_candidatescandidate_unionwarnings
In MCP, a lexical channel looks like {"available": true, "count": 2}. The embedding channel
looks like {"available": true, "requested": 5, "returned": 2} when it finds two of five requested candidates. An available embedding channel adds a warning when it returns fewer candidates than requested. A short list can mean fewer concepts match, the index scan stopped early, or standard-only filtering removed results. An unavailable channel reports zero returned candidates and a warning with the reason it could not run.
Channel counts apply before the merged-list limit. With standard_only=true, they reflect
post-filtering, deduplication within each channel, and per_channel_limit. The direct Python
service and REST endpoint also return each channel's result list.
With standard_only=true, retrieval can find non-standard sources. Groundworkers replaces those hits with their standard OMOP Maps to targets in the requested domain and deduplicates the results. For each mapped candidate, retrieved_by includes the source retrieval channels and maps_to. Each reached_via entry identifies the source concept, its vocabulary and the channel that found it. Embedding entries also include similarity when available. When a mapping leads outside the requested domain, warnings names up to three such targets with their source names.
When include_standard_mappings=true, standardized_candidates describes the standard mappings of non-standard sources from the candidate union before post-filtering.
Hierarchy previews and relationship summaries enrich only the first five merged candidates.
concept_nearest_standard_ancestor
Finds the nearest active standard ancestor using stored OMOP separation, abstaining on equal-distance ties. Accepts either a free-text query or an explicit concept_id. Useful when a source concept is too specific or non-standard and you need a broader standard parent.
{
"query": "left lower lobe lung adenocarcinoma",
"domain": "Condition",
"max_depth": 5
}
In query mode, vocabulary_id and parent_ids constrain grounded seeds; they do not filter ancestor targets. candidate_limit bounds the retrieved seed list, and only its first candidate is used for ancestor selection.
Useful response fields:
seed_candidatesselected_parentselection_reasonpath_to_parentalternative_parents
concept_mapping_context
Builds one deterministic context packet for a known concept ID so the caller does not have to stitch together multiple lower-level calls.
{
"concept_id": 201826,
"include_standard_mapping": true,
"include_ancestors": true,
"include_relationship_summary": true,
"include_neighbors": true,
"include_embedding_neighbors": true
}
Possible sections include:
conceptstandard_mappingancestorsdescendantsrelationship_summaryneighborsembedding_neighborswarnings
Set include_descendants=true to include up to descendant_limit rows (default 10, range 1..10) from three stored hierarchy levels. descendant_scope reports max_depth, limit, the full total, and whether more rows remain in truncated. The row limit does not change which descendants qualify.
{
"descendants": [{"concept_id": 441484, "depth": 1}],
"descendant_scope": {
"max_depth": 3,
"limit": 1,
"total": 12,
"truncated": true
}
}
concept_map_to_value
Finds Maps to value relationships for a source vocabulary ID and concept code.
{
"vocabulary_id": "ICDO3",
"concept_code": "8500/3"
}
concept_resolve_mapping_expression
Expands a simple list of concept items with support for:
concept_idinclude_descendantsexclude
{
"items": [
{"concept_id": 201826},
{"concept_id": 443392, "include_descendants": true},
{"concept_id": 320128, "exclude": true}
],
"domain": "Condition",
"deduplicate": true,
"resolve_to_standard": true
}
mapping_evaluate_candidates
Compares predicted mappings with a reference mapping set using hit-at-k agreement: the reference ID must occur within the first top_k predicted IDs. Omitting top_k uses all predictions. IDs are compared in memory without checking the vocabulary.
Rows are paired by source_key, source_id or source_term, in that order. Reference rows require reference_standard_concept_id; prediction rows use a ranked predicted_standard_concept_ids list (or predicted_concept_ids).
{
"predicted_mappings": [
{
"source_term": "type 2 diabetes",
"domain_id": "Condition",
"predicted_standard_concept_ids": [201826]
}
],
"reference_mappings": [
{
"source_term": "type 2 diabetes",
"domain_id": "Condition",
"reference_standard_concept_id": 201826
}
]
}
Useful response sections:
summary_metricsby_domainagreement_casesdisagreement_casesmissing_reference_casesextra_prediction_cases
Direct Python use
These workflows are also available directly through app.services.mapping.
from groundworkers.app import build_application
app = build_application(config)
mapping = app.services.mapping
bundle = mapping.concept_candidate_bundle("type 2 diabetes", domain="Condition")
context = mapping.concept_mapping_context(201826)
concept_shared_standard_ancestor
Read-only, deterministic common-ancestor selection for alternative concept IDs representing one source record. It needs a configured vocabulary/graph, not an embedding or LLM backend. Do not use separate combination ingredients as if they were alternative product candidates.
Supply concept_ids (2..200 positive strict integers, at least two distinct), max_depth (0..20, default 5), optional concept_class_ids / vocabulary_ids, and display limit (1..50, default 10) / offset (default 0). Filters must use exact installed catalogue IDs; null is unrestricted, empty/blank/unknown filters are invalid. RxNorm alone does not include RxNorm Extension.
{"concept_ids": [40166038, 41038881], "concept_class_ids": ["Clinical Drug"], "vocabulary_ids": ["RxNorm", "RxNorm Extension"], "max_depth": 5}
The response is {error, code, message, data}. On success data.status is selected, ambiguous, no_match, or incompatible_inputs. found indicates a unique selection, so it is false for an ancestry tie. Eligible targets must be active standard concepts in the same domain as every input. The response echoes constraints, complete-set counts and per-input distances for any selected target.
Distances are stored minimum separation from CONCEPT_ANCESTOR. Include each seed itself at zero; retain distinct zero-separation ancestors. Such a connection does not prove clinical interchangeability. Nearest means the lowest maximum distance across all inputs. Equal nearest distances abstain. Display pagination never changes that computation; limit=1 cannot force a selection. A selected concept is returned independently of the candidate display page.
Native MCP argument/schema errors set isError=true. Errors from the service use the typed envelope with error=true and data=null. Backend failure is never a no-match. Text and structured payloads are normalized to the same envelope.
Ancestry consistency changes
concept_nearest_standard_ancestor and hierarchy previews now use the same stored ancestry as concept_ancestors. Nearest-standard ties abstain instead of selecting the first row. Query mode still starts from the first grounded candidate, which is disclosed as seed_selection_policy; source-concept ambiguity remains the agent's responsibility. Maps-to fallback is labelled evidence_route=maps_to, with multiple targets left ambiguous. Missing relationship paths do not invalidate stored ancestor evidence and are reported separately.
concept_mapping_context uses ancestor_limit only as a display count (1..50). ancestor_max_depth independently sets stored separation (0..20, default 5). ancestor_scope reports the full count and whether the display was truncated. Ancestor bounds reject invalid values. Descendants use a fixed stored-ancestry depth of 3; descendant_limit defaults to 10 (1..10), and descendant_scope reports the full count and truncation. neighbor_limit defaults to 15 (1..100), and embedding_neighbor_limit defaults to 10 (1..20). The MCP schema rejects values outside these ranges; direct in-process calls retain the runtime clamps. For the runtime contract and bounded relationship-neighborhood behavior see stored ancestry and shared targets.