Polyglot \ Advanced
Context Caching
How to use context caching in Polyglot
Context caching improves performance by reusing parts of a conversation, reducing token usage and API costs. This is particularly useful for multi-turn conversations or when processing large documents.
Using Cached Context
Polyglot supports context caching through the withCachedContext()
method:
Provider Support for Context Caching
Different providers have varying levels of support for context caching:
- Anthropic: Supports native context caching with explicit cache markers
- OpenAI: Provides automatic caching for optimization, but not as explicit as Anthropic
- Other providers: May not support native caching, but Polyglot still helps manage conversation state
Processing Large Documents with Cached Context
Context caching is particularly valuable when working with large documents: