Funnel

Progressive precision refinement through staged filtering.

Overview

The Funnel starts broad and narrows at each stage via prompt-guided extraction. Each stage applies a filter criterion to reduce the result set.

Usage

from contextual_distillation import Funnel, FunnelStage

stages = [
    FunnelStage(
        prompt="Extract all legal references",
        filter_criterion="is_legal_reference",
    ),
    FunnelStage(
        prompt="Keep only statutes",
        filter_criterion="is_statute",
    ),
]
funnel = Funnel(stages=stages)
result = await funnel.run(
    query="Find applicable statutes",
    chunks=chunks,
)

FunnelStage

Each stage has:

Field Type Description
prompt str Instructions for the LLM at this stage
filter_criterion str Field or function to filter results

FunnelResult

The result contains:

Field Type Description
context str Final extracted context
stage_stats list[StageStats] Per-stage reduction metrics
reduction_ratio float Overall reduction from input to output