@elizaos/plugin-knowledge 1.0.1 → 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 +186 -1
- package/package.json +130 -2
package/README.md
CHANGED
|
@@ -197,9 +197,194 @@ The document processing flow follows these steps regardless of database type:
|
|
|
197
197
|
- Rate limiting to respect provider limitations
|
|
198
198
|
- Support for multiple LLM providers
|
|
199
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
|
+
|
|
200
385
|
## Usage
|
|
201
386
|
|
|
202
|
-
###
|
|
387
|
+
### Programmatic Usage
|
|
203
388
|
|
|
204
389
|
```typescript
|
|
205
390
|
import { KnowledgeService } from '@elizaos/plugin-knowledge';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elizaos/plugin-knowledge",
|
|
3
3
|
"description": "Plugin for Knowledge",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.2",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -74,5 +74,133 @@
|
|
|
74
74
|
"resolutions": {
|
|
75
75
|
"zod": "3.25.23"
|
|
76
76
|
},
|
|
77
|
-
"gitHead": "b165ad83e5f7a21bc1edbd83374ca087e3cd6b33"
|
|
77
|
+
"gitHead": "b165ad83e5f7a21bc1edbd83374ca087e3cd6b33",
|
|
78
|
+
"agentConfig": {
|
|
79
|
+
"pluginType": "elizaos:plugin:1.0.0",
|
|
80
|
+
"pluginParameters": {
|
|
81
|
+
"OPENAI_API_KEY": {
|
|
82
|
+
"type": "string",
|
|
83
|
+
"description": "API key for authenticating requests to OpenAI services used by the Knowledge plugin.",
|
|
84
|
+
"required": false
|
|
85
|
+
},
|
|
86
|
+
"OPENAI_EMBEDDING_MODEL": {
|
|
87
|
+
"type": "string",
|
|
88
|
+
"description": "Specifies the OpenAI embedding model to use when generating vector embeddings.",
|
|
89
|
+
"required": false
|
|
90
|
+
},
|
|
91
|
+
"CTX_KNOWLEDGE_ENABLED": {
|
|
92
|
+
"type": "boolean",
|
|
93
|
+
"description": "Enables contextual knowledge functionality with enriched embeddings.",
|
|
94
|
+
"required": false
|
|
95
|
+
},
|
|
96
|
+
"TEXT_PROVIDER": {
|
|
97
|
+
"type": "string",
|
|
98
|
+
"description": "LLM provider for text generation (e.g., openai, anthropic, openrouter, google).",
|
|
99
|
+
"required": false
|
|
100
|
+
},
|
|
101
|
+
"TEXT_MODEL": {
|
|
102
|
+
"type": "string",
|
|
103
|
+
"description": "Name of the text generation model to use with the selected provider.",
|
|
104
|
+
"required": false
|
|
105
|
+
},
|
|
106
|
+
"OPENROUTER_API_KEY": {
|
|
107
|
+
"type": "string",
|
|
108
|
+
"description": "API key for authenticating with the OpenRouter service when TEXT_PROVIDER=openrouter.",
|
|
109
|
+
"required": false
|
|
110
|
+
},
|
|
111
|
+
"ANTHROPIC_API_KEY": {
|
|
112
|
+
"type": "string",
|
|
113
|
+
"description": "API key for Anthropic models when TEXT_PROVIDER=anthropic.",
|
|
114
|
+
"required": false
|
|
115
|
+
},
|
|
116
|
+
"GOOGLE_API_KEY": {
|
|
117
|
+
"type": "string",
|
|
118
|
+
"description": "API key for Google AI models when TEXT_PROVIDER=google or EMBEDDING_PROVIDER=google.",
|
|
119
|
+
"required": false
|
|
120
|
+
},
|
|
121
|
+
"EMBEDDING_PROVIDER": {
|
|
122
|
+
"type": "string",
|
|
123
|
+
"description": "Provider to use for generating embeddings (e.g., openai, google).",
|
|
124
|
+
"required": false
|
|
125
|
+
},
|
|
126
|
+
"TEXT_EMBEDDING_MODEL": {
|
|
127
|
+
"type": "string",
|
|
128
|
+
"description": "Embedding model name to use with the selected EMBEDDING_PROVIDER.",
|
|
129
|
+
"required": false
|
|
130
|
+
},
|
|
131
|
+
"EMBEDDING_DIMENSION": {
|
|
132
|
+
"type": "number",
|
|
133
|
+
"description": "Custom dimension size for generated embeddings.",
|
|
134
|
+
"required": false
|
|
135
|
+
},
|
|
136
|
+
"MAX_CONCURRENT_REQUESTS": {
|
|
137
|
+
"type": "number",
|
|
138
|
+
"description": "Maximum number of concurrent API requests allowed for rate limiting.",
|
|
139
|
+
"required": false,
|
|
140
|
+
"default": 30
|
|
141
|
+
},
|
|
142
|
+
"REQUESTS_PER_MINUTE": {
|
|
143
|
+
"type": "number",
|
|
144
|
+
"description": "Maximum number of API requests permitted per minute.",
|
|
145
|
+
"required": false,
|
|
146
|
+
"default": 60
|
|
147
|
+
},
|
|
148
|
+
"TOKENS_PER_MINUTE": {
|
|
149
|
+
"type": "number",
|
|
150
|
+
"description": "Maximum number of tokens that can be processed per minute.",
|
|
151
|
+
"required": false,
|
|
152
|
+
"default": 150000
|
|
153
|
+
},
|
|
154
|
+
"OPENAI_BASE_URL": {
|
|
155
|
+
"type": "string",
|
|
156
|
+
"description": "Custom base URL for routing OpenAI API requests (useful for proxies).",
|
|
157
|
+
"required": false
|
|
158
|
+
},
|
|
159
|
+
"ANTHROPIC_BASE_URL": {
|
|
160
|
+
"type": "string",
|
|
161
|
+
"description": "Custom base URL for Anthropic API requests.",
|
|
162
|
+
"required": false
|
|
163
|
+
},
|
|
164
|
+
"OPENROUTER_BASE_URL": {
|
|
165
|
+
"type": "string",
|
|
166
|
+
"description": "Custom base URL for OpenRouter API requests.",
|
|
167
|
+
"required": false
|
|
168
|
+
},
|
|
169
|
+
"GOOGLE_BASE_URL": {
|
|
170
|
+
"type": "string",
|
|
171
|
+
"description": "Custom base URL for Google AI API requests.",
|
|
172
|
+
"required": false
|
|
173
|
+
},
|
|
174
|
+
"KNOWLEDGE_PATH": {
|
|
175
|
+
"type": "string",
|
|
176
|
+
"description": "Filesystem path where the plugin should look for knowledge documents.",
|
|
177
|
+
"required": false,
|
|
178
|
+
"default": "./docs"
|
|
179
|
+
},
|
|
180
|
+
"MAX_INPUT_TOKENS": {
|
|
181
|
+
"type": "number",
|
|
182
|
+
"description": "Maximum number of input tokens allowed per request.",
|
|
183
|
+
"required": false,
|
|
184
|
+
"default": 4000
|
|
185
|
+
},
|
|
186
|
+
"MAX_OUTPUT_TOKENS": {
|
|
187
|
+
"type": "number",
|
|
188
|
+
"description": "Maximum number of output tokens that the model can generate.",
|
|
189
|
+
"required": false,
|
|
190
|
+
"default": 4096
|
|
191
|
+
},
|
|
192
|
+
"OPENAI_EMBEDDING_DIMENSIONS": {
|
|
193
|
+
"type": "number",
|
|
194
|
+
"description": "Alternative environment variable for embedding dimension when using OpenAI.",
|
|
195
|
+
"required": false,
|
|
196
|
+
"default": 1536
|
|
197
|
+
},
|
|
198
|
+
"LOAD_DOCS_ON_STARTUP": {
|
|
199
|
+
"type": "boolean",
|
|
200
|
+
"description": "Determines whether documents should be automatically loaded from the docs folder when the plugin starts. Any value other than the string 'false' enables loading.",
|
|
201
|
+
"required": false,
|
|
202
|
+
"default": true
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
78
206
|
}
|