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

Đang mở
#358 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
35/100
Loại issue
Tính năng
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Ít trao đổi
Công nghệ
python
Lĩnh vực
ai, documentation

Hướng nghiên cứu

Bắt đầu với _provider_google.py và accessor Chat.files mới, sau đó so sánh cách xử lý cache trong _provider_anthropic.py và _provider_openai.py. Làm rõ thiết kế API cho việc cache ngữ cảnh Gemini một cách tường minh, hướng dẫn caching và bất kỳ việc expose tham số nhỏ nào. Được xem là hoàn tất khi hành vi caching provider-native đã thống nhất và tài liệu bao quát cached_input, các giá trị mặc định của provider, các đánh đổi của TTL và các prompt thân thiện với cache.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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).

Ngôn ngữ chính
Python
Star
179
Fork
32
Merge trung bình
1 ngày 3 giờ
Pull request đã merge (30 ngày)
10

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của posit-dev/chatlas

Tất cả issue của posit-dev/chatlas

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.