ontocast.tool.chunk.section_llm¶
LLM section-label backfill for chunk preparation.
BatchSectionClassification
¶
Bases: BasePydanticModel
LLM output assigning a section label to each numbered excerpt.
Source code in ontocast/tool/chunk/section_llm.py
ChunkSectionClassification
¶
Bases: BasePydanticModel
LLM output mapping one excerpt to a canonical section label.
Source code in ontocast/tool/chunk/section_llm.py
SectionLabelAssignment
¶
Bases: BasePydanticModel
One excerpt index and the section label assigned to it.
Source code in ontocast/tool/chunk/section_llm.py
classify_section_with_llm(text, tools, schema, *, document_type_hint=None)
async
¶
Classify a text fragment with the section-label LLM prompt.
Source code in ontocast/tool/chunk/section_llm.py
classify_sections_batched(items, tools, schema, *, document_type_hint=None, batch_size=40)
async
¶
Classify many excerpts in as few LLM calls as possible.
One call covers up to batch_size excerpts, versus one call per excerpt
for :func:classify_section_with_llm. Passing the excerpts together also
gives the model the document's shape, which a single fragment cannot show.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
items
|
list[tuple[int, str]]
|
|
required |
tools
|
'ToolBox'
|
ToolBox providing the LLM. |
required |
schema
|
SectionLabelSchema
|
Active section label schema. |
required |
document_type_hint
|
str | None
|
Optional free-text document type. |
None
|
batch_size
|
int
|
Maximum excerpts per LLM call. |
40
|
Returns:
| Type | Description |
|---|---|
dict[int, str | None] | None
|
Mapping of index to label ( |
dict[int, str | None] | None
|
when the model's response could not be used, so the caller can fall |
dict[int, str | None] | None
|
back to per-excerpt classification. |
Source code in ontocast/tool/chunk/section_llm.py
fragment_for_text(text)
¶
Return a short excerpt suitable for LLM section classification.
Source code in ontocast/tool/chunk/section_llm.py
llm_backfill_section_labels(segments, tools, *, section_schema_id=None, document_type_hint=None, section_tag_min_chars=80, batch_size=40, schema=None)
async
¶
Set section_label on segments that are still unlabeled (mutates in place).
Classifies in batches when batch_size is positive, falling back to one
call per segment if the batched response cannot be used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
segments
|
list
|
Prepare segments, mutated in place. |
required |
tools
|
'ToolBox'
|
ToolBox providing the LLM. |
required |
section_schema_id
|
str | None
|
Raw request value; used only when |
None
|
document_type_hint
|
str | None
|
Free-text document type, also passed to the prompt. |
None
|
section_tag_min_chars
|
int
|
Minimum segment length to be worth classifying. |
80
|
batch_size
|
int
|
Excerpts per LLM call; 0 restores one call per segment. |
40
|
schema
|
SectionLabelSchema | None
|
Already-resolved schema. Callers that resolved it themselves must pass it: re-deriving from the raw request would ignore a text-based schema detection, and labels outside the re-derived schema are silently discarded. |
None
|
Source code in ontocast/tool/chunk/section_llm.py
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 | |