| name | skill-rag-retrieve |
| description | RAG vector database retrieval with evidence scoring. Query ES index by company_id, filter hits by keywords and must_terms, score by relevance, return top-N evidence snippets. |
RAG Retrieval + Evidence Scoring
Purpose
Retrieve relevant evidence from the RAG vector database (Elasticsearch) for each report section, and score evidence by relevance to the section's keywords and mandatory terms.
Process
0. Map Chapter Names (before first retrieve)
Before calling ivr_search_rag, translate Chinese chapter names from the chapter skill's "来源" descriptions into section_id values:
- Call
ivr_get_prospectus_chapter_map(task_id) to get the mapping: [{chapter_title, chapter_code, page_start, page_end}, ...].
- Match the skill's Chinese chapter name (e.g. "业务和技术", "财务会计信息") against
chapter_title using substring/fuzzy matching.
- ⛔ Do NOT pass
limit_chapter — ES chapter_code is the prospectus original chapter number (e.g. ch4=发行人基本情况), NOT the IVR report chapter number (e.g. ch4=行业分析). Passing limit_chapter will match the WRONG chapter.
- ✅ Use
section_id from the 子节索引对照表 for precise filtering. If section_id is unavailable, search by query + company_id without limit_chapter.
Example: Skill says 来源:招股说明书「业务和技术」 → call ivr_get_prospectus_chapter_map → match chapter_title: "第六节 业务和技术" → use section_id from the matched chapter's subsections, NOT limit_chapter.
1. Retrieve
- Query the ES index filtered by
company_id
- Search for content matching the section's
keywords
- Retrieve up to
retrieval.rag hits per section (configurable, default 5)
2. Score Evidence
Each evidence snippet is scored:
- +6 points if it contains a
must_term (section-specific mandatory terms)
- +2 points for each matching
keyword
- +1 point if source is a PDF from the company's uploaded documents
3. Filter
- Discard evidence with score < 2
- Deduplicate by source + content fingerprint
- Return top-N results sorted by score descending
4. Output Format
For each evidence item returned by ivr_search_rag:
content: full text snippet from the PDF (use this for writing)
source: source document filename or identifier
page_no: page number in the source PDF
chapter_code: chapter the chunk belongs to (e.g. "ch4"), or null
section_id: section identifier (e.g. "sec_2_5"), or null — use this from the 子节索引对照表 for precise filtering
breadcrumb: hierarchical path (e.g. "正文 > 第五节 业务和技术"), or null
score: relevance score (0-1)
type: "text" or "image"
img_url: image file URL (for type: "image" results) — use  in markdown
caption: image caption (for type: "image" results)
figure_number: figure/table number (for type: "image" results)
Precise filtering: Prefer section_id from the 子节索引对照表 over fuzzy section_name matching. Example: use section_id="sec_2_5" instead of guessing limit_chapter="ch4".
5. Image Insertion(铁律)
⛔ 最高优先级铁律:每个小节写作前,必须先调用 ivr_fetch_section(section_id="xxx", need_img=True) 拉取该小节全部图片(含无 caption 的技术图、流程图、股权图),再开始写作。ivr_search_rag 的语义搜索无法命中 caption 为空的技术图表——只有 ivr_fetch_section 按页码范围拉取可以。跳过此步骤直接写作 = 违规,必须驳回重写。
写作流程(强制顺序):
- 先拉图:对当前小节调用
ivr_fetch_section(section_id="xxx", need_img=True),获取 img_list
- 再检索:调用
ivr_search_rag 获取文本证据片段
- 后写作:将
img_list 中的每张图片用  格式插入对应段落下方
- 最后保存:调用
ivr_save_chapter_content
配图规范:
- MUST insert:
img_list 中每张图都必须插入,不得遗漏
- Caption fallback: 如果
caption 为空,用 [图表 p{page}] 作为 alt text
- Placement rule: 根据图片的
page 和 figure_number 确定插入位置,放在最近的相关段落下方
- Dedup: 跳过与已插入图片相同
url 的重复图片
- No fabricated images: 只使用
img_list 返回的图片,禁止自创 URL
Example:
公司核心技术平台具有全球领先优势...

*来源:招股书 P8*
Anti-Patterns
- Do NOT fabricate evidence when no RAG results found
- Do NOT use the same evidence snippet for multiple sections
- Do NOT skip the scoring step — unscreened evidence produces hallucinations
- Do NOT ignore
type: "image" results — they MUST be inserted as  in the chapter content