SuperAPI AI Directory

lark-workflow-knowledge-qa

Office & productivity

View repository

Updated 10-16 08:52

About this skill

Knowledge Base Q&A Workflow

CRITICAL — Before starting, you MUST first use the Read tool to read lark-shared/SKILL.md, which contains authentication, permission handling, and security rules.

Applicable Scenarios

  • "What does the knowledge base say about XX" / "What is the company's YY policy"
  • "What is the reimbursement process" / "How many days in advance do I need to request leave"
  • "Where is the XX technical solution document" / "Find the document about YY"
  • "Help me look up ZZ from the knowledge base" / "Is there an explanation about XX in the documents"
  • "Knowledge base search XX" / "Knowledge base Q&A"

Implement RAG (Retrieval-Augmented Generation)Q&A for the Feishu knowledge base: first search to locate relevant documents, then read the content, and finally answer questions based on the actual document content with source citations.

用户问题 ──► 搜索知识库 ──► 定位相关文档 ──► 读取内容 ──► AI 问答 ──► 回答 + 引用

Prerequisites

Supports user identity. Ensure authorization before execution:

lark-cli auth login --domain wiki,doc,drive

Workflow

用户问题(自然语言)
        │
        ├─► wiki(搜索知识空间节点)──► 匹配文档列表
        │
        ├─► drive files search(补充搜索)──► 匹配文档列表(可选)
        │
        ▼
   合并去重 → 按相关性排序 → 取 Top N
        │
        ▼
   逐个 docs +fetch(读取文档内容)
        │
        ▼
   AI 综合分析(问题 + 文档内容)
        │
        ▼
   结构化回答 + 来源引用链接

Step 1: Parse the user's question

Extract key search terms from the user's natural language question:

  • "What is the reimbursement process" → Search terms: "reimbursement process"
  • "Specifications regarding API integration" → Search terms: "API integration specifications"
  • "What do new employees need to prepare for onboarding" → Search terms: "new employee onboarding"

Note: Search terms should remove stop words and retain core nouns and verbs, preferably 2-4 words.

Step 2: Search the knowledge base

Refer to lark-wiki/SKILL.md。

Method A — Knowledge base node search:

# 列出可用的知识空间
lark-cli wiki spaces list --format json

# 在知识空间中搜索
lark-cli wiki spaces nodes search --data '{"space_id":"<space_id>","query":"<搜索词>","page_size":10}' --format json

Method B — Cloud space file search (supplementary):

Refer to lark-drive/SKILL.md。

# 全局搜索文档
lark-cli drive files search --data '{"search_key":"<搜索词>","count":10,"doc_types":["docx","doc","wiki"]}' --format json

Advanced search syntax (v1.0.7+):

Improve search precision, supporting the following syntax:

  • Boolean search:"A AND B" — contains both A and B
  • Title search:"intitle:报销流程" — search only documents whose titles contain the keyword
  • Combined search:"intitle:入职 AND 流程" — title contains "onboarding" and body contains "process"

Tip: Advanced search syntax can significantly improve retrieval accuracy; it is recommended to use it first. See the search syntax description in lark-doc SKILL.md .

Step 3: Filter and sort

Filter the most relevant documents from the search results:

  1. Merge the results of both searches and deduplicate by doc_token Deduplication
  2. Prefer documents whose titles contain the search terms
  3. Take the Top 3-5 most relevant documents to the next step

Context management: Read at most 5 documents. If there are too many results, prompt the user to narrow the search scope.

Step 4: Read document content

Refer to lark-doc/SKILL.md。

For each filtered document:

# Wiki 链接需先解析真实 token
lark-cli wiki spaces get_node --params '{"token":"<wiki_token>"}'

# 读取文档内容
lark-cli docs +fetch --doc "<doc_token>" --format markdown

Long document handling: If a single document is too long (>20KB), read only the sections relevant to the question. You can locate relevant paragraphs through the document outline (# heading levels).

Step 5: AI comprehensive Q&A

Based on the user's question + the read document content, generate an answer:

## 💡 回答:{用户问题的简短回述}

{基于文档内容生成的详细回答}

{如果有具体步骤、流程,使用有序列表}

### 📚 来源文档

| # | 文档标题 | 相关程度 | 链接 |
|---|---------|---------|------|
| 1 | {文档标题 1} | ⭐⭐⭐ 高度相关 | [查看文档]({链接}) |
| 2 | {文档标题 2} | ⭐⭐ 部分相关 | [查看文档]({链接}) |

### 💬 补充说明
- {如果文档中信息有冲突,指出冲突}
- {如果信息可能已过时,提示最后更新时间}
- {如果问题未在文档中完全覆盖,说明缺失部分}

Generation rules:

  1. Answers must be based on document content: Do not generate from thin air; every key point should be traceable to a specific document
  2. Citation annotation: In the answer, use [1] [2] to mark the information source
  3. Honest declaration: If no relevant content is found in the knowledge base, clearly inform the user "No content about XX was found in the knowledge base"
  4. Timeliness notice: If the document creation time or edit time is old (>6 months), remind the user that the information may be outdated
  5. Multi-document synthesis: If multiple documents involve the same topic, synthesize all information to provide a complete answer

Step 6: Follow-up and deeper exploration (interactive)

After answering, proactively provide follow-up suggestions:

### 🔍 您可能还想了解
- "{相关问题 1}"
- "{相关问题 2}"
- "查看完整文档:[{标题}]({链接})"

Fault tolerance mechanism

Exception scenario Handling method
No relevant document found Clearly state "not found", suggest expanding the search scope or using a different keyword
Document has no read permission List the title but mark it as "no permission", suggest the user contact the document administrator
Too many search results Take the Top 5 and prompt the user to narrow the scope
Document content is too long Locate relevant paragraphs by section headings; do not read the full text
wiki domain not authorized Degrade to using only drive files search
Document may be outdated Mark the document's last edit time in the answer

Permission table

Step Command Required scope Mandatory
Knowledge base search wiki spaces nodes search wiki:wiki:readonly ✅ Mandatory
Wiki node parsing wiki spaces get_node wiki:wiki:readonly ✅ Mandatory
Document search drive files search drive:drive:readonly Optional (supplementary search)
Read document docs +fetch docx:document:readonly ✅ Mandatory

Reference

  • lark-shared — Authentication, permissions (required reading)
  • lark-wiki — Knowledge base search and node query
  • lark-doc — +fetch Detailed usage
  • lark-drive — Detailed usage of file search