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_entitiesmetadata 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
- Click your profile icon and choose Settings.
- Go to Workspace>Integrations.
- Find the provider you want to connect and click Connect next to them.
- Enter the API key and any other required details.
- Click Connect. You can use this integration in pipelines and indexes in the current workspace.
Add Organization-Level Integration
- Click your profile icon and choose Settings.
- Go to Organization>Integrations.
- Find the provider you want to connect and click Connect next to them.
- Enter the API key and any other required details.
- Click Connect. You can use this integration in pipelines and indexes in all workspaces in the current organization.
- Drag the
SpacyNamedEntityExtractorcomponent onto the canvas from the Component Library. - Click on the component to open the configuration panel.
- On the General tab:
- Set the
modelto a spaCy model name or local path (for example,en_core_web_sm).
- Set the
- Go to the Advanced tab to configure
pipeline_kwargsanddevice.
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
| Parameter | Type | Description |
|---|---|---|
documents | List[Document] | Documents to annotate with named entities. |
batch_size | int | Batch size used for processing the documents. |
Outputs
| Parameter | Type | Description |
|---|---|---|
documents | List[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:
| Parameter | Type | Default | Description |
|---|---|---|---|
model | str | Name of the spaCy model or a path to the model on the local disk. | |
pipeline_kwargs | Optional[Dict[str, Any]] | None | Keyword arguments passed to the spaCy pipeline. The pipeline can override these arguments at run time. |
device | Optional[ComponentDevice] | None | The 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.
| Parameter | Type | Default | Description |
|---|---|---|---|
documents | List[Document] | Documents to annotate with named entities. | |
batch_size | int | 1 | Batch size used for processing the documents. |
Related Information
Was this page helpful?