PromptCompressorBase

Base Classes · AiDotNet.PromptEngineering.Compression

Provides a base implementation for prompt compressors with common functionality.

Implements: IPromptCompressor

Known derived types: CachingCompressor, CompositeCompressor, LLMSummarizationCompressor, RedundancyRemovalCompressor, SentenceCompressor, StopWordRemovalCompressor

For Beginners

This is the foundation that all prompt compressors build upon.

Think of it like a template for making prompts shorter:

  • It handles common tasks (counting tokens, checking inputs)
  • Specific compression methods fill in how they compress
  • This ensures all compressors work consistently

Derived classes just need to implement CompressCore to define their compression logic.

How It Works

This abstract class implements the IPromptCompressor interface and provides common functionality for prompt compression strategies. It handles token counting, validation, and delegates to derived classes for the core compression logic.

Properties

Property Summary
string Name { get; } Gets the name of this compressor implementation.

Methods

Method Summary
CompressionResult CompressWithMetrics(string prompt, CompressionOptions options) Compresses a prompt and returns detailed metrics about the compression.
Task<string> CompressAsync(string prompt, CompressionOptions options, CancellationToken cancellationToken) Compresses a prompt asynchronously.
string Compress(string prompt, CompressionOptions options) Compresses a prompt to reduce its token count.