Skip to main content
Version: 0.0.5 (stable)

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 to ExtractionLLMSettings(), loaded from the environment or .env. Ignored when client is given. An injected client also disables settings.retry because its caller owns retry behavior.
  • client (object | None) – An already-built BAML client exposing ExtractEntitiesAndRelations.
  • tracer (Tracer | None) – Opens agrag.extraction.baml and agrag.llm.call spans. None opens no recorded span.
  • include_heading_path (bool) – Whether to pass the chunk's heading path as a separate section line. 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:

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. Only chunk.text and chunk.id are 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 means
  • ExtractionResult – the model answered with no entities or relations.

Raises:

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