@elizaos/plugin-knowledge 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +216 -2
- package/dist/.vite/manifest.json +2 -2
- package/dist/assets/index-BRhhNXdt.js +140 -0
- package/dist/assets/index-Clk6Xgn1.css +1 -0
- package/dist/{chunk-HUTF5APY.js → chunk-BB6B27BS.js} +11 -1
- package/dist/{chunk-HUTF5APY.js.map → chunk-BB6B27BS.js.map} +1 -1
- package/dist/{docs-loader-2S6H7F4L.js → docs-loader-NAE6ASGY.js} +2 -2
- package/dist/index.d.ts +21 -1
- package/dist/index.html +2 -2
- package/dist/index.js +46 -87
- package/dist/index.js.map +1 -1
- package/package.json +130 -2
- package/dist/assets/index-BdT7VEOH.css +0 -1
- package/dist/assets/index-lAKoVTZd.js +0 -142
- /package/dist/{docs-loader-2S6H7F4L.js.map → docs-loader-NAE6ASGY.js.map} +0 -0
package/README.md
CHANGED
|
@@ -4,6 +4,8 @@ This plugin provides Retrieval Augmented Generation (Knowledge) capabilities for
|
|
|
4
4
|
|
|
5
5
|
## Quick Setup
|
|
6
6
|
|
|
7
|
+
> **⚠️ Note**: `TEXT_PROVIDER` and `TEXT_MODEL` configuration are temporarily disabled. The plugin currently uses `runtime.useModel(TEXT_LARGE)` for text generation. Full provider configuration support will be added soon.
|
|
8
|
+
|
|
7
9
|
### Basic Setup (With plugin-openai)
|
|
8
10
|
|
|
9
11
|
If you already have plugin-openai configured, you don't need any additional environment variables! The Knowledge plugin will automatically use your OpenAI configuration.
|
|
@@ -22,11 +24,13 @@ If you already have plugin-openai configured, you don't need any additional envi
|
|
|
22
24
|
|
|
23
25
|
If you want enhanced Knowledge capabilities with contextual embeddings, add:
|
|
24
26
|
|
|
27
|
+
> **Note**: The TEXT_PROVIDER and TEXT_MODEL settings below are temporarily disabled. The plugin will use `runtime.useModel(TEXT_LARGE)` for now.
|
|
28
|
+
|
|
25
29
|
```env
|
|
26
30
|
# Enable contextual Knowledge
|
|
27
31
|
CTX_KNOWLEDGE_ENABLED=true
|
|
28
32
|
|
|
29
|
-
# Required text generation settings
|
|
33
|
+
# Required text generation settings (TEMPORARILY DISABLED)
|
|
30
34
|
TEXT_PROVIDER=openrouter # Choose your provider: openai, anthropic, openrouter, or google
|
|
31
35
|
TEXT_MODEL=anthropic/claude-3.5-sonnet # Model for your chosen provider
|
|
32
36
|
|
|
@@ -109,6 +113,31 @@ OPENROUTER_BASE_URL=https://your-openrouter-proxy.com/api/v1
|
|
|
109
113
|
GOOGLE_BASE_URL=https://your-google-proxy.com
|
|
110
114
|
```
|
|
111
115
|
|
|
116
|
+
### Knowledge Document Path
|
|
117
|
+
|
|
118
|
+
By default, the plugin looks for knowledge documents in a `docs` folder in your project root. You can customize this location using the `KNOWLEDGE_PATH` environment variable:
|
|
119
|
+
|
|
120
|
+
```env
|
|
121
|
+
# Custom path to your knowledge documents
|
|
122
|
+
KNOWLEDGE_PATH=/path/to/your/documents
|
|
123
|
+
|
|
124
|
+
# Examples:
|
|
125
|
+
# KNOWLEDGE_PATH=./my-docs # Relative path from project root
|
|
126
|
+
# KNOWLEDGE_PATH=/home/user/docs # Absolute path
|
|
127
|
+
# KNOWLEDGE_PATH=../shared/knowledge # Relative path to parent directory
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
**How it works:**
|
|
131
|
+
- If `KNOWLEDGE_PATH` is set, the plugin will use that directory for loading knowledge documents
|
|
132
|
+
- If `KNOWLEDGE_PATH` is not set, the plugin defaults to `./docs` (a `docs` folder in your project root)
|
|
133
|
+
- Both relative and absolute paths are supported
|
|
134
|
+
- If the specified path doesn't exist, the plugin will log a warning but continue to function
|
|
135
|
+
|
|
136
|
+
**Supported document formats:**
|
|
137
|
+
- PDF files (`.pdf`)
|
|
138
|
+
- Text files (`.txt`, `.md`)
|
|
139
|
+
- And other formats supported by the document processor
|
|
140
|
+
|
|
112
141
|
### Token Limits
|
|
113
142
|
|
|
114
143
|
```env
|
|
@@ -168,9 +197,194 @@ The document processing flow follows these steps regardless of database type:
|
|
|
168
197
|
- Rate limiting to respect provider limitations
|
|
169
198
|
- Support for multiple LLM providers
|
|
170
199
|
|
|
200
|
+
## API Routes
|
|
201
|
+
|
|
202
|
+
The Knowledge plugin provides a comprehensive REST API for managing knowledge documents. All routes are prefixed with `/api/agents/{agentId}/plugins/knowledge`.
|
|
203
|
+
|
|
204
|
+
### Knowledge Panel UI
|
|
205
|
+
|
|
206
|
+
#### GET `/display`
|
|
207
|
+
Access the web-based knowledge management interface.
|
|
208
|
+
|
|
209
|
+
- **URL**: `/api/agents/{agentId}/plugins/knowledge/display`
|
|
210
|
+
- **Method**: GET
|
|
211
|
+
- **Public**: Yes
|
|
212
|
+
- **Description**: Serves the HTML frontend for managing knowledge documents
|
|
213
|
+
- **Response**: HTML page with embedded configuration
|
|
214
|
+
|
|
215
|
+
### Document Management
|
|
216
|
+
|
|
217
|
+
#### POST `/documents` - Upload Knowledge
|
|
218
|
+
Upload files or URLs to create knowledge documents.
|
|
219
|
+
|
|
220
|
+
**File Upload:**
|
|
221
|
+
```bash
|
|
222
|
+
curl -X POST \
|
|
223
|
+
"/api/agents/{agentId}/plugins/knowledge/documents" \
|
|
224
|
+
-H "Content-Type: multipart/form-data" \
|
|
225
|
+
-F "files=@document.pdf" \
|
|
226
|
+
-F "documentId=optional-custom-id" \
|
|
227
|
+
-F "worldId=optional-world-id"
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
**URL Upload:**
|
|
231
|
+
```bash
|
|
232
|
+
curl -X POST \
|
|
233
|
+
"/api/agents/{agentId}/plugins/knowledge/documents" \
|
|
234
|
+
-H "Content-Type: application/json" \
|
|
235
|
+
-d '{
|
|
236
|
+
"fileUrls": ["https://example.com/document.pdf"],
|
|
237
|
+
"worldId": "optional-world-id"
|
|
238
|
+
}'
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
**Request Parameters:**
|
|
242
|
+
- `files`: File(s) to upload (multipart)
|
|
243
|
+
- `fileUrl` or `fileUrls`: URL(s) to fetch content from (JSON)
|
|
244
|
+
- `documentId` or `documentIds`: Optional custom document IDs
|
|
245
|
+
- `worldId`: Optional world ID for scoping
|
|
246
|
+
|
|
247
|
+
**Response:**
|
|
248
|
+
```json
|
|
249
|
+
{
|
|
250
|
+
"success": true,
|
|
251
|
+
"data": [
|
|
252
|
+
{
|
|
253
|
+
"id": "document-uuid",
|
|
254
|
+
"filename": "document.pdf",
|
|
255
|
+
"status": "success",
|
|
256
|
+
"fragmentCount": 15,
|
|
257
|
+
"createdAt": 1703123456789
|
|
258
|
+
}
|
|
259
|
+
]
|
|
260
|
+
}
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
**Supported File Types:**
|
|
264
|
+
- **Documents**: PDF, DOC, DOCX
|
|
265
|
+
- **Text**: TXT, MD, HTML, JSON, XML, YAML
|
|
266
|
+
- **Code**: JS, TS, PY, JAVA, C, CPP, CS, PHP, RB, GO, RS, and more
|
|
267
|
+
- **Config**: INI, CFG, CONF, ENV
|
|
268
|
+
- **Data**: CSV, TSV, LOG
|
|
269
|
+
|
|
270
|
+
#### GET `/documents` - List Documents
|
|
271
|
+
Retrieve all knowledge documents.
|
|
272
|
+
|
|
273
|
+
```bash
|
|
274
|
+
curl "/api/agents/{agentId}/plugins/knowledge/documents?limit=20&before=1703123456789&includeEmbedding=false"
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
**Query Parameters:**
|
|
278
|
+
- `limit`: Number of documents to return (default: 20)
|
|
279
|
+
- `before`: Timestamp for pagination (default: current time)
|
|
280
|
+
- `includeEmbedding`: Include embedding data (default: false)
|
|
281
|
+
- `fileUrls`: Filter by specific URLs (comma-separated)
|
|
282
|
+
|
|
283
|
+
**Response:**
|
|
284
|
+
```json
|
|
285
|
+
{
|
|
286
|
+
"success": true,
|
|
287
|
+
"data": {
|
|
288
|
+
"memories": [
|
|
289
|
+
{
|
|
290
|
+
"id": "document-uuid",
|
|
291
|
+
"content": { "text": "..." },
|
|
292
|
+
"metadata": {
|
|
293
|
+
"type": "document",
|
|
294
|
+
"title": "Document Title",
|
|
295
|
+
"filename": "document.pdf",
|
|
296
|
+
"fileType": "application/pdf",
|
|
297
|
+
"fileSize": 1024,
|
|
298
|
+
"timestamp": 1703123456789,
|
|
299
|
+
"source": "upload"
|
|
300
|
+
},
|
|
301
|
+
"createdAt": 1703123456789
|
|
302
|
+
}
|
|
303
|
+
],
|
|
304
|
+
"urlFiltered": false,
|
|
305
|
+
"totalFound": 1,
|
|
306
|
+
"totalRequested": 0
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
#### GET `/documents/:knowledgeId` - Get Specific Document
|
|
312
|
+
Retrieve a specific knowledge document by ID.
|
|
313
|
+
|
|
314
|
+
```bash
|
|
315
|
+
curl "/api/agents/{agentId}/plugins/knowledge/documents/{documentId}"
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
**Response:**
|
|
319
|
+
```json
|
|
320
|
+
{
|
|
321
|
+
"success": true,
|
|
322
|
+
"data": {
|
|
323
|
+
"document": {
|
|
324
|
+
"id": "document-uuid",
|
|
325
|
+
"content": { "text": "..." },
|
|
326
|
+
"metadata": { "..." },
|
|
327
|
+
"createdAt": 1703123456789
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
#### DELETE `/documents/:knowledgeId` - Delete Document
|
|
334
|
+
Delete a knowledge document and all its fragments.
|
|
335
|
+
|
|
336
|
+
```bash
|
|
337
|
+
curl -X DELETE "/api/agents/{agentId}/plugins/knowledge/documents/{documentId}"
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
**Response:**
|
|
341
|
+
```json
|
|
342
|
+
{
|
|
343
|
+
"success": true,
|
|
344
|
+
"data": null
|
|
345
|
+
}
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
### Knowledge Fragments
|
|
349
|
+
|
|
350
|
+
#### GET `/knowledges` - List Knowledge Chunks
|
|
351
|
+
Retrieve knowledge fragments/chunks for detailed analysis or graph view.
|
|
352
|
+
|
|
353
|
+
```bash
|
|
354
|
+
curl "/api/agents/{agentId}/plugins/knowledge/knowledges?limit=100&documentId=optional-filter"
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
**Query Parameters:**
|
|
358
|
+
- `limit`: Number of chunks to return (default: 100)
|
|
359
|
+
- `before`: Timestamp for pagination (default: current time)
|
|
360
|
+
- `documentId`: Filter chunks by parent document ID
|
|
361
|
+
|
|
362
|
+
**Response:**
|
|
363
|
+
```json
|
|
364
|
+
{
|
|
365
|
+
"success": true,
|
|
366
|
+
"data": {
|
|
367
|
+
"chunks": [
|
|
368
|
+
{
|
|
369
|
+
"id": "fragment-uuid",
|
|
370
|
+
"content": { "text": "chunk content..." },
|
|
371
|
+
"metadata": {
|
|
372
|
+
"type": "fragment",
|
|
373
|
+
"documentId": "parent-document-uuid",
|
|
374
|
+
"position": 0,
|
|
375
|
+
"timestamp": 1703123456789
|
|
376
|
+
},
|
|
377
|
+
"embedding": [0.1, 0.2, ...], // If included
|
|
378
|
+
"createdAt": 1703123456789
|
|
379
|
+
}
|
|
380
|
+
]
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
```
|
|
384
|
+
|
|
171
385
|
## Usage
|
|
172
386
|
|
|
173
|
-
###
|
|
387
|
+
### Programmatic Usage
|
|
174
388
|
|
|
175
389
|
```typescript
|
|
176
390
|
import { KnowledgeService } from '@elizaos/plugin-knowledge';
|
package/dist/.vite/manifest.json
CHANGED