From 23df1bf89b4fc3c10af906bc1a2af07e42bb6651 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E6=BD=AE?= Date: Thu, 7 May 2026 19:47:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8F=AC=E5=9B=9E=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E8=AF=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ragflow-loader/hooks/retrieval-policy.md | 67 +++++++++++++++++-- 1 file changed, 60 insertions(+), 7 deletions(-) diff --git a/skills/linggan/ragflow-loader/hooks/retrieval-policy.md b/skills/linggan/ragflow-loader/hooks/retrieval-policy.md index bf915b8..b41e660 100644 --- a/skills/linggan/ragflow-loader/hooks/retrieval-policy.md +++ b/skills/linggan/ragflow-loader/hooks/retrieval-policy.md @@ -1,31 +1,84 @@ # Retrieval Policy +## 0. Task Classification + +Classify the request before acting: +- **Knowledge retrieval** (facts, summaries, comparisons, lists, timelines, extraction, etc.): follow this policy strictly. +- **Codebase engineering** (modify/debug/inspect code): normal tools (Glob, Read, Grep, Bash) allowed. +- **Mixed**: use retrieval tools for the knowledge portion, code tools for the code portion only. +- **Uncertain**: default to knowledge retrieval. + +## 1. Critical Enforcement + +For knowledge retrieval tasks, **this policy overrides generic codebase exploration behavior**. + +- **Prohibited tools**: `Glob`, `Read`, `LS`, Bash (`ls`, `find`, `cat`, `head`, `tail`, `grep`, etc.) — these are forbidden even when retrieval results are empty/insufficient, even if local files seem helpful. +- **Allowed tool only**: `rag_retrieve`. No other source for factual answering. +- Local filesystem is a **prohibited** knowledge source, not merely non-recommended. +- Exception: user explicitly asks to read a specific local file as the task itself. + +## 2. Retrieval Order + - `rag_retrieve` is the only knowledge source. - Do NOT answer from model knowledge first. -## 1.Query Preparation +## 3. Query Preparation + - Do NOT pass the raw user question unless it already works well for retrieval. - Rewrite for recall: extract entity, time scope, attributes, and intent. - Add useful variants: synonyms, aliases, abbreviations, related titles, historical names, and category terms. - Expand list-style, extraction, overview, historical, roster, timeline, and archive queries more aggressively. - Preserve meaning. Do NOT introduce unrelated topics. -## 2.Retrieval Breadth (`top_k`) +## 4. Retrieval Breadth (`top_k`) + - Apply `top_k` only to `rag_retrieve`. Use the smallest sufficient value, then expand only if coverage is insufficient. - Use `30` for simple fact lookup. - Use `50` for moderate synthesis, comparison, summarization, or disambiguation. - Use `100` for broad recall, such as comprehensive analysis, scattered knowledge, multiple entities or periods, or list / catalog / timeline / roster / overview requests. - Raise `top_k` when keyword branches are many or results are too few, repetitive, incomplete, sparse, or too narrow. -- Use this expansion order: `30 -> 50 -> 100`. If unsure, use `100`. +- Use this expansion order: `30 → 50 → 100`. If unsure, use `100`. -## 3.Retry -- If the result is insufficient, retry `rag_retrieve` with a better rewritten query or a larger `top_k`. -- Only say no relevant information was found after `rag_retrieve` has been tried and still provides insufficient evidence. +## 5. Result Evaluation + +Treat as insufficient if: empty, `Error:`, off-topic, missing core entity/scope, no usable evidence, partial coverage, or truncated results. + +## 6. Fallback and Sequential Retry + +On insufficient results, follow this sequence: + +1. Rewrite query, retry `rag_retrieve` (once) +2. Expand `top_k`: `30 → 50 → 100` +3. Say "no relevant information was found" **only after** exhausting all retries. +- Do NOT switch to local filesystem inspection at any point. + +## 7. Image Handling -## 4.Image Handling - The content returned by the `rag_retrieve` tool may include images. - Each image is exclusively associated with its nearest text or sentence. - If multiple consecutive images appear near a text area, all of them are related to the nearest text content. - Do NOT ignore these images, and always maintain their correspondence with the nearest text. - Each sentence or key point in the response should be accompanied by relevant images when they meet the established association criteria. - Avoid placing all images at the end of the response. + +## 8. Controlled Self-Knowledge Supplement + +This section applies only when self-knowledge is enabled. + +- Retrieval remains the primary source. +- If retrieval is sufficient, answer from retrieval only. +- If retrieval is partially sufficient, answer the supported parts first. +- The model may supplement only the missing parts that are general knowledge, conceptual explanation, or common background. +- The model must not use self-knowledge to invent private, internal, current, precise, or source-sensitive facts. +- The model must not use self-knowledge to invent or complete prices, fees, discounts, rankings, internal policies, user-specific details, current status, latest updates, exact numbers, dates, metrics, or specifications. +- Retrieved facts and self-knowledge supplements must be clearly separated in the response. +- If self-knowledge may be uncertain or time-sensitive, state the uncertainty explicitly. + +## 9. Pre-Reply Self-Check + +Before replying to a knowledge retrieval task, verify: +- Used only `rag_retrieve` — no local filesystem inspection? +- Exhausted retrieval flow (rewritten query + expanded `top_k`) before concluding "not found"? +- If self-knowledge was used, was it clearly separated from retrieved facts and limited to allowed supplement scope? + +If any answer is "no", correct the process first.