This commit is contained in:
32
docs/snippets/csharp/advanced/token_reduction_example.md
Normal file
32
docs/snippets/csharp/advanced/token_reduction_example.md
Normal file
@@ -0,0 +1,32 @@
|
||||
```csharp title="C#"
|
||||
using Kreuzberg;
|
||||
|
||||
var config = new ExtractionConfig
|
||||
{
|
||||
TokenReduction = new TokenReductionConfig
|
||||
{
|
||||
Mode = "moderate",
|
||||
PreserveMarkdown = true
|
||||
}
|
||||
};
|
||||
|
||||
var result = await KreuzbergLib.ExtractFileAsync(
|
||||
"verbose_document.pdf",
|
||||
config
|
||||
);
|
||||
|
||||
var original = result.Metadata.ContainsKey("original_token_count")
|
||||
? (int)result.Metadata["original_token_count"]
|
||||
: 0;
|
||||
|
||||
var reduced = result.Metadata.ContainsKey("token_count")
|
||||
? (int)result.Metadata["token_count"]
|
||||
: 0;
|
||||
|
||||
var ratio = result.Metadata.ContainsKey("token_reduction_ratio")
|
||||
? (double)result.Metadata["token_reduction_ratio"]
|
||||
: 0.0;
|
||||
|
||||
Console.WriteLine($"Reduced from {original} to {reduced} tokens");
|
||||
Console.WriteLine($"Reduction: {ratio * 100:F1}%");
|
||||
```
|
||||
Reference in New Issue
Block a user