Files
fil/docs/snippets/elixir/advanced/token_reduction_example.md
Henrik Jess Nielsen b4c07d3693
All checks were successful
Deploy fil (kreuzberg) / deploy (push) Successful in 49s
Nomad changes
2026-06-01 23:40:55 +02:00

737 B

config_json = Jason.encode!(%{
  "token_reduction" => %{
    "mode" => "moderate",
    "preserve_markdown" => true
  }
})

{:ok, result} = Kreuzberg.extract_file_sync("verbose_document.pdf", "application/pdf", config_json)

# Display token reduction metrics
original = result.original_token_count || 0
reduced = result.reduced_token_count || 0

IO.puts("Original tokens: #{original}")
IO.puts("Reduced tokens: #{reduced}")

if original > 0 do
  reduction_percent = Float.round((1 - reduced / original) * 100, 2)
  IO.puts("Reduction: #{reduction_percent}%")
end

# Show sample of reduced text
if result.text do
  IO.puts("\nSample of reduced text:")
  IO.puts(String.slice(result.text, 0..200) <> "...")
end