Extraction
Extraction turns a chunk into extracted entities and relations, which are not graph nodes yet. The schema defines which types and relation patterns the extractor can return; later resolution decides which extracted entities refer to the same entity.
Why it exists
A chunk is plain text. Extraction turns statements in that text into typed facts, such as "Charles Babbage designed the Analytical Engine". It records where each extracted entity came from so later stages can validate and resolve it.
A schema keeps the facts consistent. It names the valid entity types and relation types. It also names the pairs of types that each relation can join. An extractor cannot add a type that the schema does not declare.
GLiNER is a compact encoder model that is trained to extract any entity types you define. Your schema's types and descriptions are its input. It runs on your machine and reads every chunk without API calls. The extraction mode is one of three values: gliner uses only the local model, hybrid (the default) adds LLM review of weak chunks, and llm sends chunks directly to the LLM. See Choose an extraction mode for the settings. In hybrid mode, an LLM re-reads eligible chunks, such as those with a kept entity scoring under 0.75, up to the escalation_budget setting, which is the share of each batch the LLM may read. The LLM provider comes from the extraction LLM settings, which use the EXTRACTION_LLM_ prefix.
How it works


The local model reads every chunk. The LLM reads the chunks that most need it, up to a budget, and its entities combine with the local entities.
- The extractor receives one chunk and the schema.
- The local model (GLiNER 2.5) reads the chunk. When candidates are on, it makes a second call that reports spans scoring just under the entity threshold. It sees every entity type and every relation of the schema, each with its description. It returns entities with a text span and a confidence score. It also returns relations between them, with a score.
- The extractor keeps an entity when its score is 0.5 or more. It keeps a relation when its score is 0.7 or more and the pair of entity types is one that the schema allows. When a type has a parent type, the model sees both. If it returns the same words under both, the extractor keeps the label with the higher score. On a tie it keeps the child.
- The extractor reports rejected relations, weak entities and proposed types as candidates, with a reason. Validation also reports each undeclared property as a property candidate. Property candidates occur only on chunks read by the LLM tier and only when the schema declares properties. You can turn candidate reporting off.
- In hybrid mode, after the local model has read every chunk of a batch, the graph ranks eligible chunks. With default settings, a chunk is eligible when a kept entity scores below 0.75, when it has no kept entities and at least eight words, or when a kept entity's type has declared or inherited properties. Chunks with at least two kept entities and no relation come first, because a chunk with several entities and no relation is the likeliest to be missing links. The other chunks follow, weakest first, and chunks with no kept entities come last.
- An LLM reads the eligible chunks in that order, until the budget is used. The budget is 20% of the chunks in a batch by default. In hybrid mode, the local entities go to the LLM as candidates, and the LLM keeps, corrects, or adds to them. The schema is part of the prompt, and BAML builds the allowed entity and relation labels from it at call time, so the reply can only use declared labels. The
relationsandpropertiesfields are added only when the schema declares them. Its entities and the local entities combine into one result. An LLM entity with the name of a local entity keeps the local span and score. A local entity that the LLM did not return stays in the result. If the LLM call fails or gives no usable answer, the chunk keeps the local result. - The pipeline validates the result of every extractor, including an extractor that you write. Validation removes every entity whose label the schema does not declare. It removes every relation whose label, or whose pair of entity types, the schema does not declare. A pattern that names a parent type also covers the child types of that type. It removes undeclared properties from entities and returns them as property candidates. Cardinality and symmetry declarations are not enforced on extracted edges. The pipeline logs how many entities, relations and properties it dropped.
- The result is a list of extracted entities and relations. An extracted entity is not a graph node yet. It keeps its chunk, label, text, and character span. An extracted entity from the local model also keeps a confidence score. One from an LLM has none.
The graph's extraction mode and available LLM settings determine whether an LLM reads chunks. In hybrid or llm mode, omitting llm_extractor still lets the graph build its default BAML extractor from configured environment settings. If those settings are absent, hybrid mode runs locally; use mode="gliner" to disable LLM extraction explicitly. In client mode the server calls no LLM. Chunks that hybrid would send are stored as pending work. See Choose an extraction mode for the mode and model settings.
The local model reports spans and labels, but does not fill property values. A kept entity with declared or inherited properties makes its chunk eligible for LLM review, subject to the hybrid budget. Graph logs a warning when it runs in GLiNER-only mode with declared properties. The LLM reports labels, names, and property values; the extractor finds the names' spans in the text.
Review candidates
Extraction keeps proposed types, items that fall outside the schema, and items below a confidence threshold as candidates. Review lists them, and you approve or reject each one. Approval returns a schema patch. You apply that patch to your schema yourself and raise the schema version, because the review API does not edit the schema file. Converting an approved candidate turns it into an entity, a relation, or a property. A rejected candidate is not created again. See Candidates and Review candidates and grow your schema.
Example
A schema declares the entity types Person, Machine, and City. It declares the relations DESIGNED (Person to Machine) and WORKED_IN (Person to City). The local model reads two sentences.
| Text | Extracted entities | Relations |
|---|---|---|
| Charles Babbage designed the Analytical Engine in London. | Charles Babbage (Person), Analytical Engine (Machine), London (City) | Charles Babbage DESIGNED Analytical Engine |
| Ada Lovelace worked in London and wrote notes on the Analytical Engine. | Ada Lovelace (Person), London (City), Analytical Engine (Machine) | Ada Lovelace WORKED_IN London |
The two sentences give six extracted entities. After resolution, they are four entities, because the two "London" extracted entities and the two "Analytical Engine" extracted entities have equal text.
Design choices
An entity that both results find keeps the local span and score, because the local model reports both for every entity.
The local entities that the LLM did not return stay in the result. The local model finds some entities that the LLM misses, and dropping them would lower recall, so the union keeps both.
The graph uses the lowest score and not the mean, because one uncertain entity can be wrong while the others are right. The mean hides that entity, and the lowest score finds it.
The budget bounds the LLM cost of a run, because an LLM call costs more than a local call and most chunks have at least one entity below 0.75. The run report shows how many eligible chunks the budget left out.
An empty result escalates only for chunks of eight words or more. A short chunk with no entities is often correct, and a long chunk with no entities is usually a miss.
Validation runs after extraction because an LLM can invent a type or a property, and the schema is the contract. Validation is the last step for every extractor, so the graph never receives an undeclared type.
The model scores entities and relations in one pass, so one model call covers both. A second pass for relations only costs time, and the relation endpoints would need a match to the entities anyway.
When the model returns the same words under a parent type and a child type, the extractor keeps the label with the higher score, and keeps the child on a tie. Two labels on one span would make two extracted entities for one thing. The parent labels are added when the node is written.
The model reads each chunk a second time at a lower score to report weak spans as candidates. A lower score changes which overlapping spans the model keeps, so the kept entities come from the first read only.
Related
- Guide: Define a graph schema shows how to declare the entity types and relations that extraction can return.
- Guide: Extract and resolve entities shows how to extract and resolve entities in a graph.
- How-to: Control LLM cost during extraction shows how to limit the LLM calls in a run.
- How-to: Turn candidates off shows how to stop writing discarded items as candidates.
- Explanation: Candidates describes the results that extraction keeps outside the graph.
- Next: Entity resolution
- Reference: Run statistics lists the counts a run reports.
- Reference: Ingestion API lists the ingestion classes and functions.