agrag.ingestion.extract.BAMLExtractor
BAMLExtractor(*, settings:ExtractionLLMSettings | None = None, client:object | None = None, tracer:Tracer | None = None, include_heading_path:bool = True) -> None
Bases: LLMExtractor
Extract entities and relations with an LLM through a typed BAML function.
The extractor calls ExtractEntitiesAndRelations on the clients in
ExtractionLLMSettings and retries failed calls with the backoff from
its configuration. The model sees each label with its description through
the enum values. The model answers with labels and names only. The
extractor finds each name in the chunk text and drops a name that is not
there. The response type comes from the graph schema, so the model can
return only declared labels. When an entity type declares properties, the
model also fills a properties value for each entity. A reply that holds
no JSON answer raises UnparsableExtractionError. Needs the llm
extra and a reachable LLM endpoint.
Parameters:
- settings (
ExtractionLLMSettings | None) – LLM client configuration. Defaults toExtractionLLMSettings(), loaded from the environment or.env. Ignored whenclientis given. An injected client also disablessettings.retrybecause its caller owns retry behavior. - client (
object | None) – An already-built BAML client exposingExtractEntitiesAndRelations. - tracer (
Tracer | None) – Opensagrag.extraction.bamlandagrag.llm.callspans.Noneopens no recorded span. - include_heading_path (
bool) – Whether to pass the chunk's heading path as a separatesectionline. The heading is never searched for mentions, so an entity found only in the heading is dropped; only this extractor uses heading context.
Functions:
- extract – Extract with an LLM call through the configured ClientRegistry.
Attributes:
- include_heading_path (
bool) – Whether the chunk's heading path is sent to the model as context. - max_concurrency (
int | None) – - settings –
extract
extract(chunk:Chunk, schema:GraphSchema, candidates:Sequence[ExtractedEntity] | None = None) -> ExtractionResult
Extract with an LLM call through the configured ClientRegistry.
Parameters:
- chunk (
Chunk) – The chunk to read. Onlychunk.textandchunk.idare used. - schema (
GraphSchema) – The entity and relation types to extract. - candidates (
Sequence[ExtractedEntity] | None) – Entities an earlier extractor found. They are listed in the prompt for the model to check. None or empty gives the prompt without that list.
Returns:
ExtractionResult– The entities and relations found in the chunk. An empty result meansExtractionResult– the model answered with no entities or relations.
Raises:
ExtractorMissingExtraError– Thellmpackage extra is not installed.UnparsableExtractionError– The reply holds no JSON answer, such as prose or a cut-off object.ValueError–chunk.idisNone.
include_heading_path
include_heading_path: bool
Whether the chunk's heading path is sent to the model as context.
max_concurrency
max_concurrency: int | None = None
settings
settings = settings