> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mixpeek.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Taxonomy Enrich

> Classify and tag documents using predefined taxonomies

<Frame>
  <img src="https://mintcdn.com/mixpeek/TmiAqiYj-LwmWL2a/assets/retrievers/taxonomy-enrich.svg?fit=max&auto=format&n=TmiAqiYj-LwmWL2a&q=85&s=64bc8288d3799384b8bd0097193b27e3" alt="Taxonomy Enrich stage showing document classification with hierarchical taxonomies" width="1000" height="400" data-path="assets/retrievers/taxonomy-enrich.svg" />
</Frame>

The Taxonomy Enrich stage classifies documents against predefined taxonomies, adding structured category labels and hierarchical classifications to your search results.

<Note>
  **Stage Category**: ENRICH (Enriches documents with classifications)

  **Transformation**: N documents → N documents (with taxonomy labels added)
</Note>

## When to Use

| Use Case                   | Description                         |
| -------------------------- | ----------------------------------- |
| **Content categorization** | Auto-classify documents into topics |
| **Faceted search**         | Add filterable category facets      |
| **Compliance tagging**     | Apply regulatory classifications    |
| **Product taxonomy**       | Classify into product hierarchies   |

## When NOT to Use

| Scenario                    | Recommended Alternative      |
| --------------------------- | ---------------------------- |
| Free-form tagging           | `llm_enrich`                 |
| Pre-classified content      | Skip this stage              |
| Custom classification logic | `api_call` to custom service |

## Parameters

| Parameter           | Type    | Default    | Description                      |
| ------------------- | ------- | ---------- | -------------------------------- |
| `taxonomy_id`       | string  | *Required* | ID of the taxonomy to use        |
| `content_field`     | string  | `content`  | Field to classify                |
| `result_field`      | string  | `taxonomy` | Field for classification results |
| `max_depth`         | integer | `null`     | Maximum hierarchy depth          |
| `top_k`             | integer | `3`        | Number of top classifications    |
| `min_score`         | float   | `0.5`      | Minimum confidence threshold     |
| `include_ancestors` | boolean | `true`     | Include parent categories        |

## Configuration Examples

<CodeGroup>
  ```json Basic Classification theme={null}
  {
    "stage_name": "taxonomy_enrich",
    "stage_type": "enrich",
    "config": {
      "stage_id": "taxonomy_enrich",
      "parameters": {
        "taxonomy_id": "product_categories"
      }
    }
  }
  ```

  ```json High-Confidence Only theme={null}
  {
    "stage_name": "taxonomy_enrich",
    "stage_type": "enrich",
    "config": {
      "stage_id": "taxonomy_enrich",
      "parameters": {
        "taxonomy_id": "topics",
        "top_k": 1,
        "min_score": 0.8
      }
    }
  }
  ```

  ```json Limit Matches Per Document theme={null}
  {
    "stage_name": "taxonomy_enrich",
    "stage_type": "enrich",
    "config": {
      "stage_id": "taxonomy_enrich",
      "parameters": {
        "taxonomy_id": "industry_taxonomy",
        "top_k": 3
      }
    }
  }
  ```

  ```json Multiple Classifications theme={null}
  {
    "stage_name": "taxonomy_enrich",
    "stage_type": "enrich",
    "config": {
      "stage_id": "taxonomy_enrich",
      "parameters": {
        "taxonomy_id": "content_types",
        "top_k": 5,
        "min_score": 0.3
      }
    }
  }
  ```
</CodeGroup>

## Output Schema

### Basic Classification

```json theme={null}
{
  "document_id": "doc_123",
  "content": "Latest smartphone with 5G connectivity...",
  "categories": {
    "primary": {
      "id": "electronics.mobile.smartphones",
      "name": "Smartphones",
      "confidence": 0.95
    },
    "all": [
      {"id": "electronics.mobile.smartphones", "name": "Smartphones", "confidence": 0.95},
      {"id": "electronics.mobile", "name": "Mobile Devices", "confidence": 0.82},
      {"id": "electronics", "name": "Electronics", "confidence": 0.78}
    ]
  }
}
```

### With Ancestors

```json theme={null}
{
  "document_id": "doc_456",
  "content": "Investment banking services...",
  "industry": {
    "primary": {
      "id": "finance.banking.investment",
      "name": "Investment Banking",
      "confidence": 0.91
    },
    "ancestors": [
      {"id": "finance.banking", "name": "Banking", "level": 2},
      {"id": "finance", "name": "Finance", "level": 1}
    ],
    "path": "Finance > Banking > Investment Banking"
  }
}
```

### Low Confidence (No Match)

```json theme={null}
{
  "document_id": "doc_789",
  "content": "Random unrelated content...",
  "categories": {
    "primary": null,
    "all": [],
    "message": "No classifications above confidence threshold"
  }
}
```

## Taxonomy Structure

Taxonomies are hierarchical classification systems:

```
Electronics
├── Mobile Devices
│   ├── Smartphones
│   ├── Tablets
│   └── Wearables
├── Computers
│   ├── Laptops
│   ├── Desktops
│   └── Components
└── Audio
    ├── Headphones
    └── Speakers
```

Each node has:

* **ID**: Dot-notation path (e.g., `electronics.mobile.smartphones`)
* **Name**: Human-readable label
* **Level**: Depth in hierarchy (1 = root)

## Performance

| Metric                 | Value                          |
| ---------------------- | ------------------------------ |
| **Latency**            | 10-50ms per document           |
| **Batch processing**   | Automatic                      |
| **Model type**         | Embedding-based classification |
| **Parallel execution** | Up to 20 concurrent            |

<Tip>
  Pre-compute taxonomy embeddings for faster classification. Use `top_k: 1` and higher `min_score` when you only need the best match.
</Tip>

## Common Pipeline Patterns

### Search + Classify + Filter

```json theme={null}
[
  {
    "stage_name": "semantic_search",
    "stage_type": "filter",
    "config": {
      "stage_id": "feature_search",
      "parameters": {
        "searches": [
          { "feature_uri": "mixpeek://text_extractor@v1/multilingual_e5_large_instruct_v1", "query": { "input_mode": "text", "value": "{{INPUT.query}}" }, "top_k": 100 }
        ],
        "final_top_k": 100
      }
    }
  },
  {
    "stage_name": "taxonomy_enrich",
    "stage_type": "enrich",
    "config": {
      "stage_id": "taxonomy_enrich",
      "parameters": {
        "taxonomy_id": "product_categories",
        "top_k": 1,
        "min_score": 0.7
      }
    }
  },
  {
    "stage_name": "structured_filter",
    "stage_type": "filter",
    "config": {
      "stage_id": "attribute_filter",
      "parameters": {
        "conditions": {
          "field": "category.primary.id",
          "operator": "starts_with",
          "value": "{{INPUT.category_filter}}"
        }
      }
    }
  }
]
```

### Multi-Taxonomy Classification

```json theme={null}
[
  {
    "stage_name": "semantic_search",
    "stage_type": "filter",
    "config": {
      "stage_id": "feature_search",
      "parameters": {
        "searches": [
          { "feature_uri": "mixpeek://text_extractor@v1/multilingual_e5_large_instruct_v1", "query": { "input_mode": "text", "value": "{{INPUT.query}}" }, "top_k": 50 }
        ],
        "final_top_k": 50
      }
    }
  },
  {
    "stage_name": "taxonomy_enrich",
    "stage_type": "enrich",
    "config": {
      "stage_id": "taxonomy_enrich",
      "parameters": {
        "taxonomy_id": "topics"
      }
    }
  },
  {
    "stage_name": "taxonomy_enrich",
    "stage_type": "enrich",
    "config": {
      "stage_id": "taxonomy_enrich",
      "parameters": {
        "taxonomy_id": "sentiment"
      }
    }
  }
]
```

### Faceted Search Results

```json theme={null}
[
  {
    "stage_name": "hybrid_search",
    "stage_type": "filter",
    "config": {
      "stage_id": "feature_search",
      "parameters": {
        "searches": [
          { "feature_uri": "mixpeek://text_extractor@v1/multilingual_e5_large_instruct_v1", "query": { "input_mode": "text", "value": "{{INPUT.query}}" }, "top_k": 100 }
        ],
        "final_top_k": 100
      }
    }
  },
  {
    "stage_name": "taxonomy_enrich",
    "stage_type": "enrich",
    "config": {
      "stage_id": "taxonomy_enrich",
      "parameters": {
        "taxonomy_id": "categories",
        "top_k": 3
      }
    }
  }
]
```

## Error Handling

| Error                  | Behavior                        |
| ---------------------- | ------------------------------- |
| Unknown taxonomy\_id   | Stage fails                     |
| No match found         | Empty classification, continues |
| Invalid content\_field | Stage fails                     |
| Low confidence         | Filtered by `min_score`         |

## Related

* [LLM Enrich](/retrieval/stages/llm-enrich) - Free-form extraction
* [Document Enrich](/retrieval/stages/document-enrich) - Collection joins
* [Attribute Filter](/retrieval/stages/attribute-filter) - Filter by categories
