From 209e246e6f5fce408421eb30001c1886885aee5a Mon Sep 17 00:00:00 2001
From: thiswillbeyourgithub
<26625900+thiswillbeyourgithub@users.noreply.github.com>
Date: Thu, 12 Sep 2024 15:31:49 +0200
Subject: [PATCH] fix: much improved RAG template
---
backend/open_webui/config.py | 24 +++++++++++++++---------
1 file changed, 15 insertions(+), 9 deletions(-)
diff --git a/backend/open_webui/config.py b/backend/open_webui/config.py
index 5ccb40d47..c87256a08 100644
--- a/backend/open_webui/config.py
+++ b/backend/open_webui/config.py
@@ -1085,19 +1085,25 @@ CHUNK_OVERLAP = PersistentConfig(
int(os.environ.get("CHUNK_OVERLAP", "100")),
)
-DEFAULT_RAG_TEMPLATE = """Use the following context as your learned knowledge, inside XML tags.
+DEFAULT_RAG_TEMPLATE = """You are given a user query, some textual context and rules, all inside xml tags. You have to answer the query based on the context while respecting the rules.
+
- [context]
+[context]
-When answer to user:
-- If you don't know, just say that you don't know.
-- If you don't know when you are not sure, ask for clarification.
-Avoid mentioning that you obtained the information from the context.
-And answer according to the language of the user's question.
+
+- If you don't know, just say so.
+- If you are not sure, ask for clarification.
+- Answer in the same language as the user query.
+- If the context appears unreadable or of poor quality, tell the user then answer as best as you can.
+- If the answer is not in the context but you think you know the answer, explain that to the user then answer with your own knowledge.
+- Answer directly and without using xml tags.
+
-Given the context information, answer the query.
-Query: [query]"""
+
+[query]
+
+"""
RAG_TEMPLATE = PersistentConfig(
"RAG_TEMPLATE",