# Classify and route your data using Content Understanding

## Classification and splitting

The `analyzer` concept has been expanded to include `contentCategories` and `enableSegment`, which let you classify and split the input data processed by your application. This analyzer capability can classify an entire input file at once, and it can also detect multiple documents—or multiple copies of the same document—contained within a single input file.

Beyond this, Content Understanding lets you build custom classification workflows that direct your content to the appropriate analyzer. Through routing, you can pass several data streams through one shared pipeline while making sure each is handled by the analyzer best suited to its type.

* * *

## Architecture Overview

![](https://cdn.hashnode.com/uploads/covers/68f7b959ef9f07b510b2b032/407ca730-99f7-4ed8-aa31-9f55606398b5.png align="center")

**Input file** enters the pipeline as the raw document you want to process.

**Classifier analyzer** sits at the center. This is the analyzer configured with `contentCategories` and `enableSegment` — it looks at the input file and both classifies it and splits it into segments.

That classifier fans out into three example categories, each representing a type of content the classifier can detect:

*   **Category A** and **Category B** are each routed to their own **custom analyzer**, which extracts the relevant fields from that piece of content and produces **structured output**.
    
*   **Category C** (e.g. a cover page) has no analyzer linked to it. Not every category needs one — if a segment just needs to be identified and removed rather than further processed, you can leave it unrouted and you can simply discard it from the pipeline.
    

* * *

## Creating a **base classifier**

To create the base classifier, first you need to define the custom categories with names and descriptions. These definitions will be used by the analyzer to classify the input file.

Here is an example `definition of a list of categories`. For simplicity, I define only one category in the list. To `improve classification and splitting quality`, use a good category name and description so that the model can understand the categories with some context.

```csharp
public sealed record ContentUnderstandingCategory(string Name, string Description);

public static readonly IReadOnlyList<ContentUnderstandingCategory> All =
[
    new("Walmart_Invoice",
        "Invoice containing Walmart as the title on the top right of each page.") 
];
```

Then, create the `classification analyzer` for your input file:

```csharp
 var config = new ContentAnalyzerConfig
 {
     ShouldReturnDetails = false,
     EnableOcr = true,
     EnableLayout = true,
     EnableFormula = false,
     EnableFigureDescription = false,
     EnableFigureAnalysis = false,
     ChartFormat = ChartFormat.ChartJs,
     TableFormat = TableFormat.Html,
     AnnotationFormat = AnnotationFormat.Markdown,
     EnableSegment = true,
     SegmentPerPage = false,
     ShouldOmitContent = false
 };

 foreach (var category in ContentUnderstandingCategories.All)
 {
     var definition = new ContentCategoryDefinition { Description = category.Description };
 
// If you have more than one category, each will have a different analyzer linked
definition.AnalyzerId = _options.ExtractAnalyzerId;

config.ContentCategories.Add(category.Name, definition);
 }

 var analyzer = new ContentAnalyzer
 {
     BaseAnalyzerId = "prebuilt-document",
     ProcessingLocation = ProcessingLocation.Geography,
     Config = config,
 };

 analyzer.Models["completion"] = _options.CompletionModelName;

 await CreateOrReplaceAsync(_options.ClassifierAnalyzerId, analyzer, ct).ConfigureAwait(false);
```

To route to a custom analyzer, we need to create one. Below is the code for the analyzer that will extract information from the `Walmart invoice`:

```csharp
public async Task CreateOrUpdateExtractAnalyzerAsync(CancellationToken ct = default)
 {
     var analyzer = new ContentAnalyzer
     {
         BaseAnalyzerId = "prebuilt-document",
         Config = new ContentAnalyzerConfig
         {
             EnableOcr = true,
             EnableLayout = true,
             EstimateFieldSourceAndConfidence = true,
         }
         FieldSchema = new ContentFieldSchema(
             WalmartFields.All.ToDictionary(
                 f => f.Name,
                 f => ExtractField(f.Type, f.Description))),
     };

     analyzer.Models["completion"] = _options.CompletionModelName;

// You will create one analyzer per category needed to be processed
     await CreateOrReplaceAsync(_options.ExtractAnalyzerId, analyzer, ct).ConfigureAwait(false);
 }
```

As mentioned above, you **don't need to link an analyzer to a category** if that category doesn't require further processing.

* * *
