Verifier
Last line of defence before a cached response is served.
Guards are lexical and free; a verifier is whatever you are willing to pay for. The usual shape is a cheap model asked a yes/no question, which still costs far less than the call being avoided:
val verifier = Verifier { query, cached, _ ->
haiku.complete("Do these two questions have the same correct answer? Reply YES or NO.\nA: $cached\nB: $query")
.trim().startsWith("YES")
}Content copied to clipboard
A verifier only ever sees candidates that already cleared the similarity threshold and every guard, so it runs on a small fraction of lookups. Returning false turns the lookup into a MissReason.REJECTED_BY_VERIFIER miss.
Inheritors
Functions
Link copied to clipboard
fun Verifier.caching(maxEntries: Int = CachingVerifier.DEFAULT_MAX_ENTRIES, ttl: Duration? = null, clock: Clock = Clock.systemUTC()): CachingVerifier
Wraps this verifier in a CachingVerifier that memoizes verdicts per (query, cachedPrompt) pair.