AI Sheet Cache 🟑 BETA

Intelligent caching for AI-powered spreadsheet formulas

Overview

The AI Sheet Cache provides an asynchronous evaluation pipeline for =BOT_AI_PROMPT() formulas inside spreadsheets. Each formula invocation is cached using a SHA256 hash of the prompt template and referenced cell values, preventing redundant LLM API calls and reducing costs.

Architecture

User edits cell with =BOT_AI_PROMPT()
  β”‚
  β–Ό
Formula Parser (botsheet-core)
  β”‚
  β–Ό
  β”œβ”€β”€ SHA256 cache key (prompt + cell values)
  β”œβ”€β”€ Cache hit β†’ return cached result immediately
  └── Cache miss β†’
       β”œβ”€β”€ Acquire Semaphore (max 10 concurrent)
       β”œβ”€β”€ Call LLM API
       β”œβ”€β”€ Store in cache
       └── Return result

BOT_AI_PROMPT Formula

=BOT_AI_PROMPT("Analyze the tone of: ", A2)
=BOT_AI_PROMPT("Translate to Portuguese: ", B2)
=BOT_AI_PROMPT("Summarize in 3 bullet points: ", C2, D2)

The formula parser extracts all cell references as dependencies. When referenced cells change, the cached result is invalidated automatically.

Cache Layer

PropertyValue
Key algorithmSHA256
Key componentsPrompt template + referenced cell values + model name
BackendValkey (Redis-compatible)
TTLPermanent until referenced cells change
Rate limitingTokio Semaphore (max 10 concurrent LLM calls)

Batch Evaluation

EndpointMethodDescription
/api/sheet/ai/evaluatePOSTEvaluate a single AI formula
/api/sheet/ai/batch-evaluatePOSTBatch evaluate up to 100 formulas

Batch request format:

{
  "cells": [
    { "prompt": "Analyze: ", "values": ["Great product!"] },
    { "prompt": "Translate: ", "values": ["Hello world"] }
  ]
}

Batch response:

{
  "results": [
    { "index": 0, "value": "Positive feedback", "cached": false },
    { "index": 1, "value": "OlΓ‘ mundo", "cached": true }
  ]
}

Cost Controls

  • Maximum batch size: 100 formulas per request
  • Concurrent LLM requests: 10 (configurable via Semaphore)
  • Cache TTL: configurable per-bot via config.csv
  • Error cells render #VALUE! or #TIMEOUT! β€” never crash

UI Integration

The Sheet app (see Sheet - Spreadsheets) renders a loading state (...) while AI formulas are being evaluated, then swaps the cell content via HTMX when the result is ready.

Configuration

config.csv keyDescriptionDefault
sheet-ai-enabledEnable AI formulastrue
sheet-ai-max-batchMax batch size100
sheet-ai-concurrencyMax concurrent LLM calls10
sheet-ai-cache-ttlCache TTL in seconds86400

Feature Flag

Enable with sheet feature flag in Cargo.toml:

botserver = { features = ["sheet"] }