ontocast.runtime¶
Tenancy-independent tools shared across every :class:~ontocast.toolbox.ToolBox.
A ToolBox is bound to one tenant/project partition: its triple store, ontology catalog and vector store all describe that partition. Serving several tenants therefore means several ToolBoxes.
Most of what a ToolBox holds does not vary by tenant, though, and some of it is
expensive: :class:~ontocast.tool.vector_store.embedding.EmbeddingTool loads
model weights, :class:~ontocast.tool.converter.ConverterTool pulls docling,
and the LLM tool owns a provider client and the response cache. Duplicating
those per tenant would make a sixteen-scope registry sixteen copies of an
embedding model.
:class:ToolBoxRuntime holds exactly that shared half. ToolBox exposes every
one of its members as a property, so tools.llm and tools.converter mean
what they always did.
ToolBoxRuntime
¶
Shared, tenancy-independent tools.
Satisfies :class:~ontocast.tool.atomic.AtomicLLMProvider so it can back
the AtomicToolBox directly rather than routing through a ToolBox, which
would tie the shared half to one scope.
Source code in ontocast/runtime.py
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 | |
__init__(config, *, llm=None, cache=None, prune_cache=True)
¶
Build the shared tools.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
Configuration to read tool settings from. Only tenancy-independent sections are consulted. |
required |
llm
|
LLMTool | None
|
Pre-built LLM tool. Supply one from
:meth: |
None
|
cache
|
Cacher | None
|
Pre-built shared cache. Supply the same instance that
|
None
|
prune_cache
|
bool
|
Bound the cache on construction. :meth: |
True
|
Source code in ontocast/runtime.py
acreate(config)
async
classmethod
¶
Build the shared tools from inside a running event loop.
Source code in ontocast/runtime.py
get_entity_aligner(embedding_model, similarity_threshold)
¶
Return a cached entity aligner for the given embedding settings.
Source code in ontocast/runtime.py
get_llm_tool(budget_tracker)
async
¶
Return the shared LLM tool, charging usage to budget_tracker.
The tracker is bound to the calling task rather than to the shared tool
instance. Assigning it to the instance -- as this did once -- meant that
with PARALLEL_WORKERS unit workers in flight, whichever bound last
collected every concurrent call's usage; document totals still summed
correctly, but per-unit attribution was arbitrary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
budget_tracker
|
The budget tracker to charge for this task's calls. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
LLMTool |
The shared LLM tool. |
Source code in ontocast/runtime.py
sparse_embedding_tool(config)
¶
Shared BM25 sparse encoder for the external vector backends.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
EmbeddingConfig
|
Embedding config; only consulted on first construction, since the encoder is tenancy-independent. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
FastembedBm25SparseTool |
FastembedBm25SparseTool
|
The process-shared sparse encoder. |