Skip to main content
For the complete documentation index for agents and LLMs, see llms.txt.

SpacyNamedEntityExtractor

Extract named entities from documents using spaCy models and store the annotations in each document's metadata.

Key Features

  • Works with any spaCy model that includes an NER component.
  • Adds named entity annotations to the named_entities metadata field on each document.
  • Supports configurable batch size for processing multiple documents.
  • Supports GPU inference on a single device.
  • Disables unnecessary spaCy pipeline components to improve performance.

Configuration

Add Workspace-Level Integration

  1. Click your profile icon and choose Settings.
  2. Go to Workspace>Integrations.
  3. Find the provider you want to connect and click Connect next to them.
  4. Enter the API key and any other required details.
  5. Click Connect. You can use this integration in pipelines and indexes in the current workspace.

Add Organization-Level Integration

  1. Click your profile icon and choose Settings.
  2. Go to Organization>Integrations.
  3. Find the provider you want to connect and click Connect next to them.
  4. Enter the API key and any other required details.
  5. Click Connect. You can use this integration in pipelines and indexes in all workspaces in the current organization.
  1. Drag the SpacyNamedEntityExtractor component onto the canvas from the Component Library.
  2. Click on the component to open the configuration panel.
  3. On the General tab:
    1. Set the model to a spaCy model name or local path (for example, en_core_web_sm).
  4. Go to the Advanced tab to configure pipeline_kwargs and device.
note

Install the spaCy model before running the pipeline. For example, run python -m spacy download en_core_web_sm.

Connections

SpacyNamedEntityExtractor receives a list of documents and outputs the same documents with a named_entities metadata field. Connect it to downstream components that read document metadata, such as MetadataRouter or custom processing components.

Source Code

To check this component's source code, open named_entity_extractor.py in the Haystack Core Integrations repository.

Usage Examples

Basic Configuration

  SpacyNamedEntityExtractor:
type: haystack_integrations.components.extractors.spacy.named_entity_extractor.SpacyNamedEntityExtractor
init_parameters:
model: en_core_web_sm

Using the Component in a Pipeline

# haystack-pipeline
components:
SpacyNamedEntityExtractor:
type: haystack_integrations.components.extractors.spacy.named_entity_extractor.SpacyNamedEntityExtractor
init_parameters:
model: en_core_web_sm

document_writer:
type: haystack.components.writers.document_writer.DocumentWriter
init_parameters:
document_store:
type: haystack.document_stores.in_memory.document_store.InMemoryDocumentStore
init_parameters: {}

connections:
- sender: SpacyNamedEntityExtractor.documents
receiver: document_writer.documents

max_runs_per_component: 100

metadata: {}

Parameters

Inputs

ParameterTypeDescription
documentsList[Document]Documents to annotate with named entities.
batch_sizeintBatch size used for processing the documents.

Outputs

ParameterTypeDescription
documentsList[Document]The input documents with meta["named_entities"] set to a list of entity annotations. Each annotation includes entity, start, end, and optionally score.

Init Parameters

These are the parameters you can configure in Pipeline Builder:

ParameterTypeDefaultDescription
modelstrName of the spaCy model or a path to the model on the local disk.
pipeline_kwargsOptional[Dict[str, Any]]NoneKeyword arguments passed to the spaCy pipeline. The pipeline can override these arguments at run time.
deviceOptional[ComponentDevice]NoneThe device on which the model is loaded. If None, the default device is automatically selected. Only single-device inference is supported.

Run Method Parameters

These are the parameters you can configure for the component's run() method. This means you can pass these parameters at query time through the API, in Playground, or when running a job. For details, see Modify Pipeline Parameters at Query Time.

ParameterTypeDefaultDescription
documentsList[Document]Documents to annotate with named entities.
batch_sizeint1Batch size used for processing the documents.