PinkRooster.Extensions.DataIngestion.Chunkers 1.0.0-preview.4

This is a prerelease version of PinkRooster.Extensions.DataIngestion.Chunkers.
dotnet add package PinkRooster.Extensions.DataIngestion.Chunkers --version 1.0.0-preview.4
                    
NuGet\Install-Package PinkRooster.Extensions.DataIngestion.Chunkers -Version 1.0.0-preview.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PinkRooster.Extensions.DataIngestion.Chunkers" Version="1.0.0-preview.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PinkRooster.Extensions.DataIngestion.Chunkers" Version="1.0.0-preview.4" />
                    
Directory.Packages.props
<PackageReference Include="PinkRooster.Extensions.DataIngestion.Chunkers" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add PinkRooster.Extensions.DataIngestion.Chunkers --version 1.0.0-preview.4
                    
#r "nuget: PinkRooster.Extensions.DataIngestion.Chunkers, 1.0.0-preview.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package PinkRooster.Extensions.DataIngestion.Chunkers@1.0.0-preview.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=PinkRooster.Extensions.DataIngestion.Chunkers&version=1.0.0-preview.4&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=PinkRooster.Extensions.DataIngestion.Chunkers&version=1.0.0-preview.4&prerelease
                    
Install as a Cake Tool

PinkRooster logo

PinkRooster.Extensions.DataIngestion.Chunkers

Structure-aware chunking (recursive, table and hierarchical) and situational contextual enrichment for Microsoft.Extensions.DataIngestion.

Status: release, developed against the .NET 10 SDK with AOT and trimmability support.

dotnet add package PinkRooster.Extensions.DataIngestion.Chunkers --prerelease

Overview

PinkRooster.Extensions.DataIngestion.Chunkers extends Microsoft's RAG abstractions with production-grade text processing components:

  • RecursiveTokenChunker: Hierarchical document chunker that respects document structure (headers, code blocks, tables, paragraphs) and uses stepped token budget windows (MaxTokensPerChunk, ReservedHeaderTokens, OverlapTokens). Slices text without intermediate allocations and snaps boundaries cleanly to word boundaries.
  • MarkdownTableChunker: Splits Markdown and document tables into row windows that each repeat the header row, with part index, continuation flag and row range in the chunk metadata. Prose around the tables can be emitted or skipped (EmitNonTableContent).
  • HierarchicalTokenChunker: Streams large parent chunks and the smaller child chunks cut from each, linked by chunk_id/parent_id metadata for small-to-big retrieval. EmissionMode selects parents, children, or both interleaved.
  • ContextualChunkProcessor: Enriches chunks with document-level situational context using an IChatClient (e.g. Azure OpenAI, Ollama, or custom models), boosting retrieval precision and MRR in dense and hybrid vector search pipelines.

Quickstart

using Microsoft.Extensions.DataIngestion;
using Microsoft.ML.Tokenizers;
using PinkRooster.Extensions.DataIngestion.Chunkers;

var tokenizer = TiktokenTokenizer.CreateForModel("gpt-4o");

var options = new RecursiveChunkerOptions(tokenizer)
{
    MaxTokensPerChunk = 256,
    OverlapTokens = 32,
    PreserveAtomicElements = true,
};

var chunker = new RecursiveTokenChunker(options);

var document = new IngestionDocument("guide.md");
var section = new IngestionDocumentSection();
section.Elements.Add(new IngestionDocumentHeader("# Architecture Overview") { Level = 1 });
section.Elements.Add(new IngestionDocumentParagraph("This guide covers the core pipeline flow."));
document.Sections.Add(section);

await foreach (IngestionChunk<string> chunk in chunker.ProcessAsync(document))
{
    Console.WriteLine($"Chunk ({chunk.Content.Length} chars): {chunk.Content}");
}

Features

  • Zero-allocation slicing: Uses ReadOnlySpan<char> and Tokenizer.GetIndexByTokenCount for deterministic token evaluation.
  • Atomic element preservation: Prevents tables, formulas, and demarcated code blocks from being split into illegible fragments.
  • Situational enrichment: Prepends document-level context summaries via ContextualChunkProcessor with token budget guards.
  • AOT and Trimmable: Fully validated with <IsAotCompatible>true</IsAotCompatible> and <IsTrimmable>true</IsTrimmable>.

Chunk metadata

Every key below is a constant on ChunkMetadataKeys; read metadata through the constants rather than string literals.

Constant Key Value Written by
IsTablePart is_table_part bool, always true chunks cut from a table
TablePartIndex table_part_index int, zero-based part within the table chunks cut from a table
IsTableContinuation is_table_continuation bool, true after the first part chunks cut from a table
TableRowRange table_row_range string, one-based inclusive data rows such as 3-7, or 0-0 chunks cut from a table
ChunkRole chunk_role string, ParentRole (parent) or ChildRole (child) HierarchicalTokenChunker
ChunkId chunk_id string, identifier within the document HierarchicalTokenChunker
ParentId parent_id string, the parent's chunk_id HierarchicalTokenChunker children
ChildIndex child_index int, zero-based position within the parent HierarchicalTokenChunker children
ChildCount child_count int, number of children of the parent HierarchicalTokenChunker
ParentTokenCount parent_token_count int, token count of the parent HierarchicalTokenChunker
ContextualHeader contextual_header string, the prepended header ContextualChunkProcessor
ConditionalSymbols conditional_symbols string[], active preprocessor symbols RoslynCodeChunker (CodeAnalysis package)
FilePath file_path string, file path or document identifier RoslynCodeChunker, RecursiveTokenChunker
StartLine start_line int, 1-based start line in source document RoslynCodeChunker, RecursiveTokenChunker
EndLine end_line int, 1-based end line in source document RoslynCodeChunker, RecursiveTokenChunker
LineRange line_range string, formatted 1-based line span (e.g. 42-65) RoslynCodeChunker, RecursiveTokenChunker
StartColumn start_column int, 1-based character column where chunk begins RoslynCodeChunker
EndColumn end_column int, 1-based character column where chunk ends RoslynCodeChunker

Telemetry

ContextualChunkProcessor emits one contextual_enrichment activity per enriched chunk from the ActivitySource named by ContextualChunkProcessor.ActivitySourceName (PinkRooster.Extensions.DataIngestion.Chunkers). Register that name with your tracer (for OpenTelemetry, AddSource(ContextualChunkProcessor.ActivitySourceName)). Each activity carries these tags:

Tag Value
contextual_enrichment.outcome enriched, header_omitted, provider_fallback or provider_error
gen_ai.usage.input_tokens input tokens reported by the chat client
gen_ai.usage.output_tokens output tokens reported by the chat client
gen_ai.usage.cache_read.input_tokens cached input tokens reported by the chat client

When LoggerFactory is set, every outcome and its token counts are logged at Debug level, including the two outcomes that start no activity: filtered (excluded by ChunkFilter) and unresolved_context (fallback when the chunk cannot be located in its document).

Compatibility

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on PinkRooster.Extensions.DataIngestion.Chunkers:

Package Downloads
PinkRooster.Extensions.DataIngestion.CodeAnalysis

Roslyn-based C# source reading and syntax-aware AST chunking for Microsoft.Extensions.DataIngestion.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0-preview.4 62 11/21/2026
1.0.0-preview.3 66 11/20/2026
1.0.0-preview.2 59 11/20/2026
1.0.0-preview.1 62 11/20/2026