@elizaos/plugin-knowledge 1.0.5 → 1.0.7
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 +168 -338
- package/dist/.vite/manifest.json +2 -2
- package/dist/assets/index-BMDX6vvo.js +160 -0
- package/dist/assets/index-o1rKIvUo.css +1 -0
- package/dist/{chunk-MFXNKYBS.js → chunk-536BD2UA.js} +6 -1
- package/dist/{chunk-MFXNKYBS.js.map → chunk-536BD2UA.js.map} +1 -1
- package/dist/{docs-loader-AEQHIBO4.js → docs-loader-IBTEOAYT.js} +2 -2
- package/dist/index.d.ts +5 -3
- package/dist/index.html +2 -2
- package/dist/index.js +652 -191
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/assets/index-C77XebWS.css +0 -1
- package/dist/assets/index-DZQIX0Kb.js +0 -150
- /package/dist/{docs-loader-AEQHIBO4.js.map → docs-loader-IBTEOAYT.js.map} +0 -0
package/README.md
CHANGED
|
@@ -1,409 +1,239 @@
|
|
|
1
1
|
# Knowledge Plugin for ElizaOS
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Give your AI agent the ability to learn from documents and answer questions based on that knowledge. Works out of the box with zero configuration!
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## 🚀 Getting Started (Beginner-Friendly)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
### Step 1: Add the Plugin
|
|
8
|
+
The Knowledge plugin works automatically with any ElizaOS agent. Just add it to your agent's plugin list:
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
```typescript
|
|
11
|
+
// In your character file (e.g., character.ts)
|
|
12
|
+
export const character = {
|
|
13
|
+
name: 'MyAgent',
|
|
14
|
+
plugins: [
|
|
15
|
+
'@elizaos/plugin-openai', // ← Make sure you have this
|
|
16
|
+
'@elizaos/plugin-knowledge', // ← Add this line
|
|
17
|
+
// ... your other plugins
|
|
18
|
+
],
|
|
19
|
+
// ... rest of your character config
|
|
20
|
+
};
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
**That's it!** Your agent can now learn from documents. No environment variables or API keys needed.
|
|
10
24
|
|
|
11
|
-
|
|
25
|
+
### Step 2: Upload Documents (Optional)
|
|
26
|
+
Want your agent to automatically learn from documents when it starts?
|
|
12
27
|
|
|
13
|
-
1.
|
|
28
|
+
1. **Create a `docs` folder** in your project root:
|
|
29
|
+
```
|
|
30
|
+
your-project/
|
|
31
|
+
├── .env
|
|
32
|
+
├── docs/ ← Create this folder
|
|
33
|
+
│ ├── guide.pdf
|
|
34
|
+
│ ├── manual.txt
|
|
35
|
+
│ └── notes.md
|
|
36
|
+
└── package.json
|
|
37
|
+
```
|
|
14
38
|
|
|
39
|
+
2. **Add this line to your `.env` file:**
|
|
15
40
|
```env
|
|
16
|
-
|
|
17
|
-
OPENAI_EMBEDDING_MODEL=text-embedding-3-small
|
|
41
|
+
LOAD_DOCS_ON_STARTUP=true
|
|
18
42
|
```
|
|
19
43
|
|
|
20
|
-
|
|
21
|
-
3. That's it! The plugin will work without any additional variables
|
|
44
|
+
3. **Start your agent** - it will automatically learn from all documents in the `docs` folder!
|
|
22
45
|
|
|
23
|
-
###
|
|
46
|
+
### Step 3: Ask Questions
|
|
47
|
+
Once documents are loaded, just talk to your agent naturally:
|
|
24
48
|
|
|
25
|
-
|
|
49
|
+
- "What does the guide say about setup?"
|
|
50
|
+
- "Search your knowledge for configuration info"
|
|
51
|
+
- "What do you know about [any topic]?"
|
|
26
52
|
|
|
27
|
-
|
|
53
|
+
Your agent will search through all loaded documents and give you relevant answers!
|
|
28
54
|
|
|
29
|
-
|
|
30
|
-
# Enable contextual Knowledge
|
|
31
|
-
CTX_KNOWLEDGE_ENABLED=true
|
|
55
|
+
## 📁 Supported File Types
|
|
32
56
|
|
|
33
|
-
|
|
34
|
-
TEXT_PROVIDER=openrouter # Choose your provider: openai, anthropic, openrouter, or google
|
|
35
|
-
TEXT_MODEL=anthropic/claude-3.5-sonnet # Model for your chosen provider
|
|
57
|
+
The plugin can read almost any document:
|
|
36
58
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
# OR GOOGLE_API_KEY=your-google-api-key
|
|
41
|
-
# OR use existing OPENAI_API_KEY
|
|
42
|
-
```
|
|
59
|
+
- **Text Files:** `.txt`, `.md`, `.csv`, `.json`, `.xml`, `.yaml`
|
|
60
|
+
- **Documents:** `.pdf`, `.doc`, `.docx`
|
|
61
|
+
- **Code Files:** `.js`, `.ts`, `.py`, `.java`, `.cpp`, `.html`, `.css` and many more
|
|
43
62
|
|
|
44
|
-
|
|
63
|
+
## 💬 Using the Web Interface
|
|
45
64
|
|
|
46
|
-
|
|
65
|
+
The plugin includes a web interface for managing documents!
|
|
47
66
|
|
|
48
|
-
|
|
49
|
-
# Required embedding settings
|
|
50
|
-
EMBEDDING_PROVIDER=openai # or google
|
|
51
|
-
TEXT_EMBEDDING_MODEL=text-embedding-3-small
|
|
67
|
+
**Access it at:** `http://localhost:3000/api/agents/[your-agent-id]/plugins/knowledge/display`
|
|
52
68
|
|
|
53
|
-
|
|
54
|
-
OPENAI_API_KEY=your-openai-api-key # if using openai
|
|
55
|
-
# OR GOOGLE_API_KEY=your-google-api-key # if using google
|
|
69
|
+
You can upload, view, and delete documents directly from your browser.
|
|
56
70
|
|
|
57
|
-
|
|
58
|
-
EMBEDDING_DIMENSION=1536
|
|
59
|
-
```
|
|
71
|
+
## 🎯 Agent Actions
|
|
60
72
|
|
|
61
|
-
|
|
73
|
+
Your agent automatically gets these new abilities:
|
|
62
74
|
|
|
63
|
-
|
|
75
|
+
- **PROCESS_KNOWLEDGE** - "Remember this document: [file path or text]"
|
|
76
|
+
- **SEARCH_KNOWLEDGE** - "Search your knowledge for [topic]"
|
|
64
77
|
|
|
65
|
-
|
|
78
|
+
## ❓ FAQ
|
|
66
79
|
|
|
67
|
-
**
|
|
80
|
+
**Q: Do I need any API keys?**
|
|
81
|
+
A: No! It uses your existing OpenAI/Google/Anthropic setup automatically.
|
|
68
82
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
CTX_KNOWLEDGE_ENABLED=true
|
|
72
|
-
TEXT_PROVIDER=openrouter
|
|
73
|
-
TEXT_MODEL=anthropic/claude-3.5-sonnet # or google/gemini-2.5-flash-preview
|
|
74
|
-
OPENROUTER_API_KEY=your-openrouter-api-key
|
|
75
|
-
```
|
|
83
|
+
**Q: What if I don't have any AI plugins?**
|
|
84
|
+
A: You need at least one AI provider plugin (like `@elizaos/plugin-openai`) for embeddings.
|
|
76
85
|
|
|
77
|
-
**
|
|
86
|
+
**Q: Can I upload documents while the agent is running?**
|
|
87
|
+
A: Yes! Use the web interface or just tell your agent to process a file.
|
|
78
88
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
CTX_KNOWLEDGE_ENABLED=true
|
|
82
|
-
TEXT_PROVIDER=openai
|
|
83
|
-
TEXT_MODEL=gpt-4o
|
|
84
|
-
```
|
|
89
|
+
**Q: How much does this cost?**
|
|
90
|
+
A: Only the cost of generating embeddings (usually pennies per document).
|
|
85
91
|
|
|
86
|
-
|
|
92
|
+
---
|
|
87
93
|
|
|
88
|
-
|
|
89
|
-
EMBEDDING_PROVIDER=google
|
|
90
|
-
TEXT_EMBEDDING_MODEL=text-embedding-004
|
|
91
|
-
TEXT_PROVIDER=google
|
|
92
|
-
TEXT_MODEL=gemini-1.5-pro-latest
|
|
93
|
-
GOOGLE_API_KEY=your-google-api-key
|
|
94
|
-
CTX_KNOWLEDGE_ENABLED=true
|
|
95
|
-
```
|
|
94
|
+
## 🔧 Advanced Configuration (Developers)
|
|
96
95
|
|
|
97
|
-
|
|
96
|
+
> **⚠️ Note for Beginners:** The settings below are for advanced users only. The plugin works great without any of this configuration!
|
|
98
97
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
MAX_CONCURRENT_REQUESTS=30 # Default: 30
|
|
102
|
-
REQUESTS_PER_MINUTE=60 # Default: 60
|
|
103
|
-
TOKENS_PER_MINUTE=150000 # Default: 150000
|
|
104
|
-
```
|
|
98
|
+
<details>
|
|
99
|
+
<summary><strong>🚀 Enhanced Contextual Knowledge (Recommended for Developers)</strong></summary>
|
|
105
100
|
|
|
106
|
-
|
|
101
|
+
For significantly better understanding of complex documents, enable contextual embeddings with caching:
|
|
107
102
|
|
|
108
103
|
```env
|
|
109
|
-
#
|
|
110
|
-
|
|
111
|
-
ANTHROPIC_BASE_URL=https://your-anthropic-proxy.com
|
|
112
|
-
OPENROUTER_BASE_URL=https://your-openrouter-proxy.com/api/v1
|
|
113
|
-
GOOGLE_BASE_URL=https://your-google-proxy.com
|
|
114
|
-
```
|
|
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
|
|
104
|
+
# Enable enhanced contextual understanding
|
|
105
|
+
CTX_KNOWLEDGE_ENABLED=true
|
|
123
106
|
|
|
124
|
-
#
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
107
|
+
# Use OpenRouter with Claude for best results + 90% cost savings via caching
|
|
108
|
+
TEXT_PROVIDER=openrouter
|
|
109
|
+
TEXT_MODEL=anthropic/claude-3.5-sonnet
|
|
110
|
+
OPENROUTER_API_KEY=your-openrouter-api-key
|
|
128
111
|
```
|
|
129
112
|
|
|
130
|
-
**
|
|
131
|
-
-
|
|
132
|
-
-
|
|
133
|
-
-
|
|
134
|
-
|
|
113
|
+
**Benefits:**
|
|
114
|
+
- 📈 **Better Understanding:** Chunks include surrounding context
|
|
115
|
+
- 💰 **90% Cost Reduction:** Document caching reduces repeated processing costs
|
|
116
|
+
- 🎯 **Improved Accuracy:** More relevant search results
|
|
117
|
+
|
|
118
|
+
**Best Models for Contextual Mode:**
|
|
119
|
+
- `anthropic/claude-3.5-sonnet` (recommended)
|
|
120
|
+
- `google/gemini-2.5-flash` (fast + cheap)
|
|
121
|
+
- `anthropic/claude-3.5-haiku` (budget option)
|
|
135
122
|
|
|
136
|
-
|
|
137
|
-
- PDF files (`.pdf`)
|
|
138
|
-
- Text files (`.txt`, `.md`)
|
|
139
|
-
- And other formats supported by the document processor
|
|
123
|
+
</details>
|
|
140
124
|
|
|
141
|
-
|
|
125
|
+
<details>
|
|
126
|
+
<summary><strong>⚙️ Custom Configuration Options</strong></summary>
|
|
142
127
|
|
|
128
|
+
### Document Loading
|
|
143
129
|
```env
|
|
144
|
-
#
|
|
145
|
-
|
|
146
|
-
MAX_OUTPUT_TOKENS=4096 # Default: 4096
|
|
130
|
+
LOAD_DOCS_ON_STARTUP=true # Auto-load from docs folder
|
|
131
|
+
KNOWLEDGE_PATH=/custom/path # Custom document path (default: ./docs)
|
|
147
132
|
```
|
|
148
133
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
├── src/
|
|
156
|
-
│ ├── index.ts # Main entry point and plugin definition
|
|
157
|
-
│ ├── service.ts # Knowledge service implementation
|
|
158
|
-
│ ├── types.ts # Type definitions
|
|
159
|
-
│ ├── llm.ts # LLM interactions (text generation, embeddings)
|
|
160
|
-
│ ├── config.ts # Configuration validation
|
|
161
|
-
│ ├── ctx-embeddings.ts # Contextual embedding generation
|
|
162
|
-
│ ├── document-processor.ts # Shared document processing utilities
|
|
163
|
-
│ └── utils.ts # Utility functions
|
|
164
|
-
├── README.md # This file
|
|
165
|
-
└── package.json # Package definition
|
|
134
|
+
### Embedding Configuration
|
|
135
|
+
```env
|
|
136
|
+
# Only needed if you're not using a standard AI plugin
|
|
137
|
+
EMBEDDING_PROVIDER=openai # openai | google
|
|
138
|
+
TEXT_EMBEDDING_MODEL=text-embedding-3-small
|
|
139
|
+
EMBEDDING_DIMENSION=1536 # Vector dimension
|
|
166
140
|
```
|
|
167
141
|
|
|
168
|
-
###
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
1. **PostgreSQL Mode**: Uses worker threads to offload document processing from the main thread
|
|
173
|
-
2. **PGLite Mode**: Uses synchronous processing in the main thread due to PGLite's single-threaded nature
|
|
174
|
-
|
|
175
|
-
This allows the plugin to work optimally with both databases while maintaining the same functionality.
|
|
176
|
-
|
|
177
|
-
### Processing Flow
|
|
178
|
-
|
|
179
|
-
The document processing flow follows these steps regardless of database type:
|
|
180
|
-
|
|
181
|
-
1. Extract text from the document based on content type
|
|
182
|
-
2. Store the main document in the database
|
|
183
|
-
3. Split the document into chunks
|
|
184
|
-
4. Generate embeddings for each chunk (with optional context enrichment)
|
|
185
|
-
5. Store the chunks with embeddings in the database
|
|
186
|
-
|
|
187
|
-
## Component Overview
|
|
188
|
-
|
|
189
|
-
- **KnowledgeService**: Core service that manages document processing and storage
|
|
190
|
-
- **Document Processor**: Provides shared document processing utilities for both processing paths
|
|
191
|
-
|
|
192
|
-
## Features
|
|
193
|
-
|
|
194
|
-
- Document upload and processing (PDF, text, and other formats)
|
|
195
|
-
- Contextual chunking and embedding generation
|
|
196
|
-
- Robust error handling and recovery
|
|
197
|
-
- Rate limiting to respect provider limitations
|
|
198
|
-
- Support for multiple LLM providers
|
|
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"
|
|
142
|
+
### Text Generation (for Contextual Mode)
|
|
143
|
+
```env
|
|
144
|
+
TEXT_PROVIDER=openrouter # openai | anthropic | openrouter | google
|
|
145
|
+
TEXT_MODEL=anthropic/claude-3.5-sonnet
|
|
228
146
|
```
|
|
229
147
|
|
|
230
|
-
|
|
231
|
-
```
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
"fileUrls": ["https://example.com/document.pdf"],
|
|
237
|
-
"worldId": "optional-world-id"
|
|
238
|
-
}'
|
|
148
|
+
### API Keys (as needed)
|
|
149
|
+
```env
|
|
150
|
+
OPENAI_API_KEY=sk-...
|
|
151
|
+
ANTHROPIC_API_KEY=sk-ant-...
|
|
152
|
+
OPENROUTER_API_KEY=sk-or-...
|
|
153
|
+
GOOGLE_API_KEY=your-key
|
|
239
154
|
```
|
|
240
155
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
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
|
-
}
|
|
156
|
+
### Performance Tuning
|
|
157
|
+
```env
|
|
158
|
+
MAX_CONCURRENT_REQUESTS=30 # Parallel processing limit
|
|
159
|
+
REQUESTS_PER_MINUTE=60 # Rate limiting
|
|
160
|
+
TOKENS_PER_MINUTE=150000 # Token rate limiting
|
|
161
|
+
MAX_INPUT_TOKENS=4000 # Chunk size limit
|
|
162
|
+
MAX_OUTPUT_TOKENS=4096 # Response size limit
|
|
261
163
|
```
|
|
262
164
|
|
|
263
|
-
|
|
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
|
|
165
|
+
</details>
|
|
269
166
|
|
|
270
|
-
|
|
271
|
-
|
|
167
|
+
<details>
|
|
168
|
+
<summary><strong>🔌 API Reference</strong></summary>
|
|
272
169
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
170
|
+
### HTTP Endpoints
|
|
171
|
+
- `POST /api/agents/{agentId}/plugins/knowledge/documents` - Upload documents
|
|
172
|
+
- `GET /api/agents/{agentId}/plugins/knowledge/documents` - List all documents
|
|
173
|
+
- `GET /api/agents/{agentId}/plugins/knowledge/documents/{id}` - Get specific document
|
|
174
|
+
- `DELETE /api/agents/{agentId}/plugins/knowledge/documents/{id}` - Delete document
|
|
175
|
+
- `GET /api/agents/{agentId}/plugins/knowledge/display` - Web interface
|
|
276
176
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
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
|
-
```
|
|
177
|
+
### Programmatic Usage
|
|
178
|
+
```typescript
|
|
179
|
+
import { KnowledgeService } from '@elizaos/plugin-knowledge';
|
|
317
180
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
181
|
+
// Add knowledge programmatically
|
|
182
|
+
const result = await knowledgeService.addKnowledge({
|
|
183
|
+
clientDocumentId: 'unique-doc-id',
|
|
184
|
+
content: documentContent, // Base64 for PDFs, plain text for others
|
|
185
|
+
contentType: 'application/pdf',
|
|
186
|
+
originalFilename: 'document.pdf',
|
|
187
|
+
worldId: runtime.worldId,
|
|
188
|
+
roomId: runtime.roomId,
|
|
189
|
+
entityId: runtime.entityId,
|
|
190
|
+
metadata: { // Optional
|
|
191
|
+
source: 'upload',
|
|
192
|
+
author: 'John Doe'
|
|
329
193
|
}
|
|
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
|
-
```
|
|
194
|
+
});
|
|
339
195
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
}
|
|
196
|
+
// Search knowledge
|
|
197
|
+
const searchResults = await knowledgeService.searchKnowledge({
|
|
198
|
+
query: 'quantum computing',
|
|
199
|
+
agentId: runtime.agentId,
|
|
200
|
+
limit: 10
|
|
201
|
+
});
|
|
346
202
|
```
|
|
347
203
|
|
|
348
|
-
|
|
204
|
+
</details>
|
|
349
205
|
|
|
350
|
-
|
|
351
|
-
|
|
206
|
+
<details>
|
|
207
|
+
<summary><strong>🐛 Troubleshooting</strong></summary>
|
|
352
208
|
|
|
353
|
-
|
|
354
|
-
curl "/api/agents/{agentId}/plugins/knowledge/knowledges?limit=100&documentId=optional-filter"
|
|
355
|
-
```
|
|
209
|
+
### Common Issues
|
|
356
210
|
|
|
357
|
-
**
|
|
358
|
-
-
|
|
359
|
-
-
|
|
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
|
-
```
|
|
211
|
+
**"Knowledge plugin failed to initialize"**
|
|
212
|
+
- Make sure you have an AI provider plugin (openai, google-genai, etc.)
|
|
213
|
+
- Check that your AI provider has valid API keys
|
|
384
214
|
|
|
385
|
-
|
|
215
|
+
**"Documents not loading automatically"**
|
|
216
|
+
- Verify `LOAD_DOCS_ON_STARTUP=true` in your `.env` file
|
|
217
|
+
- Check that the `docs` folder exists in your project root
|
|
218
|
+
- Make sure files are readable and in supported formats
|
|
386
219
|
|
|
387
|
-
|
|
220
|
+
**"Search returns no results"**
|
|
221
|
+
- Documents need to be processed first (wait for startup to complete)
|
|
222
|
+
- Try simpler search terms
|
|
223
|
+
- Check that documents actually contain the content you're searching for
|
|
388
224
|
|
|
389
|
-
|
|
390
|
-
|
|
225
|
+
**"Out of memory errors"**
|
|
226
|
+
- Reduce `MAX_CONCURRENT_REQUESTS` to 10-15
|
|
227
|
+
- Process smaller documents or fewer documents at once
|
|
228
|
+
- Increase Node.js memory limit: `node --max-old-space-size=4096`
|
|
391
229
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
contentType: 'application/pdf',
|
|
397
|
-
originalFilename: 'document.pdf',
|
|
398
|
-
worldId: 'world-id',
|
|
399
|
-
roomId: 'optional-room-id', // Optional scoping
|
|
400
|
-
entityId: 'optional-entity-id', // Optional scoping
|
|
401
|
-
});
|
|
230
|
+
### Performance Tips
|
|
231
|
+
- **Smaller chunks = better search precision** (but more tokens used)
|
|
232
|
+
- **Contextual mode = better understanding** (but slower processing)
|
|
233
|
+
- **Batch document uploads** rather than one-by-one for better performance
|
|
402
234
|
|
|
403
|
-
|
|
404
|
-
console.log(`Created ${result.fragmentCount} searchable fragments`);
|
|
405
|
-
```
|
|
235
|
+
</details>
|
|
406
236
|
|
|
407
|
-
## License
|
|
237
|
+
## 📝 License
|
|
408
238
|
|
|
409
|
-
See the ElizaOS license for details.
|
|
239
|
+
MIT License - See the main ElizaOS license for details.
|
package/dist/.vite/manifest.json
CHANGED