Skip to content

Add CommunityToolkit.DataIngestion package with LLM chunk processors#10

Closed
luisquintanilla wants to merge 8 commits into
CommunityToolkit:mainfrom
luisquintanilla:feature/data-ingestion
Closed

Add CommunityToolkit.DataIngestion package with LLM chunk processors#10
luisquintanilla wants to merge 8 commits into
CommunityToolkit:mainfrom
luisquintanilla:feature/data-ingestion

Conversation

@luisquintanilla

Copy link
Copy Markdown

PR: Add CommunityToolkit.DataIngestion — LLM Chunk Enrichment Processors

Description

Adds a new CommunityToolkit.DataIngestion package providing 4 LLM-powered chunk processors for Microsoft.Extensions.DataIngestion pipelines. These processors run at ingestion time to enrich chunks with semantic metadata, dramatically improving downstream retrieval quality without adding latency to the query path.

What Each Processor Does

Processor What It Does Why It Helps
EntityExtractionProcessor Identifies people, organizations, technologies, and versions in each chunk Enables filtered vector search — combine semantic similarity with structured filters like "mentions Azure Functions"
TopicClassificationProcessor Labels chunks with primary/secondary topics from your taxonomy Enables topic-based routing — boost or restrict search to relevant domains
HypotheticalQueryProcessor Generates questions each chunk answers, stores them as additional embeddings Bridges the question↔answer gap — users ask questions but docs contain statements; this creates "question-space" vectors that match queries directly
TreeIndexProcessor Creates document-level and corpus-level summary chunks Enables multi-resolution retrieval (RAPTOR) — broad questions match summaries, specific questions match leaf chunks

Metadata Written

Processor Keys Example Value
EntityExtraction entities_people, entities_organizations, entities_technologies, entities_versions "Microsoft, .NET Foundation"
TopicClassification topic_primary, topic_secondary "security", "data,web"
HypotheticalQuery chunk_type, parent_chunk_id, hypothetical_questions "hypothetical_query", "12345"
TreeIndex level, chunk_type, parent_id 1, "branch_summary", "root"

Also includes:

  • IngestionPipelineBuilder<T> — fluent builder with convenience methods
  • DataIngestionServiceCollectionExtensions — DI registration
  • MetadataKeys — strongly-typed metadata key constants

Usage

// Register in DI
builder.Services.AddIngestionPipeline<string>()
    .UseEntityExtraction()
    .UseTopicClassification(o => o.Taxonomy = ["web", "data", "security"])
    .UseHypotheticalQueries(o => o.QuestionsPerChunk = 5)
    .UseTreeIndex();

// Build and run
var pipeline = pipelineBuilder.Build(serviceProvider, reader, chunker, writer);
await pipeline.RunAsync(documents);

Design Notes

Relationship to ProcessAsync in DataIngestion:

  • This follows the same ProcessAsync pattern as Microsoft.Extensions.DataIngestion.IngestionPipeline.ProcessAsync
  • The retrieval-side uses RetrieveAsync (distinct vocabulary for read vs. write paths)

FDG Improvements over original MEDIExtensions source:

  • Metadata keys extracted to public const string fields in MetadataKeys class
  • Optional ILogger<T> on all processors (was: silent exception swallowing)
  • Internal JsonDefaults per package (clean boundary)

Dependencies

All stable, shipped packages:

  • Microsoft.Extensions.DataIngestion
  • Microsoft.Extensions.AI.Abstractions
  • Microsoft.Extensions.DependencyInjection.Abstractions
  • Microsoft.Extensions.Logging.Abstractions

Checklist

  • Code compiles with 0 errors, 0 warnings
  • XML documentation on all public APIs
  • Follows .NET Framework Design Guidelines
  • Unit tests (next PR or added before merge)
  • README/docs update

Related

luisquintanilla and others added 8 commits April 27, 2026 20:12
… DataIngestion)

Port intelligent PDF ingestion packages from luisquintanilla/PdfPig
(feature/intelligent-pdf-ingestion branch, PRs #1 and #2) into the
AI Community Toolkit as a new MEDI top-level feature area.

New packages:
- CommunityToolkit.DocumentProcessing.PdfPig.OnnxLayoutAnalysis
  ONNX-based layout detection (RT-DETR, configurable models, image
  preprocessing, NMS) implementing PdfPig IPageSegmenter
- CommunityToolkit.DocumentProcessing.PdfPig.DataIngestion
  MEDI bridge with vision LLM enrichers (OCR, table extraction,
  contextual chunking) for PDF document ingestion

Infrastructure:
- MEDI/ directory structure following MEVD pattern
- Directory.Build.props for src and test
- Central package management updates
- MEDI.slnf solution filter
- medi.yml CI workflow
- nuget.config with source mapping for dotnet-public feed

Test results: 216 total (213 passed, 3 skipped for missing ONNX model)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Port retrieval processors from MEDIExtensions to CommunityToolkit:
- DataRetrieval: MultiQueryExpander, HydeQueryTransformer, AdaptiveRouter,
  CragValidator, LlmReranker, TreeSearchRetriever, SelfRagOrchestrator,
  SpeculativeRagOrchestrator, RetrievalPipelineBuilder, DI extensions
- DataRetrieval.OnnxReranker: CrossEncoderReranker with ONNX inference,
  TextPairTokenizer, TokenizerFactory (BERT/BPE/SentencePiece support)

Both packages target net10.0;net8.0, build with 0 errors/0 warnings.
Added local NuGet source for Microsoft.Extensions.DataRetrieval packages.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Adds a terminal method to RetrievalPipelineBuilder that registers
a VectorStoreRetriever<TKey,TRecord> as IRetriever in DI. This
enables the builder pattern: services.AddRetrievalPipeline(b => {
    b.AddQueryProcessor(...); }).AsRetriever<K,R>(...);

Also exposes Services property on builder so the terminal can
register the retriever in the service collection.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Port 4 LLM-powered ingestion chunk processors from MEDIExtensions:
- EntityExtractionProcessor: NER via LLM (people, orgs, tech, versions)
- TopicClassificationProcessor: Configurable taxonomy classification
- HypotheticalQueryProcessor: Reverse HyDE question generation
- TreeIndexProcessor: RAPTOR-style tree index (leaf/branch/root summaries)

Includes:
- IngestionPipelineBuilder<T> with fluent builder extensions
- DataIngestionServiceCollectionExtensions for DI registration
- MetadataKeys constants (FDG compliance)
- Optional ILogger on all processors (FDG compliance)
- JsonDefaults internal utility

Implements IngestionChunkProcessor<string> from the stable
Microsoft.Extensions.DataIngestion package.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Port retrieval processor unit tests from MEDIExtensions with namespace
remapping. Covers: MultiQueryExpander, LlmReranker, HydeQueryTransformer,
CragValidator, AdaptiveRouter, SelfRagOrchestrator, SpeculativeRagOrchestrator,
TreeSearchRetriever.

Includes test utilities (TestChatClient, TestVectorStoreCollection) for
deterministic LLM-free testing.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Port ingestion processor unit tests covering: EntityExtraction,
TopicClassification, HypotheticalQuery, TreeIndex processors.

All tests use TestChatClient for deterministic LLM-free execution.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants