Skip to content

symfonic.core.learning.entity_extractor_spacy

entity_extractor_spacy

spaCy-backed entity extractor (opt-in via the symfonic-core[entity-linker-spacy] extra).

Lazy import: spacy is only imported when an instance is constructed. If the import fails or the model is missing, the constructor raises RuntimeError with an actionable message. The consolidation phase catches that and falls back to RegexHeuristicExtractor with a single warning (design §13.3).

Design reference: §17.1.3.

SpacyEntityExtractor

SpacyEntityExtractor(*, model_name: str = 'en_core_web_sm')

Decision 4.5 strategy. Uses spaCy en_core_web_sm by default.

Confidence is fixed at 0.7 -- spaCy does not surface a per-entity probability via the ents interface, so we use a heuristic constant (design §13.2). Callers wanting tighter control should switch to the LLM extractor.

Source code in src/symfonic/core/learning/entity_extractor_spacy.py
def __init__(self, *, model_name: str = "en_core_web_sm") -> None:
    try:
        import spacy  # type: ignore[import-not-found]
    except ImportError as exc:
        raise RuntimeError(
            "spacy is not installed. Install with: "
            "pip install symfonic-core[entity-linker-spacy] "
            "+ python -m spacy download en_core_web_sm",
        ) from exc
    try:
        self._nlp = spacy.load(model_name)
    except Exception as exc:
        raise RuntimeError(
            f"spaCy model {model_name!r} not available. Install with: "
            f"python -m spacy download {model_name}",
        ) from exc