Package org.codelibs.fess.chat
Class DefaultChatContentFetcher
java.lang.Object
org.codelibs.fess.chat.DefaultChatContentFetcher
- All Implemented Interfaces:
ChatContentFetcher
Default
ChatContentFetcher. Dispatches per document by
content_length: small documents are fetched in full (existing
behavior), large documents use query-relevant highlighted passages so the
relevant section reaches the LLM. Highlight snippets are normalized into the
content field so the downstream context builder is unchanged. A large
document with no extractable highlight passage falls back to its full content
truncated to the threshold; its short digest is never used as a passage.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classChat search params restricted to specific doc ids, using the answer-specific highlight settings (rag.chat.answer.highlight.*) instead of the display-orientedrag.chat.highlight.*.protected static enumPer-document content resolution strategy. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuildSizeMap(List<Map<String, Object>> searchResults) Builds a doc_id -> content_length map from the search-phase results.protected DefaultChatContentFetcher.StrategydecideStrategy(String docId, Long contentLength, ChatContentRequest request) Decides the fetch strategy for a document.fetchContent(ChatContentRequest request) Resolves the LLM-context content for the given relevant documents.fetchFullContent(List<String> docIds) Fetches full content for the given document ids via doc_id lookup (no highlighting).fetchHighlightedContent(List<String> docIds, String query) Fetches query-relevant highlighted passages for large documents via a doc_id-restricted highlighted search, normalizing the snippet into thecontentfield.protected longReturns the content_length threshold above which highlighted passages are used.protected StringReturns the document-map key that holds the highlight passage for the content field (the highlight prefix joined with the content field name, e.g.normalizeHighlightedDocs(List<Map<String, Object>> docs) Normalizes highlighted search results: copies the highlight passage into thecontentfield, and drops documents that produced no highlight passage so the caller can fall back to their truncated full content.protected LongConverts a value to Long, tolerating Number and numeric String.protected voidtruncateContent(Map<String, Object> doc, long maxLength) Truncates thecontentfield of a document to at mostmaxLengthcharacters, keeping the leading portion.
-
Constructor Details
-
DefaultChatContentFetcher
public DefaultChatContentFetcher()Default constructor.
-
-
Method Details
-
fetchContent
Description copied from interface:ChatContentFetcherResolves the LLM-context content for the given relevant documents.- Specified by:
fetchContentin interfaceChatContentFetcher- Parameters:
request- the fetch request (doc ids, search results, query)- Returns:
- document maps in the same order as
request.getDocIds(), each with thecontentfield set to the text to send to the LLM
-
decideStrategy
protected DefaultChatContentFetcher.Strategy decideStrategy(String docId, Long contentLength, ChatContentRequest request) Decides the fetch strategy for a document.- Parameters:
docId- the document idcontentLength- the indexed content length (null if unknown)request- the fetch request- Returns:
DefaultChatContentFetcher.Strategy.HIGHLIGHTfor large documents, otherwiseDefaultChatContentFetcher.Strategy.FULL
-
getFulltextThreshold
protected long getFulltextThreshold()Returns the content_length threshold above which highlighted passages are used.- Returns:
- the threshold in characters
-
truncateContent
Truncates thecontentfield of a document to at mostmaxLengthcharacters, keeping the leading portion. Used as the fallback for a large document that produced no highlight passage so it still contributes a leading excerpt without crowding out the answer context.- Parameters:
doc- the document map (modified in place)maxLength- the maximum content length in characters
-
buildSizeMap
Builds a doc_id -> content_length map from the search-phase results.- Parameters:
searchResults- the search-phase result maps (may be null)- Returns:
- the size map (empty when searchResults is null/empty)
-
toLong
Converts a value to Long, tolerating Number and numeric String.- Parameters:
value- the value- Returns:
- the Long value, or null if not convertible
-
fetchFullContent
Fetches full content for the given document ids via doc_id lookup (no highlighting).- Parameters:
docIds- the document ids- Returns:
- document maps (unordered)
-
fetchHighlightedContent
Fetches query-relevant highlighted passages for large documents via a doc_id-restricted highlighted search, normalizing the snippet into thecontentfield. Returns empty on failure (callers fall back to full).- Parameters:
docIds- the large-document idsquery- the highlight query- Returns:
- document maps with
contentset to the highlighted snippet
-
normalizeHighlightedDocs
Normalizes highlighted search results: copies the highlight passage into thecontentfield, and drops documents that produced no highlight passage so the caller can fall back to their truncated full content.The passage is read from the raw highlight field (
hl_content), not fromcontent_description.content_descriptionis built byViewHelper#getContentDescriptionfromhl_content,digestand therefore falls back to the short crawl-timedigestwhen there is no highlight match; relying on it would mask the "no passage" case and send the digest to the LLM instead of the truncated full-content fallback. Reading the highlight field directly keeps that case detectable.- Parameters:
docs- the highlighted search result maps- Returns:
- maps that produced a highlight passage only, each with
contentset to it
-
getHighlightContentField
Returns the document-map key that holds the highlight passage for the content field (the highlight prefix joined with the content field name, e.g.hl_content).- Returns:
- the highlight content field key
-