Package org.codelibs.fess.chat
Class ChatClient
java.lang.Object
org.codelibs.fess.chat.ChatClient
Client class for RAG (Retrieval-Augmented Generation) chat functionality.
Orchestrates the multi-phase RAG workflow including session management,
document search, and delegation to LlmClientManager for LLM operations.
Prompt construction and LLM-specific logic is handled by LlmClient implementations.
- Author:
- FessProject
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classResult of a chat request.protected static classSearch request parameters for RAG chat context retrieval. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ChatSessionManagerThe session manager for managing chat sessions.protected LlmClientManagerThe LLM client manager for language model interactions.protected MarkdownRendererThe markdown renderer for converting markdown to safe HTML. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionPerforms a chat request with RAG.protected StringescapeHtml(String text) Escapes HTML special characters.protected List<LlmMessage> extractHistory(ChatSession session) Extracts conversation history from a chat session as LlmMessage list.fetchFullContent(List<String> docIds) Fetches full document content for the given document IDs.protected intGets the maximum number of history messages to retain.booleanChecks if RAG chat is available.protected StringrenderMarkdownToHtml(String markdown) Renders markdown text to sanitized HTML.searchByUrl(String url) Searches for documents by URL.searchDocuments(String query) Searches for documents relevant to the user's query.searchWithQuery(String query) Searches documents using a Lucene query.streamChat(String sessionId, String userMessage, String userId, LlmStreamCallback callback) Performs a streaming chat request with RAG.streamChatEnhanced(String sessionId, String userMessage, String userId, ChatPhaseCallback callback) Performs an enhanced streaming chat request with multi-phase RAG flow.
-
Field Details
-
chatSessionManager
The session manager for managing chat sessions. -
llmClientManager
The LLM client manager for language model interactions. -
markdownRenderer
The markdown renderer for converting markdown to safe HTML.
-
-
Constructor Details
-
ChatClient
public ChatClient()Default constructor.
-
-
Method Details
-
isAvailable
public boolean isAvailable()Checks if RAG chat is available.- Returns:
- true if RAG chat is available
-
chat
Performs a chat request with RAG.- Parameters:
sessionId- the session ID (can be null for new sessions)userMessage- the user's messageuserId- the user ID (can be null for anonymous users)- Returns:
- the chat response including session info and sources
-
streamChat
public ChatClient.ChatResult streamChat(String sessionId, String userMessage, String userId, LlmStreamCallback callback) Performs a streaming chat request with RAG.- Parameters:
sessionId- the session ID (can be null for new sessions)userMessage- the user's messageuserId- the user ID (can be null for anonymous users)callback- the callback to receive streaming chunks- Returns:
- the chat result with session info and sources
-
streamChatEnhanced
public ChatClient.ChatResult streamChatEnhanced(String sessionId, String userMessage, String userId, ChatPhaseCallback callback) Performs an enhanced streaming chat request with multi-phase RAG flow. This flow includes: intent detection, keyword search, result evaluation, content retrieval, answer generation, and markdown rendering.- Parameters:
sessionId- the session ID (can be null for new sessions)userMessage- the user's messageuserId- the user ID (can be null for anonymous users)callback- the callback to receive phase notifications and streaming chunks- Returns:
- the chat result with session info, sources, and HTML content
-
extractHistory
Extracts conversation history from a chat session as LlmMessage list.- Parameters:
session- the chat session- Returns:
- the list of LlmMessages representing the conversation history
-
searchWithQuery
Searches documents using a Lucene query.- Parameters:
query- the Lucene query string- Returns:
- the list of search result documents
-
fetchFullContent
Fetches full document content for the given document IDs.- Parameters:
docIds- the document IDs to fetch- Returns:
- list of documents with full content
-
searchByUrl
Searches for documents by URL.- Parameters:
url- the URL to search for- Returns:
- list of documents matching the URL
-
renderMarkdownToHtml
Renders markdown text to sanitized HTML.- Parameters:
markdown- the markdown text- Returns:
- sanitized HTML
-
escapeHtml
Escapes HTML special characters.- Parameters:
text- the text to escape- Returns:
- the escaped text
-
getMaxHistoryMessages
protected int getMaxHistoryMessages()Gets the maximum number of history messages to retain.- Returns:
- the maximum number of history messages
-
searchDocuments
Searches for documents relevant to the user's query.- Parameters:
query- the search query- Returns:
- a list of documents matching the query
-