Skip to content

Cache: fix key to be request-based, not Example-based #71

@darinkishore

Description

@darinkishore

Problem

dspy-rs caches LM responses keyed on Vec<(String, Value)> derived from the Example struct. This is semantically wrong:

  • Same logical request through different Example shapes = cache miss
  • The cache should key on the actual formatted request (messages + params), not the pre-formatting input

DSPy Python keys on SHA256(json(request_params)) with ignored args stripped (api_key, api_base, etc.), which correctly caches at the LM request boundary.

What's needed

  • Cache key = hash of (model, messages, temperature, max_tokens, tools, ...) — the actual CompletionRequest
  • Strip non-deterministic fields (api_key, timestamps) from key
  • Consider rollout_id semantics for cache-busting during optimization (DSPy uses this when temperature > 0)
  • CacheEntry should store raw response + metadata, not Prediction

Related

  • data storage #55 (data storage)
  • History decoupling (history should be separate from cache)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions