ontocast.tool¶
Tool package for OntoCast.
The Qdrant and LanceDB vector managers are re-exported lazily. Naming them in a
plain from .vector_store import ... would defeat that subpackage's own lazy
export, because a from-import resolves every name in its list immediately.
AtomicToolBox
¶
Small tool surface used by atomic render/critic paths.
Configuration arrives as config sections, never as unpacked scalars. An
earlier signature accepted both a :class:WebSearchConfig and seventeen
flat web_search_* parameters mirroring its fields, chosen between by an
if/else; production passed the section and only tests took the flat
branch, so the tested configuration path was not the one that shipped. Each
default also existed three times -- here, in settings.py, and inline at
the read sites. Now settings.py is the single source.
Source code in ontocast/tool/atomic.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
__init__(llm_provider, search_provider=None, web_search_config=None, facts_validation_config=None, citation_vocabulary=None)
¶
Build the atomic tool surface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
llm_provider
|
AtomicLLMProvider
|
Supplies budget-aware LLM tools. |
required |
search_provider
|
AtomicSearchProvider | None
|
Optional web-search backend. Without one, search returns no hits regardless of configuration. |
None
|
web_search_config
|
WebSearchConfig | None
|
Web-grounding settings. Defaults to
:class: |
None
|
facts_validation_config
|
FactsValidationConfig | None
|
Facts-gate settings consumed by the render
and repair paths. Defaults to :class: |
None
|
citation_vocabulary
|
dict[str, str] | None
|
Bibliographic terms for citation-metadata units. Configuration rather than retrieval: a reference list is not domain content, so its vocabulary never reaches the catalog. |
None
|
Source code in ontocast/tool/atomic.py
get_llm_tool(budget_tracker)
async
¶
search(query, max_results=None)
async
¶
Run optional web search and return normalized hits.
Source code in ontocast/tool/atomic.py
web_grounding_enabled_for_node(node)
¶
Return whether web grounding is enabled for a workflow node.
Source code in ontocast/tool/atomic.py
ChunkerTool
¶
Bases: Tool
Tool for semantic chunking of documents.
Falls back to naive chunking if sentence-transformers is not available. Includes caching to avoid re-chunking the same text with the same parameters.
Source code in ontocast/tool/chunk/chunker.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 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 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | |
__call__(doc)
¶
Chunk a document into semantic segments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc
|
str
|
The document text to chunk. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of text chunks. |
Source code in ontocast/tool/chunk/chunker.py
__init__(chunk_config=None, cache=None, **kwargs)
¶
Initialize the ChunkerTool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunk_config
|
ChunkConfig | None
|
Chunking configuration. If None, uses default ChunkConfig. |
None
|
cache
|
Cacher | None
|
Optional shared Cacher instance. If None, creates a new one. |
None
|
**kwargs
|
Additional keyword arguments passed to the parent class. |
{}
|
Source code in ontocast/tool/chunk/chunker.py
embed_texts(texts)
¶
Embed short texts with the chunker's model, or None if unavailable.
Exposed so document-type detection can reuse the model already loaded
for semantic chunking instead of constructing a second one. Returns
None -- rather than raising -- when the semantic extras are absent,
so callers degrade to their deterministic tiers exactly as chunking
itself degrades to naive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
texts
|
list[str]
|
Short strings to embed (headings or sampled paragraphs). |
required |
Returns:
| Type | Description |
|---|---|
list[list[float]] | None
|
One embedding per input, or |
Source code in ontocast/tool/chunk/chunker.py
embeddings()
¶
Embeddings over the process-shared encoder, or None if unavailable.
The encoder is shared with retrieval and entity clustering when their model names match, so this loads no weights of its own in that case, and its inference is serialised against theirs.
Source code in ontocast/tool/chunk/chunker.py
naive_split(doc)
¶
Split text by paragraph/sentence boundaries up to max_size.
Unlike :meth:_naive_chunk, does not enforce min_size filtering.
Source code in ontocast/tool/chunk/chunker.py
size_text(doc)
¶
Split doc to respect min_size / max_size using naive boundaries.
ConverterTool
¶
Bases: Tool
Tool for converting documents to native DoclingDocument format.
This class provides functionality for converting various document formats into DoclingDocument objects that can be processed by the OntoCast system. It includes caching to avoid re-converting the same documents.
Attributes:
| Name | Type | Description |
|---|---|---|
supported_extensions |
set[str]
|
Set of supported file extensions. |
cache |
Any
|
Cacher instance for caching conversion results. |
Source code in ontocast/tool/converter.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 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 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | |
__call__(file_input)
¶
Convert a document to a DoclingDocument.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_input
|
bytes | str | Path
|
The input file as either bytes, string, or pathlib.Path. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
DoclingDocument |
DoclingDocument
|
The converted document. |
Source code in ontocast/tool/converter.py
205 206 207 208 209 210 211 212 213 214 215 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 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | |
__init__(cache=None, converter_config=None, **kwargs)
¶
Initialize the converter tool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cache
|
Cacher | None
|
Optional shared Cacher instance. If None, creates a new one. |
None
|
**kwargs
|
Additional keyword arguments passed to the parent class. |
{}
|
Source code in ontocast/tool/converter.py
ensure_converter()
¶
Return the Docling converter, building it once on first use.
Exposed so a server can warm the models at startup instead of making the first request pay for loading the layout, OCR and table-structure models.
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The shared docling |
Any
|
docling is an optional dependency resolved lazily. |
Source code in ontocast/tool/converter.py
EmbeddingBasedAggregator
¶
Main aggregator using embedding-based entity disambiguation.
Pipeline stages: 1. Entity normalisation (with semantic context) 2. Parallel embedding 3. Similarity-based clustering 4. Representative selection (prefer ontology, then simplicity) 5. URI normalisation (PascalCase/camelCase under DEFAULT_IRI) 6. Graph rewriting
ContentUnit types are handled as follows:
- facts: entities under base_iri are normalised.
- ontology: all other entities are considered ontology entities and preserved.
Source code in ontocast/tool/agg/aggregate.py
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 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 | |
__init__(config=None, *, add_sameas_links=True, base_iri=DEFAULT_IRI, candidate_similarity_threshold=None)
¶
Initialise the embedding-based aggregator.
Every tunable lives on :class:AggregationConfig, so settings.py
stays the single source of their defaults rather than restating them in
this signature and again at the call site.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
AggregationConfig | None
|
Aggregation tunables. Defaults to :class: |
None
|
add_sameas_links
|
bool
|
Whether to add |
True
|
base_iri
|
str
|
Base IRI for fact entity URIs. Entities under this namespace are facts; everything else is treated as an ontology entity and left unchanged. |
DEFAULT_IRI
|
candidate_similarity_threshold
|
float | None
|
Overrides the configured permissive candidate threshold. The entity aligner pins it to its own similarity threshold rather than the pipeline's. |
None
|
Source code in ontocast/tool/agg/aggregate.py
aggregate_graphs(units, ontology_graph, merge_vetoes=None)
¶
Aggregate multiple content unit graphs with embedding-based disambiguation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
units
|
list[ContentUnit]
|
List of ContentUnits to aggregate. |
required |
ontology_graph
|
RDFGraph
|
Selected ontology graph used to distinguish known ontology entities from tentative ontology-like aliases. |
required |
merge_vetoes
|
set[frozenset[URIRef]] | None
|
Extra entity pairs that must never identity-merge — the targeted un-merge lever used by the post-aggregation validation gate. Unioned into the direct-relation veto set. |
None
|
Returns:
| Type | Description |
|---|---|
AggregationResult
|
|
AggregationResult
|
bookkeeping (decisions, merged clusters, rejection count). |
Source code in ontocast/tool/agg/aggregate.py
1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 | |
postprocess_facts_units(units, ontology_graph, *, doc_iri=None, document_metadata=None, doc_namespace=None, merge_vetoes=None)
¶
Sanitize facts units, then run aggregation/normalization.
This method is intentionally safe for both single-unit and multi-unit inputs so unit-pipeline and graph-pipeline paths share the same post-processing behavior.
When doc_iri and non-empty document_metadata are provided,
caller-asserted document identity triples are attached to the merged
facts graph. Business-oriented keys mint typed entities under
doc_namespace (defaults to the document facts namespace).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
units
|
list[ContentUnit]
|
Facts content units to aggregate. |
required |
ontology_graph
|
RDFGraph
|
Merged ontology context for classification/guards. |
required |
doc_iri
|
URIRef | None
|
Document IRI for metadata provenance attachment. |
None
|
document_metadata
|
dict[str, Any] | None
|
Caller-asserted document identity metadata. |
None
|
doc_namespace
|
str | None
|
Namespace for metadata-minted entities. |
None
|
merge_vetoes
|
set[frozenset[URIRef]] | None
|
Entity pairs that must never identity-merge (validation-gate un-merge lever). |
None
|
Returns:
| Type | Description |
|---|---|
AggregationResult
|
|
AggregationResult
|
plus any document-metadata provenance. |
Source code in ontocast/tool/agg/aggregate.py
EmbeddingTool
¶
Bases: Tool
Base embedding tool with provider-specific implementations.
Source code in ontocast/tool/vector_store/embedding.py
create(config)
classmethod
¶
Factory for provider-specific embedding tools.
Source code in ontocast/tool/vector_store/embedding.py
embed(texts)
¶
Return vectors for all given texts as documents.
Serialisation, where it is needed, belongs to whatever owns the model — the shared encoder for local checkpoints, nothing for remote providers.
Source code in ontocast/tool/vector_store/embedding.py
embed_one(text)
¶
Return a vector for one query text.
Source code in ontocast/tool/vector_store/embedding.py
embed_query(texts)
¶
Return vectors for all given texts as queries.
Asymmetric retrieval models are trained with distinct query and document
instructions and lose accuracy when both sides are encoded identically. With
empty prefixes — the default, suiting a symmetric paraphrase model — this is
exactly :meth:embed.
Source code in ontocast/tool/vector_store/embedding.py
FusekiTripleStoreManager
¶
Bases: TripleStoreManagerWithAuth
Fuseki-based triple store manager.
This class provides a concrete implementation of triple store management using Apache Fuseki. It stores ontologies as named graphs using their URIs as graph names, and supports dataset creation and cleanup.
URI shape: uri must be the Fuseki HTTP server root (e.g.
http://localhost:3032), not a dataset path or UI URL. Dataset names are
dataset / ontologies_dataset; the client calls
{uri}/{dataset_name}/sparql and similar. The UI route
/#/dataset/dataset_name is only for the browser; paste the origin (and
optional non-dataset path prefix) into FUSEKI_URI, and set
FUSEKI_DATASET to dataset_name.
The manager uses Fuseki's REST API for all operations, including: - Dataset creation and management - Named graph operations for ontologies - SPARQL queries for ontology discovery - Graph-level data operations
Attributes:
| Name | Type | Description |
|---|---|---|
dataset |
str | None
|
Facts dataset name (first path segment in Fuseki HTTP API). |
ontologies_dataset |
str
|
Ontologies dataset name. |
Source code in ontocast/tool/triple_manager/fuseki.py
70 71 72 73 74 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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 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 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 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 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 | |
__init__(uri=None, auth=None, dataset=None, ontologies_dataset=None, **kwargs)
¶
Initialize the Fuseki triple store manager.
This method sets up the connection to Fuseki and creates the dataset if it doesn't exist. The dataset is NOT cleaned on initialization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
Fuseki HTTP service root (e.g. |
None
|
|
auth
|
Authentication tuple (username, password) or string in "user/password" format. |
None
|
|
dataset
|
Facts dataset name (Fuseki API path segment). |
None
|
|
ontologies_dataset
|
Ontologies dataset name (separate Fuseki dataset). |
None
|
|
**kwargs
|
Additional keyword arguments passed to the parent class. |
{}
|
Example
manager = FusekiTripleStoreManager( ... uri="http://localhost:3030", ... dataset="acme--demo--facts", ... ontologies_dataset="acme--demo--ontologies", ... ) await manager.clean()
Source code in ontocast/tool/triple_manager/fuseki.py
aconstruct(query, *, use_ontologies_dataset=True)
async
¶
Run a SPARQL CONSTRUCT against the active dataset, parsing Turtle back.
Tenancy is implicit, as for :meth:aselect.
Source code in ontocast/tool/triple_manager/fuseki.py
afetch_ontologies()
async
¶
Async version of fetch_ontologies.
This is the preferred method when running in an async context.
afetch_ontologies_by_iri(iris)
async
¶
Fetch only the named graphs backing iris, skipping the rest.
Source code in ontocast/tool/triple_manager/fuseki.py
afetch_ontology_catalog()
async
¶
Read one header per stored ontology version via a single SELECT.
aselect(query, *, use_ontologies_dataset=True)
async
¶
Run a SPARQL SELECT against the active dataset.
Tenancy is implicit: :meth:update_tenancy rewrites the dataset names this
resolves through.
Source code in ontocast/tool/triple_manager/fuseki.py
aserialize(o, **kwargs)
async
¶
Async version of serialize.
This is the preferred method when running in an async context.
aserialize_graph(graph, **kwargs)
async
¶
Async version of serialize_graph.
This is the preferred method when running in an async context.
Source code in ontocast/tool/triple_manager/fuseki.py
async_init()
async
¶
Initialize configured Fuseki datasets explicitly.
Constructors stay side-effect free so callers can resolve tenancy first and then create datasets for the final dataset names.
Source code in ontocast/tool/triple_manager/fuseki.py
catalog_io_stats()
¶
Counters for catalog I/O, for tests and diagnostics.
Source code in ontocast/tool/triple_manager/fuseki.py
clean()
async
¶
Clear the configured facts dataset and ontologies dataset (when distinct).
Source code in ontocast/tool/triple_manager/fuseki.py
clean_tenancy(tenant, project, *, sep=TENANCY_SEP)
async
¶
Flush facts and ontologies datasets for tenant / project (by derived names).
Source code in ontocast/tool/triple_manager/fuseki.py
close()
async
¶
drop_all_ontology_graphs_for_iri(ontology_iri)
async
¶
Remove named graphs for ontology_iri (base and iri#... versioned).
Source code in ontocast/tool/triple_manager/fuseki.py
drop_named_graph(graph_uri, *, use_ontologies_dataset=True)
async
¶
Drop a single named graph in the ontologies or main dataset.
Source code in ontocast/tool/triple_manager/fuseki.py
fetch_ontologies()
¶
Synchronous wrapper for fetch_ontologies.
For async usage, use afetch_ontologies() instead.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If called from inside a running event loop; await
:meth: |
Source code in ontocast/tool/triple_manager/fuseki.py
init_dataset(dataset_name)
async
¶
Initialize a Fuseki dataset.
This method creates a new dataset in Fuseki if it doesn't already exist. It uses Fuseki's admin API to create the dataset with TDB2 storage.
Uses a temporary client to avoid event loop cleanup issues when called from different async contexts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
Name of the dataset to create. |
required |
Note
This method will not fail if the dataset already exists.
Source code in ontocast/tool/triple_manager/fuseki.py
last_catalog_was_complete()
¶
False when the last full catalog fetch could not materialize every graph.
serialize(o, **kwargs)
¶
Synchronous wrapper for serialize.
For async usage, use aserialize() instead.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If called from inside a running event loop; await
:meth: |
Source code in ontocast/tool/triple_manager/fuseki.py
serialize_graph(graph, **kwargs)
¶
Synchronous wrapper for serialize_graph.
For async usage, use aserialize_graph() instead.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If called from inside a running event loop; await
:meth: |
Source code in ontocast/tool/triple_manager/fuseki.py
update_tenancy(tenant, project, *, sep=TENANCY_SEP)
async
¶
Switch facts and ontologies Fuseki datasets for tenant / project.
Source code in ontocast/tool/triple_manager/fuseki.py
InMemoryTripleStoreManager
¶
Bases: TripleStoreManager
pyoxigraph-backed in-memory triple store with tenant/project partitions.
Source code in ontocast/tool/triple_manager/in_memory.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 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 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | |
aconstruct(query, *, use_ontologies_dataset=True)
async
¶
Evaluate a SPARQL CONSTRUCT against the active partition.
Source code in ontocast/tool/triple_manager/in_memory.py
afetch_ontologies_by_iri(iris)
async
¶
Materialize only the named graphs backing iris.
Source code in ontocast/tool/triple_manager/in_memory.py
afetch_ontology_catalog()
async
¶
Read one header per stored ontology version via a single SELECT.
aselect(query, *, use_ontologies_dataset=True)
async
¶
Evaluate a SPARQL SELECT against the active partition.
Source code in ontocast/tool/triple_manager/in_memory.py
catalog_io_stats()
¶
Counters for catalog I/O, for tests and diagnostics.
Source code in ontocast/tool/triple_manager/in_memory.py
LLMTool
¶
Bases: Tool
Tool for interacting with language models.
This class provides a unified interface for working with different language model providers (OpenAI, Ollama, Anthropic, Google) through LangChain. It supports both synchronous and asynchronous operations.
Attributes:
| Name | Type | Description |
|---|---|---|
config |
LLMConfig
|
LLMConfig object containing all LLM settings. |
cache |
Any
|
Cacher instance for caching LLM responses. |
Source code in ontocast/tool/llm.py
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 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 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 | |
llm
property
¶
Get the underlying language model instance.
Returns:
| Name | Type | Description |
|---|---|---|
BaseChatModel |
BaseChatModel
|
The configured language model. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the LLM has not been properly initialized. |
__call__(*args, **kwds)
async
¶
__init__(cache=None, budget_tracker=None, **kwargs)
¶
Initialize the LLM tool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cache
|
Cacher | None
|
Optional shared Cacher instance. If None, creates a new one. |
None
|
budget_tracker
|
Any
|
Optional budget tracker instance for usage statistics. |
None
|
**kwargs
|
Additional keyword arguments passed to the parent class. |
{}
|
Source code in ontocast/tool/llm.py
acall(*args, **kwds)
async
¶
acreate(config, cache=None, budget_tracker=None, **kwargs)
async
classmethod
¶
Create a new LLM tool instance asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
LLMConfig
|
LLMConfig object containing LLM settings. |
required |
cache
|
Cacher | None
|
Optional shared Cacher instance. |
None
|
budget_tracker
|
Any
|
Optional budget tracker instance for usage statistics. |
None
|
**kwargs
|
Additional keyword arguments for initialization. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
LLMTool |
A new instance of the LLM tool. |
Source code in ontocast/tool/llm.py
aget_cache_stats()
async
¶
Async :meth:get_cache_stats, with the directory walk off the loop.
Source code in ontocast/tool/llm.py
complete(prompt, **kwargs)
async
¶
Generate a completion for the given prompt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
str
|
The prompt to complete. |
required |
**kwargs
|
Forwarded to the provider and folded into the cache key. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The response text, normalised from provider content blocks. |
Source code in ontocast/tool/llm.py
create(config, cache=None, budget_tracker=None, **kwargs)
classmethod
¶
Create a new LLM tool instance synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
LLMConfig
|
LLMConfig object containing LLM settings. |
required |
cache
|
Cacher | None
|
Optional shared Cacher instance. |
None
|
budget_tracker
|
Any
|
Optional budget tracker instance for usage statistics. |
None
|
**kwargs
|
Additional keyword arguments for initialization. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
LLMTool |
A new instance of the LLM tool. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If called from inside a running event loop; use
:meth: |
Source code in ontocast/tool/llm.py
extract(prompt, output_schema, **kwargs)
async
¶
Extract structured data from the prompt according to a schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
str
|
The prompt describing what to extract. |
required |
output_schema
|
Type[T]
|
Pydantic model the response is parsed into. |
required |
**kwargs
|
Forwarded to the provider and folded into the cache key. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
T |
T
|
The parsed model instance. |
Source code in ontocast/tool/llm.py
get_cache_stats(include_disk=True)
¶
Return in-memory hit/miss counters and, optionally, on-disk file stats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include_disk
|
bool
|
Whether to walk the cache directory. The walk stats
every file, so callers on a hot path (or on an event loop)
should pass False or use :meth: |
True
|
Source code in ontocast/tool/llm.py
record_span(name, seconds)
¶
Charge a latency span to this call's budget tracker.
Uses the same context-local tracker as usage accounting, so per-unit
attribution under asyncio.gather is correct for free, and falls back
to this tool's own tracker for direct library use. Callers without an
:class:LLMTool instance should use :func:record_active_span.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Duration key, e.g. |
required |
seconds
|
float
|
Elapsed seconds to accumulate. |
required |
Source code in ontocast/tool/llm.py
setup()
async
¶
Set up the language model based on the configured provider.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the provider is not supported. |
Source code in ontocast/tool/llm.py
OntologyManager
¶
Bases: Tool
Manager for handling multiple ontologies with version tracking.
This class provides functionality for managing a collection of ontologies, tracking version lineage using hash-based identifiers. For each IRI, it maintains a tree/graph of all versions identified by their hashes.
Attributes:
| Name | Type | Description |
|---|---|---|
ontology_versions |
dict[str, list[Ontology]]
|
Dictionary mapping IRI to list of all ontology versions (identified by hash). Each IRI can have multiple versions forming a lineage tree. |
Source code in ontocast/tool/ontology_manager.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 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 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 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 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 | |
has_ontologies
property
¶
Check if there are any ontologies available.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if there are any ontologies, False otherwise. |
ontologies
property
¶
Return the freshest terminal ontology for each catalog IRI.
The result is cached per IRI (as hashes) and updated incrementally when ontologies are added.
Returns:
| Type | Description |
|---|---|
list[Ontology]
|
list[Ontology]: List of freshest terminal ontologies, one per IRI. |
preferred_namespace_prefixes
property
¶
Namespace URI → author prefix for sanitize preference.
__contains__(item)
¶
Check if an item (IRI or alias) is in the ontology manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
The IRI, ontology_id, or author prefix to check. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
True if the item resolves to a tracked ontology IRI. |
Source code in ontocast/tool/ontology_manager.py
__init__(**kwargs)
¶
Initialize the ontology manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Additional keyword arguments passed to the parent class. |
{}
|
Source code in ontocast/tool/ontology_manager.py
aadd_ontology(ontology, *, skip_vector_index=False)
async
¶
Async variant of :meth:add_ontology (reindex off the event loop).
Source code in ontocast/tool/ontology_manager.py
add_ontology(ontology, *, skip_vector_index=False)
¶
Add an ontology to the version tree for its IRI.
If an ontology with the same hash already exists, it is not added again. Ensures that created_at is set if not already present.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ontology
|
Ontology
|
The ontology to add. |
required |
skip_vector_index
|
bool
|
If True, do not call the vector store (caller already materialized embeddings, e.g. during ToolBox.initialize). |
False
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If vector reindex would run while an event loop is
already active. Use :meth: |
Source code in ontocast/tool/ontology_manager.py
aget_catalog_headers()
async
¶
Read ontology header metadata for every stored version.
Deliberately not cached. Headers are what terminal-version selection runs on, so caching them would let this process miss another worker's writes to a shared store -- the one thing the graph cache cannot go wrong about, and the one thing this would.
Returns:
| Type | Description |
|---|---|
list[OntologyHeader]
|
list[OntologyHeader]: One header per stored ontology version. |
Source code in ontocast/tool/ontology_manager.py
aget_merged_graph(ontologies)
async
¶
Return the prefix-bound union of ontologies, cached by version set.
The induced-subgraph builder reads this union without mutating it, so one merge can be shared by every content unit that selects the same ontology versions -- which is the common case inside a document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ontologies
|
Sequence[Ontology]
|
Ontology versions to merge. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
RDFGraph
|
|
dict[str, str]
|
by callers**; it is shared. |
Source code in ontocast/tool/ontology_manager.py
aget_ontologies_by_iri(iris)
async
¶
Return terminal ontologies for iris, fetching only cache misses.
Terminal selection always runs against freshly read headers; only the
graph bytes come from cache, keyed by the content-addressed
versioned_iri.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iris
|
Sequence[str]
|
Ontology IRIs to resolve. Empty means "no restriction", matching
:meth: |
required |
Returns:
| Type | Description |
|---|---|
list[Ontology]
|
list[Ontology]: Terminal ontologies with graphs. Callers must treat |
list[Ontology]
|
these as shared read-only references. |
Source code in ontocast/tool/ontology_manager.py
aget_patch_context(query, top_k=None, subgraph_depth=None, max_total_triples=None, estimated_triples_per_query=None)
async
¶
Async variant of :meth:get_patch_context.
Source code in ontocast/tool/ontology_manager.py
aget_patch_context_with_sources(query, top_k=None, subgraph_depth=None, max_total_triples=None, estimated_triples_per_query=None)
async
¶
Async variant of :meth:get_patch_context_with_sources.
Source code in ontocast/tool/ontology_manager.py
aget_patch_contexts_with_sources(queries, top_k=None, subgraph_depth=None, max_total_triples=None, estimated_triples_per_query=None)
async
¶
Async patch retrieval (vector + induced subgraph) for many queries.
With a patch retriever, returns a one-element list: a single induced graph for
the union of hits over queries, plus contributing ontology IRIs.
Source code in ontocast/tool/ontology_manager.py
author_prefix_for_namespace(namespace)
¶
Return the catalog-registered author prefix for a namespace, if any.
Source code in ontocast/tool/ontology_manager.py
catalog_cache_stats()
¶
Cache hit/miss counters, for tests and retrieval diagnostics.
Source code in ontocast/tool/ontology_manager.py
get_freshest_terminal_ontology(ontology_id=None)
¶
Get the freshest terminal ontology by ontology_id, alias, or IRI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ontology_id
|
str | None
|
Optional ontology_id / alias / IRI to filter by. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Ontology |
Ontology | None
|
The freshest terminal ontology, or None if no terminal ontologies exist. |
Source code in ontocast/tool/ontology_manager.py
get_freshest_terminal_ontology_by_iri(iri=None)
¶
Get the freshest terminal ontology based on created_at timestamp.
Returns the terminal ontology with the most recent created_at timestamp.
If multiple terminal ontologies exist, returns the one that was most recently
created. If no created_at is set, falls back to the first terminal ontology.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iri
|
str | None
|
Optional IRI to filter by. If None, searches across all ontologies. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Ontology |
Ontology | None
|
The freshest terminal ontology, or None if no terminal ontologies exist. |
Source code in ontocast/tool/ontology_manager.py
get_lineage_graph(ontology_id)
¶
Get the lineage graph for a specific ontology_id, alias, or IRI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ontology_id
|
str
|
The ontology_id / alias / IRI to get the lineage graph for. |
required |
Returns:
| Type | Description |
|---|---|
|
networkx.DiGraph: The lineage graph for the ontology, or None if not found. |
Source code in ontocast/tool/ontology_manager.py
get_lineage_graph_by_iri(iri)
¶
Get the lineage graph for a specific IRI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iri
|
str
|
The IRI to get the lineage graph for. |
required |
Returns:
| Type | Description |
|---|---|
|
networkx.DiGraph: The lineage graph for the ontology, or None if not found. |
Source code in ontocast/tool/ontology_manager.py
get_ontology(ontology_id=None, ontology_iri=None, hash=None)
¶
Get an ontology by its IRI, ontology_id/alias, or hash.
If hash is provided, returns the specific version. Otherwise, returns a terminal (most recent) version if multiple versions exist. IRI is preferred over ontology_id for lookup.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ontology_id
|
str | None
|
Short name, author prefix, or IRI (optional). |
None
|
ontology_iri
|
str | None
|
The IRI of the ontology to retrieve (preferred). |
None
|
hash
|
str | None
|
The hash of a specific version to retrieve (optional). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Ontology |
Ontology
|
The matching ontology if found, NULL_ONTOLOGY otherwise. |
Source code in ontocast/tool/ontology_manager.py
get_ontology_iris()
¶
Get a list of all ontology IRIs.
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: List of ontology IRIs. |
get_ontology_names()
¶
Return unique catalog ontology_id values currently tracked.
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: Sorted unique ontology short names. |
Source code in ontocast/tool/ontology_manager.py
get_ontology_versions(ontology_id)
¶
Get all versions of an ontology by ontology_id, alias, or IRI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ontology_id
|
str
|
The ontology_id / alias / IRI to retrieve versions for. |
required |
Returns:
| Type | Description |
|---|---|
list[Ontology]
|
list[Ontology]: List of all versions of the ontology. |
Source code in ontocast/tool/ontology_manager.py
get_ontology_versions_by_iri(iri)
¶
Get all versions of an ontology by IRI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iri
|
str
|
The IRI to retrieve versions for. |
required |
Returns:
| Type | Description |
|---|---|
list[Ontology]
|
list[Ontology]: List of all versions of the ontology. |
Source code in ontocast/tool/ontology_manager.py
get_patch_context(query, top_k=None, subgraph_depth=None, max_total_triples=None, estimated_triples_per_query=None)
¶
Retrieve multi-ontology patch context for a query.
Falls back to the freshest available ontology graph if vector retrieval is not configured or yields no atoms.
Source code in ontocast/tool/ontology_manager.py
get_patch_context_with_sources(query, top_k=None, subgraph_depth=None, max_total_triples=None, estimated_triples_per_query=None)
¶
Retrieve patch context and contributing ontology IRIs.
Source code in ontocast/tool/ontology_manager.py
get_patch_contexts_with_sources(queries, top_k=None, subgraph_depth=None, max_total_triples=None, estimated_triples_per_query=None)
¶
Retrieve patch contexts for many queries in a batched pass.
With a patch retriever, the list has length 1 (ensemble graph + sources).
Without it, length matches queries (fallback ontology per query).
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If called while an event loop is running. Use
:meth: |
Source code in ontocast/tool/ontology_manager.py
get_terminal_ontologies(ontology_id=None)
¶
Get terminal (leaf) ontologies by ontology_id or alias.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ontology_id
|
str | None
|
Optional ontology_id / alias / IRI to filter by. |
None
|
Returns:
| Type | Description |
|---|---|
list[Ontology]
|
list[Ontology]: List of terminal ontologies. |
Source code in ontocast/tool/ontology_manager.py
get_terminal_ontologies_by_iri(iri=None)
¶
Get terminal (leaf) ontologies in the version graph.
Terminal ontologies are those that are not parents of any other ontology in the version tree. If iri is provided, returns terminals for that ontology only; otherwise returns terminals for all ontologies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iri
|
str | None
|
Optional IRI to filter by. |
None
|
Returns:
| Type | Description |
|---|---|
list[Ontology]
|
list[Ontology]: List of terminal ontologies. |
Source code in ontocast/tool/ontology_manager.py
register_triple_store(manager)
¶
Register the triple store this catalog reads through on a cache miss.
register_vector_store(retriever)
¶
remove_ontology_by_iri(iri)
¶
Drop all tracked versions for an ontology IRI and clear caches.
Source code in ontocast/tool/ontology_manager.py
reset_catalog()
¶
Drop every tracked ontology, identity binding, and cached graph.
Called when the active tenant/project changes: the catalog, the alias collision ledger, and the graph caches are all partition-scoped, and carrying them across a switch leaks one tenant's ontologies into another's requests.
Source code in ontocast/tool/ontology_manager.py
resolve_ontology_ref(ref)
¶
Resolve an absolute IRI or registered alias to a catalog ontology IRI.
Source code in ontocast/tool/ontology_manager.py
update_ontology(ontology_id, ontology_addendum)
¶
Update an existing ontology with additional triples.
Note: This method is deprecated. Use add_ontology() with a new version that has the current hash in parent_hashes instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ontology_id
|
str
|
The short name of the ontology to update. |
required |
ontology_addendum
|
RDFGraph
|
The RDF graph containing additional triples to add. |
required |
Source code in ontocast/tool/ontology_manager.py
validate_identity_uniqueness(ontology)
¶
Validate catalog IRI and alias uniqueness across the manager.
Same IRI may not change its primary ontology_id. The same
ontology_id alias may not point at two different IRIs. Author
prefix may differ from ontology_id (both register as aliases of
the same IRI); a prefix collision across IRIs does not block ingest —
the colliding prefix alias is simply skipped at registration and the
ontology stays addressable by IRI and ontology_id.
Source code in ontocast/tool/ontology_manager.py
OntologyPatchRetriever
¶
Bases: Tool
Combines vector retrieval into one composite ontology graph.
Source code in ontocast/tool/vector_store/patch_retriever.py
1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 | |
aretrieve(query, top_k=None, expand_sparql=True, subgraph_depth=None, max_total_triples=None, estimated_triples_per_query=None, trigger_text=None)
async
¶
Async single-query variant of :meth:aretrieve_ensemble.
Source code in ontocast/tool/vector_store/patch_retriever.py
aretrieve_ensemble(queries, top_k=None, expand_sparql=True, subgraph_depth=None, max_total_triples=None, estimated_triples_per_query=None, trigger_text=None)
async
¶
Vector search over all queries once, score-filter, dedupe, single subgraph expansion.
subgraph_depth / max_total_triples / estimated_triples_per_query
default to the configured values (ONTOLOGY_PATCH_INDUCED_SUBGRAPH_*).
They previously carried literal defaults of 1 / 300 / 24, which
contradicted the config defaults of 2 / 1200 / 24: the pipeline passed
config explicitly and was unaffected, but any other caller of this
public API silently got a 4x smaller snapshot than the deployment was
configured for.
Source code in ontocast/tool/vector_store/patch_retriever.py
1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 | |
retrieve(query, top_k=None, expand_sparql=True, subgraph_depth=None, max_total_triples=None, estimated_triples_per_query=None)
¶
Retrieve top-k hits for one query and optional induced subgraph; returns source ontology IRIs.
Source code in ontocast/tool/vector_store/patch_retriever.py
retrieve_ensemble(queries, top_k=None, expand_sparql=True, subgraph_depth=None, max_total_triples=None, estimated_triples_per_query=None, trigger_text=None)
¶
Source code in ontocast/tool/vector_store/patch_retriever.py
SearchHit
¶
Tool
¶
Bases: BasePydanticModel
Base class for all OntoCast tools.
This class serves as the foundation for all tools in the OntoCast system. It provides common functionality and interface that all tools must implement. Tools should inherit from this class and implement their specific functionality.
Source code in ontocast/tool/onto.py
__init__(**kwargs)
¶
Initialize the tool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Keyword arguments passed to the parent class. |
{}
|
TripleStoreManager
¶
Bases: Tool
Base class for managing RDF triple stores.
This class defines the interface for triple store management operations, including fetching and storing ontologies and their graphs. All concrete triple store implementations should inherit from this class.
This is an abstract base class that must be implemented by specific triple store backends (e.g., Fuseki, In-Memory).
Source code in ontocast/tool/triple_manager/core.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 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 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | |
__init__(**kwargs)
¶
Initialize the triple store manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Additional keyword arguments passed to the parent class. |
{}
|
aconstruct(query, *, use_ontologies_dataset=True)
async
¶
Run a SPARQL CONSTRUCT against the active partition.
Unlike :meth:aselect, the result carries real RDF terms, so blank nodes
and datatypes survive. Prefix bindings do not -- they are serialization
metadata rather than triples, and must be re-sourced by the caller.
Implementations must raise rather than return an empty graph on failure,
for the same reason :meth:aselect must raise: an empty result is
indistinguishable from "nothing matched".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
A SPARQL CONSTRUCT (or DESCRIBE) query. |
required |
use_ontologies_dataset
|
bool
|
Query the ontologies partition rather than facts. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
RDFGraph |
RDFGraph
|
The constructed triples, without prefix bindings. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the backend has no SPARQL engine. |
Source code in ontocast/tool/triple_manager/core.py
afetch_ontologies()
async
¶
afetch_ontologies_by_iri(iris)
async
¶
Fetch terminal ontologies restricted to iris.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iris
|
Sequence[str]
|
Ontology IRIs to fetch. Empty means "no restriction", matching
how :meth: |
required |
Returns:
| Type | Description |
|---|---|
list[Ontology]
|
list[Ontology]: The requested ontologies, with graphs. |
Source code in ontocast/tool/triple_manager/core.py
afetch_ontology_catalog()
async
¶
Fetch per-named-graph ontology header metadata.
Headers carry the lineage fields terminal-version selection needs without the graphs themselves. The default implementation materializes the catalog and derives headers from it; SPARQL-capable backends should override with a single SELECT.
Note the default returns one header per terminal ontology (whatever
:meth:afetch_ontologies returns), while a native implementation returns
one per stored version. Callers that re-run terminal selection over the
result are correct either way; that is why they should.
Returns:
| Type | Description |
|---|---|
list[OntologyHeader]
|
list[OntologyHeader]: Header metadata for stored ontologies. |
Source code in ontocast/tool/triple_manager/core.py
aselect(query, *, use_ontologies_dataset=True)
async
¶
Run a SPARQL SELECT against the active partition.
Rows map variable name to the term's lexical value only; term kind and
datatype are not preserved, so constrain kinds in the query itself
(FILTER(isIRI(?x))). Unbound variables are absent from the row dict.
Implementations must raise rather than return an empty list on failure -- an empty result set is indistinguishable from "nothing matched", which would silently disable callers that treat no-rows as a valid answer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
A SPARQL SELECT query. |
required |
use_ontologies_dataset
|
bool
|
Query the ontologies partition rather than facts. |
True
|
Returns:
| Type | Description |
|---|---|
list[dict[str, str]]
|
list[dict[str, str]]: One dict per solution. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the backend has no SPARQL engine. |
Source code in ontocast/tool/triple_manager/core.py
aserialize(o, **kwargs)
async
¶
Async serialize helper for backends without native async I/O.
aserialize_graph(graph, **kwargs)
async
¶
Async serialize helper for backends without native async I/O.
async_init()
async
¶
clean()
abstractmethod
async
¶
Clean/flush data managed by this store (backend-specific scope).
Warning: This operation is irreversible and will delete data.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the triple store doesn't support cleaning. |
Source code in ontocast/tool/triple_manager/core.py
clean_tenancy(tenant, project)
async
¶
Remove all triples for datasets derived from tenant / project.
Backends without per-tenant partitions raise :class:NotImplementedError.
Source code in ontocast/tool/triple_manager/core.py
close()
async
¶
Release any connection held by this backend.
Default is a no-op for in-process backends.
drop_all_ontology_graphs_for_iri(ontology_iri)
async
¶
Remove named graphs for ontology_iri (base and versioned).
Source code in ontocast/tool/triple_manager/core.py
drop_named_graph(graph_uri, *, use_ontologies_dataset=True)
async
¶
Drop a single named graph.
Source code in ontocast/tool/triple_manager/core.py
fetch_ontologies()
abstractmethod
¶
Fetch all available ontologies from the triple store.
This method should retrieve all ontologies stored in the triple store and return them as Ontology objects with their associated RDF graphs.
Returns:
| Type | Description |
|---|---|
list[Ontology]
|
list[Ontology]: List of available ontologies with their graphs. |
Source code in ontocast/tool/triple_manager/core.py
last_catalog_was_complete()
¶
True when the most recent full catalog fetch returned every graph.
Consulted before destructive reconciliation (vector-store orphan pruning): a backend that fetched only part of its catalog reports False so callers treat the result as non-authoritative rather than concluding that the missing ontologies were deleted. Backends that cannot fetch partially always report True.
Source code in ontocast/tool/triple_manager/core.py
serialize(o, **kwargs)
abstractmethod
¶
serialize_graph(graph, **kwargs)
abstractmethod
¶
strip_provenance(graph)
classmethod
¶
Return a graph without reification/provenance scaffolding triples.
Source code in ontocast/tool/triple_manager/core.py
supports_sparql_construct()
¶
True when :meth:aconstruct reaches a real SPARQL engine.
Separate from :meth:supports_sparql_select because a backend can answer
row queries without being able to return triples: the Fuseki SELECT path
speaks application/sparql-results+json only.
Source code in ontocast/tool/triple_manager/core.py
supports_sparql_select()
¶
True when :meth:aselect reaches a real SPARQL engine.
Callers branch on this to choose targeted queries over materializing the
whole catalog. Backends returning False still answer every catalog
method correctly, just by fetching more than they need.
Source code in ontocast/tool/triple_manager/core.py
supports_tenancy_partition()
¶
update_tenancy(tenant, project, *, sep=TENANCY_SEP)
async
¶
Switch the active tenant/project partition when supported.
Source code in ontocast/tool/triple_manager/core.py
VectorStoreManager
¶
Bases: Tool
Abstract interface for vector store implementations.
Source code in ontocast/tool/vector_store/core.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 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 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | |
afetch_vectors(atom_ids)
async
¶
Async wrapper around :meth:fetch_vectors.
apply_tenancy(tenant, project, *, sep=TENANCY_SEP)
¶
Switch the active tenant/project partition when supported.
Source code in ontocast/tool/vector_store/core.py
asearch_patch_hits_many(queries, top_k=None, filter_iri=None, filter_version=None, filter_hash=None)
abstractmethod
async
¶
Async variant of :meth:search_patch_hits_many.
Source code in ontocast/tool/vector_store/core.py
clean_tenancy(tenant, project)
async
¶
Drop or empty vector collections derived from tenant / project.
Source code in ontocast/tool/vector_store/core.py
close()
¶
Release any backend connection held by this store.
Default is a no-op: backends that open no long-lived handle (LanceDB connects per call) have nothing to release.
delete_ontology(iri, version=None, ontology_hash=None)
abstractmethod
¶
Delete all indexed atoms for a specific ontology IRI.
fetch_atoms_by_ids(atom_ids)
¶
Batch-fetch atom payloads by atom_id (for lexical-trigger injection).
Source code in ontocast/tool/vector_store/core.py
fetch_vectors(atom_ids)
abstractmethod
¶
index_ontology(ontology)
abstractmethod
¶
initialize()
abstractmethod
async
¶
list_indexed_ontology_iris()
¶
Return distinct ontology_iri values present in the ontology store.
match_lexical_triggers(text, *, max_atoms=None)
¶
Match raw text against the lexical-trigger index and return atoms.
Source code in ontocast/tool/vector_store/core.py
prune_orphan_ontology_iris(keep_iris)
¶
Delete indexed atoms whose ontology_iri is not in keep_iris.
An empty keep_iris is refused rather than treated as "everything is
an orphan". Pruning exists to follow IRI renames, and no rename makes
every ontology disappear at once -- an empty catalog means the source of
truth could not be read, and deleting the whole index on that basis is
unrecoverable. Callers that genuinely want an empty store should call
:meth:wipe_store.
Returns the orphan IRIs that were deleted (sorted); empty when the prune was refused.
Source code in ontocast/tool/vector_store/core.py
reindex_ontology(ontology)
¶
Replace all atoms for a given ontology and return indexed count.
search_patch_hits(query, top_k=None, filter_iri=None, filter_version=None, filter_hash=None)
abstractmethod
¶
Search ontology atoms and return rank-fused scored hit objects.
Source code in ontocast/tool/vector_store/core.py
search_patch_hits_many(queries, top_k=None, filter_iri=None, filter_version=None, filter_hash=None)
abstractmethod
¶
Search ontology atoms for many queries with split-channel outputs.
Source code in ontocast/tool/vector_store/core.py
search_patches(query, top_k=None, filter_iri=None, filter_version=None, filter_hash=None)
abstractmethod
¶
Search ontology patches by query text (top_k None → store default).
Source code in ontocast/tool/vector_store/core.py
supports_tenancy_partition()
¶
wipe_store()
async
¶
Drop the currently configured ontology/facts collections or tables.
Call :meth:initialize afterwards to recreate empty schema.
Source code in ontocast/tool/vector_store/core.py
__getattr__(name)
¶
Resolve the optional-backend managers on first access.