RideLink
← All blogs

Slash Your AI Costs: How We Achieved a 45% Token Reduction with TOON and Smart Caching

RideLink ·

In the rapidly evolving world of AI, optimizing performance and cost efficiency is paramount.

At Ridelink with Adrian AI, we’re constantly pushing the boundaries to deliver the best logistics solutions, and a key part of that involves meticulously managing our token usage.

We’re thrilled to share how our implementation of TOON (Token Oriented Object Notation) and a sophisticated caching strategy has resulted in a remarkable 45% reduction in token consumption, significantly cutting costs for our users.

The challenge with large language models (LLMs) is that every piece of information processed, every “token,” contributes to the operational cost. As our solutions become more complex and sophisticated, the volume of data handled by the model increases, leading to higher token usage.

We knew there had to be a more efficient way.

The Power of TOON: A Lightweight Language for LLMs.

Our biggest breakthrough came with the integration of TOON.

Traditional data formats like JSON, while universally understood, can be verbose.

They often contain redundant characters (like quotation marks, commas, and curly braces) that, while necessary for human readability and strict parsing, translate into additional tokens for an LLM.

TOON tackles this head-on by converting JSON into a highly optimized, lightweight syntax.

Think of it as a condensed version of JSON, retaining all the crucial information but stripping away the unnecessary “fluff” from a token perspective.

The model can interpret this streamlined syntax with greater efficiency, leading to a substantial reduction in the number of tokens required to represent the same data.

How does it work?

Imagine a JSON object representing a simple order:

When converted to TOON, this might look something like:

The difference in token count, especially with larger and more complex data structures, is dramatic.

This seemingly simple change has been a game-changer, achieving approximately a 45% reduction in token usage for us. This translates directly into significant cost savings and faster processing for our users.

The Strategic Art of Caching

Beyond TOON, we’ve implemented a robust caching strategy to further minimize token consumption.

Caching allows us to store frequently accessed data or model responses, so we don’t have to re-process the same information repeatedly. We employ two main types of caching:

Explicit Caching: This is where we have direct control. We identify specific data or responses that are likely to be reused and proactively store them in our cache.

For example, if a user frequently requests a certain tax calculation, we can cache the results and serve them instantly on subsequent requests, bypassing the LLM entirely. This provides predictable and significant cost savings.

Implicit Caching: This refers to caching mechanisms that are often built into the LLM infrastructure itself or are managed by underlying services.

While this can also reduce token usage, we have less direct control over what gets cached and when.

This makes optimization somewhat unpredictable, and we’re actively monitoring patterns to better understand and leverage its benefits.

Implementing Your Own Token Reduction Strategy

Inspired by our success? Here’s how you can start implementing similar token reduction strategies in your own AI applications:

  1. Investigate Data Serialization: Look closely at how you’re sending data to your LLM. Are you using verbose formats like JSON by default? Research and experiment with more token-efficient serialization methods. While a custom TOON implementation might be complex, even simple changes like removing unnecessary whitespace or using shorter keys can make a difference.
  2. Explore Existing Libraries/Tools: There might be existing libraries or tools designed to optimize data for LLMs. Look for tokenization best practices specific to the models you are using.

Implement Smart Caching:

Identify Frequent Requests: Analyze your application’s usage patterns to pinpoint data or responses that are requested repeatedly.

Prioritize Explicit Caching: Whenever possible, implement explicit caching for these frequent requests. Use a robust caching solution (e.g., Redis, in-memory caches) to store and retrieve data quickly.

Monitor and Iterate: Continuously monitor your token usage and cache hit rates. This data will help you refine your caching strategy and identify further optimization opportunities.

Prompt Engineering: Beyond data formatting, how you structure your prompts can also impact token usage. Be concise, clear, and avoid unnecessary conversational filler in your prompts.

The Bottom Line

In logistics, every percentage point of efficiency matters. Our token reduction strategy demonstrates our commitment to delivering not just powerful AI capabilities but smart, cost-effective solutions that make sense for your bottom line.

By implementing TOON and strategic caching, we’ve proven that cutting-edge AI technology doesn’t have to come with cutting-edge costs.

Adrian AI provides the most cost-effective logistics intelligence on the market because we’ve engineered efficiency into our DNA.

By Clinton Mugisha

Quote with Adrian

Where are we shipping?

Freight preference

Adrian opens in a new tab with your route and cargo details.