Implementation:Ucbepic Docetl Directive MapResolveToMapWithCategories
| Knowledge Sources | |
|---|---|
| Domains | Pipeline_Optimization, LLM_Operations |
| Last Updated | 2026-02-08 00:00 GMT |
Overview
Concrete tool for replacing a Map -> Resolve pattern with a single Map that uses predefined categories provided by the DocETL reasoning optimizer.
Description
The MapResolveToMapWithCategoriesDirective class replaces a Map -> Resolve pattern with a single Map operation that has predefined categories. The agent analyzes the data and task to propose a set of canonical categories, and the new Map forces outputs into one of these categories (or "none of the above"). This performs entity resolution deterministically by standardizing outputs upfront, avoiding the need for pairwise comparisons.
Usage
The MOAR agent applies this directive when a Map operation produces outputs that are then resolved/deduplicated, and the set of valid output categories can be enumerated upfront. More efficient than Resolve when the category space is small and well-defined (e.g., standardizing company types, product categories, sentiment labels).
Code Reference
Source Location
- Repository: Ucbepic_Docetl
- File: docetl/reasoning_optimizer/directives/map_resolve_to_map_with_categories.py
- Lines: 1-361
Signature
class MapResolveToMapWithCategoriesDirective(Directive):
name = "map_resolve_to_map_with_categories"
description = "Replace a Map -> Resolve pattern with a single Map using predefined categories for deterministic entity resolution."
def check_applicability(self, ...) -> Tuple[bool, str]: ...
def apply(self, ...) -> Tuple[List[Dict], List[Dict], str, dict]: ...
Import
from docetl.reasoning_optimizer.directives.map_resolve_to_map_with_categories import MapResolveToMapWithCategoriesDirective
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| op_config | Dict | Yes | Operation configuration to transform |
| pipeline_ops | List[Dict] | Yes | Full pipeline operations list |
| op_idx | int | Yes | Index of target operation |
| dataset_descriptions | Dict | Yes | Dataset schema descriptions |
Outputs
| Name | Type | Description |
|---|---|---|
| new_ops | List[Dict] | Transformed operation configs |
| new_steps | List[Dict] | Updated pipeline steps |
| explanation | str | Human-readable description of changes |
| metadata | dict | Additional metadata about the transformation |
Usage Examples
# Directives are typically invoked by the MOAR agent automatically
# Example of manual invocation:
from docetl.reasoning_optimizer.directives.map_resolve_to_map_with_categories import MapResolveToMapWithCategoriesDirective
directive = MapResolveToMapWithCategoriesDirective()
applicable, reason = directive.check_applicability(op_config, pipeline_ops, op_idx, dataset_descriptions)
if applicable:
new_ops, new_steps, explanation, metadata = directive.apply(op_config, pipeline_ops, op_idx, dataset_descriptions)