360 Secure SkillHub
360 安全技能中心

FileChat RAG

这是依托Google Drive的RAG文档库,支持多动态文件夹,可选Gemini或OpenAI生成嵌入。核心功能包括同步指定Drive文件夹文档到本地向量库、语义查询文档内容并返回相关片段及文件信息、存取文件。典型场景:用户存储文件、查询文档内容、获取原文件、同步文档库。需先配置环境变量,通过命令行操作,可返回文本答案或发送文件附件。

eladrave
eladrave
热度 39.27
最近更新 2026-05-11 17:35:23
分类:知识依赖:代码执行 / 读写文件 / 第三方 API应用场景:研究 / 摘要总结 / 数据处理

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add eladrave-filechat-rag
Metadata
name
filechat-rag
description
Search, retrieve, and chat with documents securely stored in ANY Google Drive folder using semantic vector search (RAG). Use when: (1) a user asks to save a file for later, (2) a user asks a question about their saved files/documents, (3) a user asks you to retrieve or send them a previously stored file, (4) a user asks to sync or flush their document library. This skill automatically chunks, embeds, and indexes Google Drive documents into isolated persistent vector databases per folder.
metadata
{"openclaw":{"category":"knowledge","requires":{"bins":["node","npm","gws"]},"install":[{"id":"gws","kind":"node","package":"@googleworkspace/cli","bins":["gws"],"label":"Install Google Workspace CLI"},{"id":"filechat-deps","kind":"script","script":"cd ./skills/filechat && npm install","label":"Install FileChat Dependencies"}]}}

FileChat RAG Skill

Your personal RAG (Retrieval-Augmented Generation) document library backed by Google Drive. Supports multiple Google Drive folders dynamically and allows choosing between Gemini or OpenAI for embeddings.

Setup & Bootstrap

If the user asks to use FileChat or asks a question about their files, FIRST verify that the required environment variables are set in /workspace/skills/filechat/.env:

  1. EMBEDDING_PROVIDER (either gemini or openai)
  2. GEMINI_API_KEY or OPENAI_API_KEY (Depending on the provider)

If they are missing, STOP and ask the user to provide them. Create the .env file like this:

echo "EMBEDDING_PROVIDER=gemini" > ./skills/filechat/.env
echo "GEMINI_API_KEY=your_key_here" >> ./skills/filechat/.env

How to Sync the Library

When the user asks to "sync", "flush", or "update" a specific FileChat folder, you must run the ingestion script. This connects to Google Drive, downloads all new/changed files (including PDFs, resolving shortcuts, and traversing sub-folders), chunks the text, gets embeddings, and saves them to a local JSON vector database keyed by the Folder ID.

You must supply the FOLDER_ID to the script. If you don't know the folder ID the user wants, ask them.

cd ./skills/filechat && node sync.js <FOLDER_ID>

How to Answer User Questions (RAG)

When a user asks a question about the contents of their documents, you MUST query the local vector store to fetch the relevant text chunks. You need the Folder ID.

cd ./skills/filechat && node query.js <FOLDER_ID> "What does my medical discharge say?"

The output will give you the most relevant text snippets, the original file names, and the Google Drive File IDs. Use the text snippets to formulate a comprehensive answer for the user. Always cite the file name you are referencing.

How to Retrieve and Send a Physical File

If the user asks for the actual file (e.g., "Send me the discharge PDF"), first find the File ID using the query script.

Then, use the gws CLI to download the file into your workspace:

gws drive files get --params '{"fileId": "<FILE_ID>", "alt": "media"}' --output /workspace/discharge.pdf

Then, reply to the user using the OpenClaw media attachment syntax: MEDIA:/workspace/discharge.pdf to send the physical file directly to their chat window.

How to Store a New File for the User

If the user uploads a file and asks you to "store" or "save" it:

  1. Upload it to their specific FileChat Google Drive folder using gws:
    gws drive files create \
      --json '{"name": "filename.pdf", "parents": ["<FOLDER_ID>"]}' \
      --upload /path/to/uploaded/file.pdf
    
  2. Trigger the sync process so the new file is immediately readable by the vector database:
    cd ./skills/filechat && node sync.js <FOLDER_ID>