📚 OpenClaw Knowledge Integration

知识库集成——让Agent拥有"外挂大脑"

为什么需要知识库?

世界上有一种Agent,它什么都懂一点,什么都不精。问它公司内部流程,它说"我不知道";问它产品细节,它说"请提供更多信息"。

Knowledge Integration让Agent连接外部知识库——飞书文档、GitHub仓库、Notion笔记、本地文件。就像给它装了个"外挂大脑",随时查阅企业知识、技术文档、项目资料。

💡 核心价值:回答准确率提升40%+、减少"我不知道"场景80%、上下文理解深度翻倍。

支持的知识源

知识源 集成方式 适用场景
飞书文档 API + OAuth 企业内部知识
GitHub GraphQL API 代码、文档、Issues
Notion REST API 项目管理、笔记
本地文件 直接读取 配置、日志、文档
Web页面 web_fetch 公开文档、博客

飞书文档集成

飞书Skill调用

# 在Skill中使用飞书知识
workflow:
  steps:
    - id: search_docs
      tool: feishu_search
      params:
        query: "{{user_query}}"
        sources: [company_docs]
        
    - id: get_content
      tool: feishu_doc_read
      params:
        doc_token: "{{search_docs.top_result.token}}"
        
    - id: answer
      model: gpt-4o
      prompt: |
        基于以下飞书文档回答用户问题:
        
        {{get_content}}
        
        用户问题:{{user_query}}

GitHub集成

# GitHub知识源配置
knowledge:
  sources:
    - type: github
      name: codebase
      
      auth:
        token: "${GITHUB_TOKEN}"
        
      scope:
        - repo: "miaoquai/openclaw-docs"
          include: [readme, docs/*, issues]
        - repo: "anthropics/anthropic-sdk-python"
          include: [examples/*]
          
      # 代码理解
      code_analysis:
        extract_functions: true
        extract_comments: true
        
      # Issue知识
      issues:
        include_closed: true
        label_filter: [documentation, question]

GitHub搜索Skill

# 搜索GitHub文档
workflow:
  steps:
    - id: search_github
      tool: github_search_code
      params:
        query: "{{user_query}}"
        repos: [openclaw-docs]
        
    - id: get_file
      tool: github_get_file
      params:
        repo: "{{search_github.repo}}"
        path: "{{search_github.path}}"
        
    - id: explain
      model: gpt-4o
      action: explain_code
      input: "{{get_file}}"

本地文件集成

# 本地文件知识源
knowledge:
  sources:
    - type: local
      name: workspace_docs
      
      paths:
        - "/var/www/miaoquai/**/*.html"  # 网站所有页面
        - "/root/.openclaw/agents/miaoquai/*.md"  # Agent配置
        - "/root/.openclaw/miaoquai-workspace/**/*.md"
        
      # 文件处理
      processing:
        html:
          extract_text: true
          exclude: [script, style]
        md:
          full_content: true
          
      # 索引更新
      watch: true  # 监听文件变化自动更新
      
      # 排除规则
      exclude:
        - "*.log"
        - "*.tmp"

知识检索策略

关键词检索

# 传统关键词匹配
search:
  strategy: keyword
  params:
    match_mode: fuzzy
    boost_fields: [title, tags]

语义检索

# Embedding语义搜索
search:
  strategy: semantic
  params:
    embedding_model: text-embedding-3-small
    vector_db: qdrant
    top_k: 10
    rerank_model: cohere-rerank

混合检索

# 关键词+语义混合
search:
  strategy: hybrid
  params:
    keyword_weight: 0.3
    semantic_weight: 0.7
    fusion: reciprocal_rank

知识更新机制

# 知识库更新策略
knowledge:
  update:
    # 定时全量更新
    full_sync:
      schedule: "0 0 * * 0"  # 每周日
      
    # 增量更新
    incremental:
      enabled: true
      watch_changes: true
      debounce: 300  # 5分钟后更新
      
    # 版本管理
    versioning:
      keep_versions: 3
      rollback_enabled: true
      
    # 质量检查
    quality_check:
      min_length: 100
      exclude_empty: true

最佳实践

⚠️ 踪坑实录:曾经把所有GitHub Issues都索引进知识库,结果Agent回答问题时引用了一个2023年已关闭的Issue,里面的信息早就过时了。教训:知识要有时效性标记,优先使用最新内容。

相关链接

#知识库集成 #飞书文档 #GitHub #知识管理 #OpenClaw