Lean into provider-native caching (explicit Gemini context caching, docs, visibility)

Abierto
#358 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
35/100
Tipo de issue
Nueva funcionalidad
Claridad
Necesita aclaración
Estado de actividad
Tranquilo
Stack tecnológico
python
Área
ai, documentation

Línea de trabajo

Empieza con _provider_google.py y el nuevo accessor Chat.files; después, compara el manejo de la caché en _provider_anthropic.py y _provider_openai.py. Aclara el diseño de la API para el almacenamiento explícito en caché del contexto de Gemini, la guía de caching y cualquier pequeña exposición de parámetros. Se considera terminado cuando el comportamiento de caching provider-native acordado y la documentación cubran cached_input, los valores predeterminados del proveedor, las ventajas y desventajas del TTL y los prompts compatibles con la caché.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

ai-triage:needs-review enhancement

Motivation

Client-side response caches (LangChain's set_llm_cache, LiteLLM's caching layer) date from early 2023, before Anthropic prompt caching (Aug 2024), OpenAI automatic prompt caching (Oct 2024), or Gemini context caching existed. The providers now solve the underlying cost/latency problem better, and chatlas already leans into that harder than most frameworks:

  • Anthropic/Bedrock: cache="5m" on by default, with cache_control injection and cache-write cost multipliers (1.25×/2×) reflected in get_cost() (_provider_anthropic.py).
  • OpenAI: automatic server-side caching; cached_tokens extracted and priced (_provider_openai.py).
  • Google: implicit-cache token counts tracked (_provider_google.py).
  • get_tokens() / get_cost() expose cached_input as a first-class field; prior art in #103, #133, #158, #243 (all closed).

What remains is closing the gaps, not adding a new cache layer.

Proposed work

  1. Explicit Gemini context caching — the one concrete API gap. Support Google's explicit caching (client.caches.create(...) with a TTL, then reference the cached content across calls). This dovetails with the new Chat.files accessor: same "register once, reference cheaply across turns" model. Whether it surfaces as a chat.files-like accessor, a content type (cf. #136 content_ephemeral()), or a ChatGoogle() parameter is the main design question.
  2. A caching guide in the docs — the current defaults are good but invisible. Cover: what each provider does automatically, how to read cached_input from get_tokens() to check your hit rate, Anthropic TTL tradeoffs ("5m" vs "1h" write multipliers), and how to keep prompts cache-friendly (stable prefix; don't churn the system prompt or tool set mid-conversation).
  3. Small parameter exposure — e.g. OpenAI's prompt_cache_key routing hint for improving hit rates. Low priority for chatlas's typical single-process user, but cheap.
  4. Cross-issue design note — prefix caches reward immutable history, so history compaction (#356) and mutable system prompts are cache-busting operations. The #356 design should account for the one-time cost cliff after a compaction.

Non-goal: client-side response cache

A LangChain-style client-side response cache is out of scope. Its one honest use case — replaying an identical request without paying again (prompt caching discounts input tokens but never eliminates the call or the output tokens) — is better served elsewhere:

  • Notebook/script re-runs: that's a persistence problem — reload the earlier conversation (#352 chat.save()/Chat.load()) instead of re-asking the model.
  • Tests/CI: VCR-style request recording (what chatlas's own test suite uses via pytest-recording) is purpose-built for this.
  • Treating nondeterministic calls as cacheable pure functions also has real surprise potential (a cache silently freezes responses that users expect to vary).

Part of the July 2026 competitive-review workstreams (#360).

Lenguaje dominante
Python
Estrellas
179
Forks
32
Merge medio
1 d 3 h
PR fusionados (30 d)
10

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de posit-dev/chatlas

Todos los issues de posit-dev/chatlas

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.