Skip to content

AutoChunking + Performance Enhancements#6

Merged
techbuzzz merged 2 commits into
mainfrom
develop
Jun 27, 2026
Merged

AutoChunking + Performance Enhancements#6
techbuzzz merged 2 commits into
mainfrom
develop

Conversation

@techbuzzz

Copy link
Copy Markdown
Owner

Pull Request

Description

v10.2.3 — AutoChunking + Performance Enhancements

This PR delivers two major bodies of work:

1. ✂️ AutoChunking — Progressive Disclosure for Large Documents

When a knowledge document (contract, report, article) exceeds the smallest model's context window, Delibera now automatically splits it into chunks and distributes them across debate rounds via progressive disclosure. Every model receives a complete view of the document by the final round — no more silent context truncation or API errors.

Key additions:

  • Chunking namespaceAutoChunker (3 strategies: SemanticBoundary, FixedSize, SlidingWindow), AutoChunkingOrchestrator, AutoChunkingOptions
  • ModelCapabilities record + ModelContextWindowRegistry (40+ pre-registered models: Llama, Qwen, DeepSeek, Phi, Mistral, Gemma, GPT, Claude, YandexGPT…)
  • ILLMProvider.GetModelCapabilitiesAsync() — Ollama queries /api/show for num_ctx; other providers fall back to the registry
  • PromptContext extended with ChunkingPlan, AutoChunkingEnabled, MinContextWindow, GetChunkedUserPrompt()
  • All debate strategies (StandardDebate, CritiqueDebate, ConsensusDebate) use BuildChunkedPrompt() for round-aware chunk distribution
  • CouncilBuilder.WithOptions() — three configuration paths: fluent API, CouncilOptions snapshot, inline lambda. CouncilBuilder(CouncilOptions) constructor for one-shot setup
  • DI auto-wiringIOptions<CouncilOptions>CouncilBuilder constructor automatically
  • AutoChunkingConfig in CouncilOptions with full appsettings.json binding
  • Console exampledotnet run -- --autochunking

2. ⚡ Performance Enhancements — High Availability & High Performance

Full audit of the hot paths across the entire codebase. 9 fixes applied:

# Area Problem Fix Impact
1 AutoChunker.SplitByHeaders O(n·k) per iteration (5× IndexOf in while-loop) Single-pass ReadOnlySpan<char> scan O(n)
2 SemanticCompressor.SplitSentences O(n·k) per iteration (6× IndexOf in while-loop) Single-pass char scan O(n)
3 AutoChunkingOrchestrator Sequential model capability queries Task.WhenAll — parallel queries N→1 round-trip
4 AutoChunker.SplitBySeparators string.Split() array allocations Span-based IndexOf + manual split 0 allocations
5 KnowledgeKeeper chunk counting context.Split("[Source ").Length - 1 CountOccurrences()IndexOf loop 0 allocations
6 PromptContext.GetChunkedUserPrompt .Skip().Take().ToList() LINQ allocations Index-based for loop 0 enumerator allocations
7 HybridCompressor new DeduplicationCompressor() etc. on every call Lazy-cached _dedup/_semantic/_summarizer fields 0 allocations on reuse
8 TokenCounter memoization No eviction — new values silently dropped when full LRU eviction with LinkedList<string> + batch eviction (64) Correct cache under load
9 CouncilBuilder.ApplyOptions Magic strings/numbers Named constants DefaultStrategy, DefaultMaxRounds, DefaultTemperature Readability + safety

Already-optimized code confirmed correct:

  • CompressionCacheArrayPool<T>, stackalloc, ReaderWriterLockSlim, batch eviction
  • SemanticCompressor.CosineSimilarity — SIMD Vector<float> hardware acceleration
  • DeduplicationCompressorCollectionsMarshal.AsSpan(), batch processing (16)
  • TokenCounter.EstimateTokens(ReadOnlySpan<char>) — allocation-free
  • OllamaProviderPolly.ResilienceContextPool.Shared

Documentation

  • CHANGELOG.md — full [10.2.3] section
  • README.md / README-RU.md — new AutoChunking section (how it works, 3 config paths, appsettings, model registry)
  • src/Delibera.Core/README.md (NuGet) — AutoChunking section + updated appsettings example
  • Delibera.Core.csproj — version 10.2.210.2.3, updated Description, PackageTags, PackageReleaseNotes

Related Issues

N/A — feature-driven release.

Type of Change

  • ✨ New feature (non-breaking change that adds functionality)
  • ⚡ Performance enhancement
  • 📚 Documentation update

Checklist

  • My code follows the project's coding standards (see CONTRIBUTING.md)
  • The solution builds with 0 errors and 0 warnings (dotnet build --configuration Release)
  • I have added/updated XML documentation for public APIs
  • I have updated relevant documentation (README.md, README-RU.md, CHANGELOG.md, NuGet README)
  • I have tested my changes (examples run as expected)

Additional Notes

  • Fully backward compatible — AutoChunking is opt-in (disabled by default). All existing ILLMProvider implementations continue to work (default GetModelCapabilitiesAsync returns null). PromptContext is a record with with-expression support.
  • 31 files changed, +2,899 / −319 lines.
  • The --autochunking console example includes an offline mode that demonstrates chunking plans for 4K/8K/32K/128K context windows without requiring a running Ollama instance.

Introduces AutoChunking for automatic splitting of large knowledge documents into context-window-sized chunks, distributed across debate rounds via progressive disclosure. Adds new Chunking namespace (AutoChunker, AutoChunkingOrchestrator, options, plan/record types), model capabilities registry, and DI/appsettings integration. All debate strategies now support round-aware chunk distribution. Includes new configuration options, DI auto-wiring, and a console example. Docs and config updated. No breaking changes; feature is opt-in and backward compatible.
Refactored text splitting to use single-pass, allocation-free span-based scans for headers, sentences, and separators, improving performance and memory usage. Added LRU memoization to TokenCounter. Reused sub-compressor instances in HybridCompressor. Centralized CouncilBuilder defaults. Replaced string.Split substring counting with a custom method in KnowledgeKeeper. Switched to index-based chunk selection in PromptContext. Parallelized model capability queries in AutoChunkingOrchestrator.
@techbuzzz techbuzzz self-assigned this Jun 27, 2026
@techbuzzz techbuzzz merged commit cb1b21d into main Jun 27, 2026
2 checks passed
@techbuzzz techbuzzz deleted the develop branch June 27, 2026 10:04
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.

1 participant