summaryrefslogtreecommitdiff
path: root/source/net
diff options
context:
space:
mode:
authorMichael Peter Christen <mc@yacy.net>2026-03-29 00:19:57 +0100
committerMichael Peter Christen <mc@yacy.net>2026-03-29 00:19:57 +0100
commitc79b7a19c8d6e9679219bc5f64bd34daa2ae2574 (patch)
treea9f1084ce8cd426bd70b1727dc53425c6ae9df7c /source/net
parenta9a365bc7503aeae921c9195304b54c9c78b85da (diff)
Add configurable maximum length for RAG search documents
Diffstat (limited to 'source/net')
-rw-r--r--source/net/yacy/ai/RAGAugmentor.java22
-rw-r--r--source/net/yacy/htroot/RAGConfig_p.java4
2 files changed, 24 insertions, 2 deletions
diff --git a/source/net/yacy/ai/RAGAugmentor.java b/source/net/yacy/ai/RAGAugmentor.java
index 71b285504..a2dde813c 100644
--- a/source/net/yacy/ai/RAGAugmentor.java
+++ b/source/net/yacy/ai/RAGAugmentor.java
@@ -68,11 +68,28 @@ import net.yacy.search.snippet.TextSnippet;
*/
public final class RAGAugmentor {
+ public static final String SEARCH_DOCUMENT_MAX_LENGTH_CONFIG = "ai.rag.search-document-maxlength";
+ public static final int SEARCH_DOCUMENT_MAX_LENGTH_DEFAULT = 30000;
+
/**
* Utility class; not instantiable.
*/
private RAGAugmentor() {}
+ public static int configuredSearchDocumentMaxLength() {
+ final Switchboard sb = Switchboard.getSwitchboard();
+ if (sb == null) return SEARCH_DOCUMENT_MAX_LENGTH_DEFAULT;
+ final long configured = sb.getConfigLong(SEARCH_DOCUMENT_MAX_LENGTH_CONFIG, SEARCH_DOCUMENT_MAX_LENGTH_DEFAULT);
+ if (configured <= 0) return SEARCH_DOCUMENT_MAX_LENGTH_DEFAULT;
+ return configured > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) configured;
+ }
+
+ private static String truncateSearchDocument(final String markdown) {
+ if (markdown == null || markdown.isEmpty()) return "";
+ final int maxLength = configuredSearchDocumentMaxLength();
+ return markdown.length() <= maxLength ? markdown : markdown.substring(0, maxLength);
+ }
+
/**
* Executes local index search.
*
@@ -117,8 +134,9 @@ public final class RAGAugmentor {
} catch (JSONException e) {}
}
- ConcurrentLog.info("RAGProxy", "markdownChars=" + sb.length() + " resultCount=" + searchResults.length());
- return sb.toString();
+ final String markdown = truncateSearchDocument(sb.toString());
+ ConcurrentLog.info("RAGProxy", "markdownChars=" + markdown.length() + " resultCount=" + searchResults.length());
+ return markdown;
}
/**
diff --git a/source/net/yacy/htroot/RAGConfig_p.java b/source/net/yacy/htroot/RAGConfig_p.java
index 819d9832d..23a5beabe 100644
--- a/source/net/yacy/htroot/RAGConfig_p.java
+++ b/source/net/yacy/htroot/RAGConfig_p.java
@@ -18,10 +18,13 @@ public class RAGConfig_p {
final String systemPrompt = post.get("ai.system-prompt", "").trim();
final String userPrefix = post.get("ai.llm-user-prefix", "").trim();
final String queryPrefix = post.get("ai.llm-query-generator-prefix", "").trim();
+ int searchDocumentMaxLength = post.getInt(net.yacy.ai.RAGAugmentor.SEARCH_DOCUMENT_MAX_LENGTH_CONFIG, net.yacy.ai.RAGAugmentor.SEARCH_DOCUMENT_MAX_LENGTH_DEFAULT);
+ if (searchDocumentMaxLength <= 0) searchDocumentMaxLength = net.yacy.ai.RAGAugmentor.SEARCH_DOCUMENT_MAX_LENGTH_DEFAULT;
sb.setConfig("ai.system-prompt", systemPrompt);
sb.setConfig("ai.llm-user-prefix", userPrefix);
sb.setConfig("ai.llm-query-generator-prefix", queryPrefix);
+ sb.setConfig(net.yacy.ai.RAGAugmentor.SEARCH_DOCUMENT_MAX_LENGTH_CONFIG, Integer.toString(searchDocumentMaxLength));
}
// mark page as visited for gamification/quest tracking
@@ -30,6 +33,7 @@ public class RAGConfig_p {
prop.put("ai.system-prompt", sb.getConfig("ai.system-prompt", net.yacy.http.servlets.RAGProxyServlet.LLM_SYSTEM_PROMPT_DEFAULT));
prop.put("ai.llm-user-prefix", sb.getConfig("ai.llm-user-prefix", "\n\nAdditional Information:\n\nbelow you find a collection of texts that might be useful to generate a response. Do not discuss these documents, just use them to answer the question above.\n\n"));
prop.put("ai.llm-query-generator-prefix", sb.getConfig("ai.llm-query-generator-prefix", "Make a list of search words with low document frequency for the following prompt; use a JSON Array: "));
+ prop.put("ai.rag.search-document-maxlength", sb.getConfig(net.yacy.ai.RAGAugmentor.SEARCH_DOCUMENT_MAX_LENGTH_CONFIG, Integer.toString(net.yacy.ai.RAGAugmentor.SEARCH_DOCUMENT_MAX_LENGTH_DEFAULT)));
return prop;
}