← Back to Plugins
Tools

Ragflow Kit

SSWhite By SSWhite 👁 56 views ▲ 0 votes

RAGFlow Knowledge Base Retrieval Plugin for OpenClaw

GitHub

Install

npm install
npm

Configuration Example

{
  "plugins": {
    "entries": {
      "ragflow-kit": {
        "enabled": true,
        "config": {
          "ragflow": {
            "api_url": "https://your-ragflow-server.com",
            "api_key": "your-api-key-here"
          },
          "retrieval": {
            "chunk_size": 6,
            "min_similarity": 0.6
          },
          "access": {
            "agents": {
              "main": {
                "search_kbs": ["kb_name_1"],
                "upload_kbs": ["kb_name_1"],
                "delete_kbs": ["kb_name_1"]
              }
            },
            "teams": {
              "team_alpha": {
                "search_agents": ["agent_id_1", "agent_id_2"],
                "search_kbs": ["shared_kb"],
                "upload_agents": ["agent_id_1"],
                "upload_kbs": ["shared_kb"],
                "delete_agents": [],
                "delete_kbs": []
              }
            }
          }
        }
      }
    }
  }
}

README

[English](./README.md) | [ไธญๆ–‡](./README_CN.md)

# RAGFlow Kit

> RAGFlow Knowledge Base Retrieval Plugin for OpenClaw


---

## Overview

RAGFlow Kit is an OpenClaw plugin that enables agents to search, upload, and delete documents in RAGFlow knowledge bases through natural language queries. It supports per-agent and per-team access control with fine-grained permissions.

## Features

- **Knowledge Base Search** โ€” Query RAGFlow knowledge bases using natural language
- **Document Upload** โ€” Upload text files to knowledge bases with auto-parsing
- **Document Delete** โ€” Delete documents from knowledge bases
- **Access Control** โ€” Configure which agents can search / upload / delete on which knowledge bases
- **Team Support** โ€” Manage knowledge base permissions by teams
- **Similarity Filtering** โ€” Filter search results by minimum similarity threshold
- **Hot Reload** โ€” Configuration changes take effect without restarting OpenClaw

## Tools

| Tool | Description |
|------|-------------|
| `rag_search` | Search documents in configured knowledge bases |
| `rag_upload` | Upload files to a knowledge base (auto-triggers parsing) |
| `rag_delete` | Delete a document from a knowledge base |

---


## Installation

### Install via OpenClaw CLI

```bash
openclaw plugins install clawhub:ragflow-kit
```

### Build from source

```bash
# Clone the repository
git clone https://github.com/SSWhite/ragflow-kit.git
cd ragflow-kit

# Install dependencies and build
npm install
npm run build

# Install to OpenClaw plugins directory
openclaw plugins install ./
```

---

## Configuration

Edit your OpenClaw configuration file (`openclaw.json`):

```json
{
  "plugins": {
    "entries": {
      "ragflow-kit": {
        "enabled": true,
        "config": {
          "ragflow": {
            "api_url": "https://your-ragflow-server.com",
            "api_key": "your-api-key-here"
          },
          "retrieval": {
            "chunk_size": 6,
            "min_similarity": 0.6
          },
          "access": {
            "agents": {
              "main": {
                "search_kbs": ["kb_name_1"],
                "upload_kbs": ["kb_name_1"],
                "delete_kbs": ["kb_name_1"]
              }
            },
            "teams": {
              "team_alpha": {
                "search_agents": ["agent_id_1", "agent_id_2"],
                "search_kbs": ["shared_kb"],
                "upload_agents": ["agent_id_1"],
                "upload_kbs": ["shared_kb"],
                "delete_agents": [],
                "delete_kbs": []
              }
            }
          }
        }
      }
    }
  }
}
```

### Configuration Reference

#### `ragflow` โ€” RAGFlow connection

| Field | Type | Required | Default | Description |
|-------|------|----------|---------|-------------|
| `api_url` | string | Yes | โ€” | RAGFlow server URL |
| `api_key` | string | Yes | โ€” | RAGFlow API key |
| `knowledge_base` | string | No | โ€” | Default knowledge base name |

#### `retrieval` โ€” Search behavior

| Field | Type | Required | Default | Description |
|-------|------|----------|---------|-------------|
| `chunk_size` | number | No | `6` | Maximum number of chunks to return |
| `min_similarity` | number | No | `0.6` | Minimum similarity threshold (0โ€“1) |

#### `access` โ€” Permission control

| Field | Type | Description |
|-------|------|-------------|
| `access.agents` | object | Map of `agentId โ†’ AgentAccess` |
| `access.teams` | object | Map of `teamId โ†’ TeamAccess` |

**`AgentAccess` structure:**

```ts
{
  search_kbs: string[];   // KB names/IDs this agent can search
  upload_kbs: string[];    // KB names/IDs this agent can upload to
  delete_kbs: string[];   // KB names/IDs this agent can delete from
}
```

**`TeamAccess` structure:**

```ts
{
  search_agents: string[];  // Agent IDs in this team (for search)
  search_kbs: string[];     // KB names/IDs this team can search
  upload_agents: string[]; // Agent IDs in this team (for upload)
  upload_kbs: string[];    // KB names/IDs this team can upload
  delete_agents: string[];// Agent IDs in this team (for delete)
  delete_kbs: string[];    // KB names/IDs this team can delete
}
```

---

## Usage

### rag_search

Search for relevant documents in configured knowledge bases.

**Parameters:**

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `query` | string | Yes | Search query text |

**Example:**

```json
{
  "tool": "rag_search",
  "params": {
    "query": "What is the company policy on remote work?"
  }
}
```

**Response format:**

```json
{
  "content": [{
    "type": "text",
    "text": "{...JSON with chunks...}\n\n[Provenance Requirements]\nYou must cite sources using [X] format..."
  }]
}
```

---

### rag_upload

Upload a text file to a knowledge base. Triggers parsing automatically.

**Parameters:**

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `kb_name` | string | Yes | Target knowledge base name |
| `file_name` | string | Yes | File name |
| `file_content` | string | Yes | File content (text) |

**Example:**

```json
{
  "tool": "rag_upload",
  "params": {
    "kb_name": "company-policies",
    "file_name": "remote-work.txt",
    "file_content": "Remote work policy content here..."
  }
}
```

**Without parameters** โ€” lists all available knowledge bases for the agent.

---

### rag_delete

Delete a document from a knowledge base.

**Parameters:**

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `kb_name` | string | Yes | Knowledge base name |
| `document_id` | string | Yes | Document ID to delete |

**Example:**

```json
{
  "tool": "rag_delete",
  "params": {
    "kb_name": "company-policies",
    "document_id": "doc-xxx-123"
  }
}
```

---

## File Structure

```
ragflow-kit/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ index.ts           # Plugin entry, registers three tools
โ”‚   โ”œโ”€โ”€ modules/
โ”‚   โ”‚   โ”œโ”€โ”€ auth.ts        # RAGFlowClient HTTP client
โ”‚   โ”‚   โ”œโ”€โ”€ query.ts       # Search logic, permissions, KB resolver
โ”‚   โ”‚   โ”œโ”€โ”€ upload.ts      # Upload & delete file operations
โ”‚   โ”‚   โ””โ”€โ”€ config.ts      # Config loading & hot reload
โ”‚   โ”œโ”€โ”€ config/
โ”‚   โ”‚   โ””โ”€โ”€ schema.ts      # Default values & validation
โ”‚   โ”œโ”€โ”€ types/
โ”‚   โ”‚   โ””โ”€โ”€ index.ts       # TypeScript type definitions
โ”‚   โ””โ”€โ”€ utils/
โ”‚       โ””โ”€โ”€ index.ts       # normalizeUrl, buildResultText, etc.
โ”œโ”€โ”€ dist/                  # Compiled JavaScript (published to npm)
โ”œโ”€โ”€ openclaw.plugin.json   # Plugin manifest
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ tsconfig.json
โ””โ”€โ”€ README.md
```

---

## Architecture Notes

### KB Name โ†’ ID Resolution

Knowledge base names are resolved to IDs lazily on first use and cached (max 100 entries). The cache is cleared when `api_url`, `api_key`, or access credentials change.

### Hot Reload

Config is reloaded on every tool call (not at startup). If the config file is modified, changes take effect on the next tool call without restarting OpenClaw.

### Permission Merging

Agent-level and team-level permissions are merged. A KB is accessible if **any** permission source grants access (union, not intersection).

---

## License

MIT License
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
tools

Comments

Sign in to leave a comment

Loading comments...