Skip to main content
Version: latest

agrag.ingestion.extract.GlinerExtractor

GlinerExtractor(*, settings:ExtractionSettings | None = None, model:object | None = None, tracer:Tracer | None = None) -> None

Bases: Extractor

Extracts entities and relations with a local GLiNER2.5 model.

The model runs in this process, so extraction needs no LLM key. It loads on first use and one load serves concurrent calls. Inference calls run one at a time on one worker thread. A call cancelled while it waits for its turn never starts, and one cancelled mid-inference leaves the next call waiting until the inference ends. The first load downloads the weights from Hugging Face unless model is passed. Needs the extract extra.

One model call reads the whole schema: every entity type and every relation, each with its description. Entities need settings.entity_threshold. Relations need settings.relation_threshold and must match a pattern of the schema, where a pattern also accepts the child types of its labels. When the model returns the same words under a parent type and a child type, the label with the higher score is kept. Every kept entity and relation carries its confidence.

The extractor reports what it dropped as candidates in the result: relations below the threshold, that match no pattern, or whose endpoint is not a kept entity. With settings.candidates_enabled it also makes a second model call at settings.band_floor and reports entity spans that score between that floor and the entity threshold and do not overlap a kept entity.

The model reports spans and types only, so extracted entities carry no property values. The result sets needs_properties when a kept entity has a type that declares properties. Chunks of the default size fit the model in one pass.

Parameters:

  • settings (ExtractionSettings | None) – Model name, data type and thresholds. Defaults to ExtractionSettings(), loaded from the environment or .env.
  • model (object | None) – An already-built GLiNER2.5 model.
  • tracer (Tracer | None) – Opens agrag.extraction.gliner and agrag.extraction.model_load spans. None opens no recorded span.

Attributes:

  • settings – The checkpoint, precision and thresholds used by extraction.

Functions:

  • extract – Extract with the local GLiNER2.5 model.

extract​

extract(chunk:Chunk, schema:GraphSchema) -> ExtractionResult

Extract with the local GLiNER2.5 model.

Parameters:

  • chunk (Chunk) – The chunk to read. Only chunk.text and chunk.id are used.
  • schema (GraphSchema) – The entity and relation types to extract.

Returns:

  • ExtractionResult – The normalized entities and relations found in the chunk.

Raises:

max_concurrency​

max_concurrency = 1

settings​

settings = settings if settings is not None else ExtractionSettings()