Package org.codelibs.fess.chat
Interface ChatPhaseCallback
public interface ChatPhaseCallback
Callback interface for receiving notifications about chat processing phases.
Used for SSE streaming to notify clients about the current processing state.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic ChatPhaseCallbacknoOp()Returns a no-op callback implementation.voidCalled when a chunk of the response is available during streaming.voidCalled when an error occurs during processing.default voidonFallback(String phase, String reason, String originalQuery, String newQuery) Called when the search query is regenerated due to no or no-relevant results.voidonPhaseComplete(String phase) Called when a processing phase completes.default voidonPhaseComplete(String phase, Map<String, Object> payload) Called when a processing phase completes with metadata payload (e.g., hit counts).voidonPhaseStart(String phase, String message) Called when a processing phase starts.default voidonPhaseStart(String phase, String message, String keywords) Called when a processing phase starts with additional context data.default voidCalled when the underlying LLM call is being retried.default voidCalled when the request is waiting for a concurrency permit.default voidCalled when an internal silent fallback occurs (e.g., reasoning model token exhaustion).
-
Field Details
-
PHASE_INTENT
Phase name for intent detection- See Also:
-
PHASE_SEARCH
Phase name for document search- See Also:
-
PHASE_EVALUATE
Phase name for result evaluation- See Also:
-
PHASE_FETCH
Phase name for content retrieval- See Also:
-
PHASE_ANSWER
Phase name for answer generation- See Also:
-
-
Method Details
-
onPhaseStart
Called when a processing phase starts.- Parameters:
phase- the phase name (e.g., "intent", "search", "evaluate", "fetch", "answer")message- a human-readable message describing what's happening
-
onPhaseStart
Called when a processing phase starts with additional context data.- Parameters:
phase- the phase name (e.g., "intent", "search", "evaluate", "fetch", "answer")message- a human-readable message describing what's happeningkeywords- the search keywords (for search phase)
-
onPhaseComplete
Called when a processing phase completes.- Parameters:
phase- the phase name that completed
-
onPhaseComplete
Called when a processing phase completes with metadata payload (e.g., hit counts). Default implementation delegates toonPhaseComplete(String)ignoring the payload.- Parameters:
phase- the phase name that completedpayload- optional metadata such ashitCount; never null
-
onChunk
Called when a chunk of the response is available during streaming.- Parameters:
content- the content chunkdone- true if this is the final chunk
-
onError
Called when an error occurs during processing.- Parameters:
phase- the phase where the error occurrederror- the error message
-
onRetry
default void onRetry(String phase, String operation, int attempt, int maxAttempts, long sleepMs, String cause) Called when the underlying LLM call is being retried.- Parameters:
phase- the phase where the retry occursoperation- log label for the LLM operation (e.g., "streamChat")attempt- 1-based attempt index that just failedmaxAttempts- total attempts including the firstsleepMs- milliseconds the client will sleep before the next attemptcause- short cause description (e.g., "status:429" or "exception:IOException")
-
onWaiting
Called when the request is waiting for a concurrency permit.- Parameters:
phase- the phase where waiting occursreason- short reason code (currently always "concurrency_limit")elapsedMs- milliseconds already spent waitingtimeoutMs- maximum milliseconds the client will wait
-
onFallback
Called when the search query is regenerated due to no or no-relevant results.- Parameters:
phase- the phase where fallback occurs (typically "search")reason- short reason code (e.g., "no_results", "no_relevant_results")originalQuery- the query that produced no useful resultsnewQuery- the regenerated query that will be retried
-
onWarning
Called when an internal silent fallback occurs (e.g., reasoning model token exhaustion).- Parameters:
phase- the phase where the warning occurredcode- short machine-readable warning code (e.g., "reasoning_token_exhausted")detail- short human-readable detail or related fallback action
-
noOp
Returns a no-op callback implementation.- Returns:
- a callback that does nothing
-