Skip to main content

agrag.ingestion.extract.BAMLExtractor

BAMLExtractor(*, settings:ExtractionLLMSettings | None = None, client:object | None = None, tracer:Tracer | None = None, include_heading_path:bool = True) -> None

Bases: Extractor

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 response type comes from the graph schema, so the model can return only declared labels and property keys, and it can fill entity properties. 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. Offsets still index chunk.text; only this extractor uses heading context.

Functions:

  • extract – Extract with an LLM call through the configured ClientRegistry.

Attributes:

extract​

extract(chunk:Chunk, schema:GraphSchema) -> 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.

Returns:

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

Raises:

settings​

settings = settings