SemanticChunkerConfig#
- class scikitplot.corpus.SemanticChunkerConfig(backend=SemanticBackend.HYBRID, model_name='paraphrase-multilingual-mpnet-base-v2', model_version=None, similarity_threshold=0.85, max_chunk_tokens=None, min_chunk_tokens=1, include_offsets=True, adapter_unit='word', multilang_config=None, device='cpu', allow_fallback=True)[source]#
Configuration for
SemanticChunker.- Parameters:
- backendSemanticBackend
Chunking backend. Default
SemanticBackend.HYBRID.- model_namestr
Sentence-transformers model name used for EMBEDDING / HYBRID backends. Default
"paraphrase-multilingual-mpnet-base-v2"(supports 50+ languages, 768-dim).- model_versionstr or None
Model version tag for
script_model_versionprovenance field. DefaultNone(auto-populated from installed package version when available).- similarity_thresholdfloat
Cosine similarity threshold for EMBEDDING / HYBRID boundary merging. Adjacent chunks with similarity >= this value are merged. Range
[0.0, 1.0]. Default0.85.- max_chunk_tokensint or None
Hard upper bound on tokens per semantic chunk. Chunks exceeding this are forcibly split by the Layer 2 adapter. Default
None(no limit).- min_chunk_tokensint
Minimum token count. Chunks below this are merged into the adjacent larger chunk. Default
1.- include_offsetsbool
Compute and store character offsets. Default
True.- adapter_unitstr
Layer 2 segmentation granularity:
"word","sentence","grapheme_cluster". Default"word".- multilang_configMultilangConfig or None
Multilang feature flags for the mixin. Default
None→MultilangConfig(include_semantemes=True).- devicestr
Torch device for embeddings:
"cpu","cuda","mps". Default"cpu".- allow_fallbackbool
When
sentence-transformersis unavailable, the model fails to load, or the model fails while refining boundaries, EMBEDDING and HYBRID fall back to MORPHOLOGICAL (True, default) or raise (False):ImportErrorfor the missing package,RuntimeError(chained from the cause) for a load failure, the model’s own exception for an encode failure. Either way the result reports what actually ran:metadata["backend"]is the effective backend,metadata["requested_backend"]the configured one, andmetadata["fallback_reason"]why they differ ("sentence_transformers_unavailable","model_load_failed"or"embedding_failed").
- Parameters:
Notes
Developer note:
model_nameandmodel_versionare recorded only when the model was called for the text: in the result metadata (model_name,model_version, andmodel_invoked) and in each chunk’smetadata["multilang"](model_name,script_model_version="name@version"or"name").script_model_versionis the idempotency verification field – setmodel_versionwhen running EMBEDDING or HYBRID to detect model-version drift across pipeline re-runs. A MORPHOLOGICAL run, requested or fallen back to, calls no model, and neither does a text with a single unit (nothing to refine: the requested backend is reported,model_invokedisFalse). A model you declare yourself inmultilang_config.embedding_model_nameis recorded on every chunk as declared, as in every chunker with multilang metadata; when the semantic model is called, its name replaces the declared one.- backend: SemanticBackend = 'hybrid'[source]#