ontocast.tool.chunk.prepare¶
Prepare content units: segment, tag, filter, and size within section boundaries.
PrepareOptions
dataclass
¶
Options for the chunk preparation pipeline.
Source code in ontocast/tool/chunk/prepare.py
filter_allowlist_param()
¶
Name of the request option that produced :meth:filter_allowlist.
filter_denylist(schema)
¶
Effective exclusion denylist.
None means "use the resolved schema's default_exclude"; an explicit
[] opts out of exclusion entirely; a non-empty list is used as-is.
Source code in ontocast/tool/chunk/prepare.py
needs_section_prepare()
¶
True when a request option explicitly requires section labels.
Section tagging itself is default-on (see CHUNK_SECTION_CLASSIFIER);
this only reports whether the request carries section-dependent options.
Source code in ontocast/tool/chunk/prepare.py
PreparedChunk
dataclass
¶
A prepared text chunk with optional structural metadata and section label.
section_label_source and section_label_confidence record which tier
of the classification cascade decided the label, so a run can be audited
and weak labels can be told from strong ones.
Source code in ontocast/tool/chunk/prepare.py
SchemaDecision
dataclass
¶
Which label schema a document is prepared against, and why.
Recorded rather than recomputed: schema selection now depends on document
text, and it used to be resolved independently in three places. If those
disagreed, the deterministic tiers would tag against one schema while the
LLM backfill validated against another, and normalise_llm_label drops
labels absent from its schema -- silent label loss, not an error.
Source code in ontocast/tool/chunk/prepare.py
SectionSelectionEmptyError
¶
Bases: ValueError
A section selection matched no segment in this document.
Distinct from a malformed parameter: target_sections=["reslts"] is
syntactically fine and only turns out to be wrong once this document has
been classified. Under the default CHUNK_SECTION_FILTER_ON_EMPTY=warn
this is a log line and the run continues to an empty graph, which reads
exactly like a document that genuinely had nothing to extract -- telling
those two apart is the whole point of the error mode.
Subclasses :class:ValueError so existing parameter guards keep their
shape. Deliberately not an api-layer error: nothing under tool/
imports ontocast.api, and the parameter here is well-formed.
Source code in ontocast/tool/chunk/prepare.py
prepare_content_units(docling_doc, splitter, config, options, tools=None)
async
¶
Segment, tag, filter, and size document text into prepared chunks.
Section tagging is default-on: the sections-first flow runs unless
CHUNK_SECTION_CLASSIFIER=off (which also disables section filters and
schema default exclusions; explicit section options are ignored with a
warning in that case).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
docling_doc
|
DoclingDocument
|
Converted source document. |
required |
splitter
|
ChunkerTool
|
Chunker used to size oversized sections. |
required |
config
|
ChunkConfig
|
Chunk configuration, including the classifier tier. |
required |
options
|
PrepareOptions
|
Per-request section schema and filters. |
required |
tools
|
'ToolBox | None'
|
ToolBox providing the LLM. Required only when
|
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
|
SectionSelectionEmptyError
|
A section allowlist or denylist removed
every segment and |
Source code in ontocast/tool/chunk/prepare.py
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 | |
resolve_prepare_schema(document_text, config, options, splitter=None)
¶
Choose the section-label schema for one document.
Precedence: an explicit section_schema_id, then a document_type_hint
that maps to a schema, then automatic detection, then the manifest default.
Caller-supplied intent is never overridden -- detection only fills the gap
where the request said nothing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
document_text
|
str
|
Markdown export used for heading detection. |
required |
config
|
ChunkConfig
|
Chunk configuration, including the detection tier. |
required |
options
|
PrepareOptions
|
Per-request schema id and document type hint. |
required |
splitter
|
ChunkerTool | None
|
Chunker, used only to reach the embedding model already loaded
for semantic chunking. |
None
|
Returns:
| Type | Description |
|---|---|
SchemaDecision
|
The chosen schema and how it was chosen. |