Interface SemanticCacheScopeResolver
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
SemanticCacheAdvisor. Cached responses are only shared between requests that
resolve to the same scope, so the scope must identify the tenant, user or any other
boundary across which responses must not leak.
The scope is typically derived from the authenticated principal or from a value the
application put into the request context, for
example through .advisors(a -> a.param("tenantId", tenantId)). Applications
that deliberately share a single cache across all users can return a constant.
The scope is the only isolation boundary: requests with different system prompts share
cached responses unless the resolver includes the system prompt in the scope, for
example tenantId + "|" + request.prompt().getSystemMessage().getText().
For streaming requests, the resolver may be invoked on a different thread than the one
that issued the request, so thread-bound state such as a security context holder backed
by a ThreadLocal may not be available. Prefer the request context in that case.
- Since:
- 2.0.2
- Author:
- Dimitar Proynov
-
Method Summary
Modifier and TypeMethodDescription@Nullable StringresolveScope(ChatClientRequest request) Resolves the cache scope of the given request.
-
Method Details
-
resolveScope
Resolves the cache scope of the given request.- Parameters:
request- the chat client request- Returns:
- the cache scope, or
nullor a blank string to bypass the cache for this request
-