pipeline
Four-step SNOMED CT attribute extraction pipeline.
Public API
find_attributes_two_stage(medical_term, attribute_index, ...) → dict
Helpers (prefixed with _) handle individual steps:
_retrieve_reference_examples — Step 1
extract_components — Step 2
_retrieve_candidates — Step 3
_build_selection_prompt — Step 4a
ContentFilterError
Bases: Exception
Raised when the LLM content filter blocks a response.
Source code in src/ariadne/hierarchy/pipeline.py
45 46 | |
call_llm(system_prompt, user_prompt, model)
Call the LLM and return LlmResult(content, cost_usd).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system_prompt
|
str
|
System-level prompt text. |
required |
user_prompt
|
str
|
User-level prompt text. |
required |
model
|
str
|
Model identifier (from |
required |
Returns:
| Type | Description |
|---|---|
LlmResult
|
LlmResult(content, cost). |
Raises:
| Type | Description |
|---|---|
ContentFilterError
|
If the content filter blocks the response. |
Source code in src/ariadne/hierarchy/pipeline.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
extract_components(medical_term, reference_text, cfg)
Step 2: Use the LLM to infer applicable SNOMED attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
medical_term
|
str
|
Term to decompose. |
required |
reference_text
|
str
|
Formatted reference examples block. |
required |
cfg
|
HierarchySettings
|
Pipeline configuration. |
required |
Returns:
| Type | Description |
|---|---|
ExtractionResult
|
ExtractionResult(components, cost). |
Source code in src/ariadne/hierarchy/pipeline.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
find_attributes_two_stage(medical_term, attribute_index, reference_index=None, cfg=None, verbose=True, precomputed_embedding=None)
Run the 4-step SNOMED CT attribute extraction pipeline.
Steps
- Retrieve reference examples (pgvector or in-memory).
- LLM infers applicable attributes.
- Retrieve SNOMED candidate values per attribute.
- LLM selects exact SNOMED concepts from candidates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
medical_term
|
str
|
The clinical term to decompose. |
required |
attribute_index
|
AttributeIndex
|
Attribute searcher (pgvector or legacy dict). |
required |
reference_index
|
ReferenceIndex | None
|
Reference searcher (pgvector, legacy dict, or None). |
None
|
cfg
|
HierarchySettings | None
|
Pipeline configuration. |
None
|
verbose
|
bool
|
Whether to log progress. |
True
|
precomputed_embedding
|
Optional |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
Dict with keys |
dict
|
|
Source code in src/ariadne/hierarchy/pipeline.py
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 | |
find_similar_reference_terms(query, reference_index, top_k, precomputed_embedding=None)
Find similar reference terms for few-shot examples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Medical term to search for. |
required |
reference_index
|
ReferenceIndex
|
Reference searcher (pgvector or legacy wrapper). |
required |
top_k
|
int
|
Number of reference examples (from |
required |
precomputed_embedding
|
Optional |
None
|
Returns:
| Type | Description |
|---|---|
ReferenceSearchResult
|
ReferenceSearchResult(examples, cost). |
Source code in src/ariadne/hierarchy/pipeline.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
format_reference_examples(similar_terms)
Format reference examples into a human-readable block for the prompt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
similar_terms
|
list[dict]
|
List of reference dicts from |
required |
Returns:
| Type | Description |
|---|---|
str
|
Formatted string, or empty string if no terms. |
Source code in src/ariadne/hierarchy/pipeline.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
parse_json_response(response)
Parse a JSON response from an LLM, stripping markdown fences if present.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
str
|
Raw LLM response string. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Parsed dict. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the response cannot be parsed as JSON. |
Source code in src/ariadne/hierarchy/pipeline.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |