Table of Contents

Class CompressionResult

Namespace
AiDotNet.PromptEngineering.Compression
Assembly
AiDotNet.dll

Contains the result of a prompt compression operation including metrics.

public class CompressionResult
Inheritance
CompressionResult
Inherited Members

Remarks

This class encapsulates the compressed prompt along with detailed metrics about the compression operation, including token counts, compression ratio, and estimated cost savings.

For Beginners: This is the result of compressing a prompt, with before/after stats.

When you compress a prompt, you want to know:

  • What's the compressed text?
  • How much shorter is it?
  • How much money did we save?

Example:

var result = compressor.CompressWithMetrics(longPrompt, options);

Console.WriteLine($"Before: {result.OriginalTokenCount} tokens");
Console.WriteLine($"After: {result.CompressedTokenCount} tokens");
Console.WriteLine($"Saved: {result.TokensSaved} tokens ({result.CompressionRatio:P0})");
Console.WriteLine($"Cost savings: ${result.EstimatedCostSavings}");
Console.WriteLine($"Compressed prompt: {result.CompressedPrompt}");

Properties

CompressedAt

Gets or sets the timestamp when compression was performed.

public DateTime CompressedAt { get; set; }

Property Value

DateTime

CompressedPrompt

Gets or sets the compressed prompt.

public string CompressedPrompt { get; set; }

Property Value

string

Remarks

For Beginners: The shorter version of your prompt. This is what you'd actually send to the AI model.

CompressedTokenCount

Gets or sets the token count of the compressed prompt.

public int CompressedTokenCount { get; set; }

Property Value

int

Remarks

For Beginners: How many tokens after compression. This is your "after" measurement.

CompressionMethod

Gets or sets the compression method used.

public string CompressionMethod { get; set; }

Property Value

string

Remarks

For Beginners: How the prompt was compressed. Examples: "RedundancyRemoval", "Summarization", "Caching"

CompressionRatio

Gets the compression ratio (0.0 to 1.0, where higher means more compression).

public double CompressionRatio { get; }

Property Value

double

Remarks

Calculated as (OriginalTokenCount - CompressedTokenCount) / OriginalTokenCount. A ratio of 0.3 means 30% of tokens were removed.

For Beginners: What percentage of the prompt was removed. - 0.0 = No compression (same size) - 0.5 = 50% smaller - 1.0 = Everything removed (shouldn't happen!)

EstimatedCostSavings

Gets or sets the estimated cost savings in USD.

public decimal EstimatedCostSavings { get; set; }

Property Value

decimal

Remarks

Based on the token reduction and current API pricing for the target model. Useful for ROI calculations on compression efforts.

For Beginners: How much money you saved by using less tokens. If compression saved 100 tokens on GPT-4 (~$0.003 per 1K tokens input), savings would be about $0.0003.

IsSuccessful

Gets whether the compression was successful (reduced token count).

public bool IsSuccessful { get; }

Property Value

bool

OriginalPrompt

Gets or sets the original prompt before compression.

public string OriginalPrompt { get; set; }

Property Value

string

Remarks

For Beginners: The prompt you started with, before any changes. Stored so you can compare or revert if needed.

OriginalTokenCount

Gets or sets the token count of the original prompt.

public int OriginalTokenCount { get; set; }

Property Value

int

Remarks

For Beginners: How many tokens the original prompt had. This is your "before" measurement.

TokensSaved

Gets the number of tokens saved by compression.

public int TokensSaved { get; }

Property Value

int

Remarks

For Beginners: How many tokens were removed. OriginalTokenCount - CompressedTokenCount

Warnings

Gets or sets any warnings generated during compression.

public IReadOnlyList<string> Warnings { get; set; }

Property Value

IReadOnlyList<string>

Remarks

Warnings about potential issues with the compression, such as possible loss of important information or reaching minimum length.

For Beginners: Problems that occurred during compression. For example: "Could not compress further without losing meaning"