@elizaos/plugin-knowledge 1.0.6 → 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 +156 -100
- package/dist/.vite/manifest.json +2 -2
- package/dist/assets/{index-DlJcnv-R.js → index-BMDX6vvo.js} +24 -24
- package/dist/assets/index-o1rKIvUo.css +1 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.html +2 -2
- package/dist/index.js +531 -164
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/assets/index-DiVvUMt0.css +0 -1
package/README.md
CHANGED
|
@@ -1,183 +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
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
plugins: [
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
+
};
|
|
17
21
|
```
|
|
18
22
|
|
|
19
|
-
That's it
|
|
20
|
-
|
|
21
|
-
## 📁 Auto-Load Documents on Startup
|
|
22
|
-
|
|
23
|
-
Want your agent to automatically learn from documents when it starts? Just:
|
|
24
|
-
|
|
25
|
-
1. **Add this to your `.env` file:**
|
|
26
|
-
|
|
27
|
-
```env
|
|
28
|
-
LOAD_DOCS_ON_STARTUP=true
|
|
29
|
-
```
|
|
23
|
+
**That's it!** Your agent can now learn from documents. No environment variables or API keys needed.
|
|
30
24
|
|
|
31
|
-
|
|
25
|
+
### Step 2: Upload Documents (Optional)
|
|
26
|
+
Want your agent to automatically learn from documents when it starts?
|
|
32
27
|
|
|
28
|
+
1. **Create a `docs` folder** in your project root:
|
|
33
29
|
```
|
|
34
30
|
your-project/
|
|
35
31
|
├── .env
|
|
36
|
-
├── docs/
|
|
32
|
+
├── docs/ ← Create this folder
|
|
37
33
|
│ ├── guide.pdf
|
|
38
34
|
│ ├── manual.txt
|
|
39
35
|
│ └── notes.md
|
|
40
|
-
└──
|
|
36
|
+
└── package.json
|
|
41
37
|
```
|
|
42
38
|
|
|
43
|
-
|
|
39
|
+
2. **Add this line to your `.env` file:**
|
|
40
|
+
```env
|
|
41
|
+
LOAD_DOCS_ON_STARTUP=true
|
|
42
|
+
```
|
|
44
43
|
|
|
45
|
-
|
|
44
|
+
3. **Start your agent** - it will automatically learn from all documents in the `docs` folder!
|
|
46
45
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
- 📊 **Data:** JSON, CSV, XML, YAML
|
|
46
|
+
### Step 3: Ask Questions
|
|
47
|
+
Once documents are loaded, just talk to your agent naturally:
|
|
50
48
|
|
|
51
|
-
|
|
49
|
+
- "What does the guide say about setup?"
|
|
50
|
+
- "Search your knowledge for configuration info"
|
|
51
|
+
- "What do you know about [any topic]?"
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
Your agent will search through all loaded documents and give you relevant answers!
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
- "Search your knowledge for information about configuration"
|
|
57
|
-
- "What do you know about [topic]?"
|
|
55
|
+
## 📁 Supported File Types
|
|
58
56
|
|
|
59
|
-
|
|
57
|
+
The plugin can read almost any document:
|
|
60
58
|
|
|
61
|
-
|
|
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
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
## 💬 Using the Web Interface
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
The plugin includes a web interface for managing documents!
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
- "Remember this: The sky is blue"
|
|
67
|
+
**Access it at:** `http://localhost:3000/api/agents/[your-agent-id]/plugins/knowledge/display`
|
|
69
68
|
|
|
70
|
-
|
|
71
|
-
- "Search your knowledge for quantum computing"
|
|
69
|
+
You can upload, view, and delete documents directly from your browser.
|
|
72
70
|
|
|
73
|
-
##
|
|
71
|
+
## 🎯 Agent Actions
|
|
74
72
|
|
|
75
|
-
|
|
73
|
+
Your agent automatically gets these new abilities:
|
|
76
74
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
```
|
|
75
|
+
- **PROCESS_KNOWLEDGE** - "Remember this document: [file path or text]"
|
|
76
|
+
- **SEARCH_KNOWLEDGE** - "Search your knowledge for [topic]"
|
|
80
77
|
|
|
81
|
-
|
|
78
|
+
## ❓ FAQ
|
|
82
79
|
|
|
83
|
-
|
|
80
|
+
**Q: Do I need any API keys?**
|
|
81
|
+
A: No! It uses your existing OpenAI/Google/Anthropic setup automatically.
|
|
84
82
|
|
|
85
|
-
**
|
|
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.
|
|
86
85
|
|
|
87
|
-
|
|
88
|
-
|
|
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.
|
|
89
88
|
|
|
90
|
-
|
|
89
|
+
**Q: How much does this cost?**
|
|
90
|
+
A: Only the cost of generating embeddings (usually pennies per document).
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
---
|
|
93
93
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
## 🔧 Advanced Configuration (Developers)
|
|
95
|
+
|
|
96
|
+
> **⚠️ Note for Beginners:** The settings below are for advanced users only. The plugin works great without any of this configuration!
|
|
97
97
|
|
|
98
|
-
|
|
98
|
+
<details>
|
|
99
|
+
<summary><strong>🚀 Enhanced Contextual Knowledge (Recommended for Developers)</strong></summary>
|
|
99
100
|
|
|
100
|
-
For better understanding of complex documents:
|
|
101
|
+
For significantly better understanding of complex documents, enable contextual embeddings with caching:
|
|
101
102
|
|
|
102
103
|
```env
|
|
104
|
+
# Enable enhanced contextual understanding
|
|
103
105
|
CTX_KNOWLEDGE_ENABLED=true
|
|
106
|
+
|
|
107
|
+
# Use OpenRouter with Claude for best results + 90% cost savings via caching
|
|
104
108
|
TEXT_PROVIDER=openrouter
|
|
105
109
|
TEXT_MODEL=anthropic/claude-3.5-sonnet
|
|
106
|
-
OPENROUTER_API_KEY=your-api-key
|
|
110
|
+
OPENROUTER_API_KEY=your-openrouter-api-key
|
|
107
111
|
```
|
|
108
112
|
|
|
109
|
-
|
|
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
|
|
110
117
|
|
|
111
|
-
|
|
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)
|
|
112
122
|
|
|
113
|
-
|
|
114
|
-
EMBEDDING_PROVIDER=openai
|
|
115
|
-
TEXT_EMBEDDING_MODEL=text-embedding-3-small
|
|
116
|
-
OPENAI_API_KEY=your-api-key
|
|
117
|
-
```
|
|
123
|
+
</details>
|
|
118
124
|
|
|
119
|
-
|
|
125
|
+
<details>
|
|
126
|
+
<summary><strong>⚙️ Custom Configuration Options</strong></summary>
|
|
120
127
|
|
|
128
|
+
### Document Loading
|
|
121
129
|
```env
|
|
122
|
-
# Document Loading
|
|
123
130
|
LOAD_DOCS_ON_STARTUP=true # Auto-load from docs folder
|
|
124
|
-
KNOWLEDGE_PATH=/custom/path # Custom document path
|
|
125
|
-
|
|
126
|
-
# Contextual Enhancement (improves understanding)
|
|
127
|
-
CTX_KNOWLEDGE_ENABLED=true # Enable contextual embeddings
|
|
131
|
+
KNOWLEDGE_PATH=/custom/path # Custom document path (default: ./docs)
|
|
132
|
+
```
|
|
128
133
|
|
|
129
|
-
|
|
130
|
-
|
|
134
|
+
### Embedding Configuration
|
|
135
|
+
```env
|
|
136
|
+
# Only needed if you're not using a standard AI plugin
|
|
137
|
+
EMBEDDING_PROVIDER=openai # openai | google
|
|
131
138
|
TEXT_EMBEDDING_MODEL=text-embedding-3-small
|
|
132
|
-
EMBEDDING_DIMENSION=1536
|
|
139
|
+
EMBEDDING_DIMENSION=1536 # Vector dimension
|
|
140
|
+
```
|
|
133
141
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
142
|
+
### Text Generation (for Contextual Mode)
|
|
143
|
+
```env
|
|
144
|
+
TEXT_PROVIDER=openrouter # openai | anthropic | openrouter | google
|
|
145
|
+
TEXT_MODEL=anthropic/claude-3.5-sonnet
|
|
146
|
+
```
|
|
137
147
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
148
|
+
### API Keys (as needed)
|
|
149
|
+
```env
|
|
150
|
+
OPENAI_API_KEY=sk-...
|
|
151
|
+
ANTHROPIC_API_KEY=sk-ant-...
|
|
152
|
+
OPENROUTER_API_KEY=sk-or-...
|
|
142
153
|
GOOGLE_API_KEY=your-key
|
|
154
|
+
```
|
|
143
155
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
#
|
|
150
|
-
|
|
151
|
-
MAX_OUTPUT_TOKENS=4096
|
|
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
|
|
152
163
|
```
|
|
153
164
|
|
|
154
|
-
|
|
165
|
+
</details>
|
|
166
|
+
|
|
167
|
+
<details>
|
|
168
|
+
<summary><strong>🔌 API Reference</strong></summary>
|
|
155
169
|
|
|
170
|
+
### HTTP Endpoints
|
|
156
171
|
- `POST /api/agents/{agentId}/plugins/knowledge/documents` - Upload documents
|
|
157
|
-
- `GET /api/agents/{agentId}/plugins/knowledge/documents` - List documents
|
|
172
|
+
- `GET /api/agents/{agentId}/plugins/knowledge/documents` - List all documents
|
|
158
173
|
- `GET /api/agents/{agentId}/plugins/knowledge/documents/{id}` - Get specific document
|
|
159
174
|
- `DELETE /api/agents/{agentId}/plugins/knowledge/documents/{id}` - Delete document
|
|
160
175
|
- `GET /api/agents/{agentId}/plugins/knowledge/display` - Web interface
|
|
161
176
|
|
|
162
177
|
### Programmatic Usage
|
|
163
|
-
|
|
164
178
|
```typescript
|
|
165
179
|
import { KnowledgeService } from '@elizaos/plugin-knowledge';
|
|
166
180
|
|
|
167
181
|
// Add knowledge programmatically
|
|
168
182
|
const result = await knowledgeService.addKnowledge({
|
|
169
|
-
clientDocumentId: 'unique-id',
|
|
170
|
-
content: documentContent,
|
|
183
|
+
clientDocumentId: 'unique-doc-id',
|
|
184
|
+
content: documentContent, // Base64 for PDFs, plain text for others
|
|
171
185
|
contentType: 'application/pdf',
|
|
172
186
|
originalFilename: 'document.pdf',
|
|
173
|
-
worldId:
|
|
174
|
-
roomId:
|
|
175
|
-
entityId:
|
|
187
|
+
worldId: runtime.worldId,
|
|
188
|
+
roomId: runtime.roomId,
|
|
189
|
+
entityId: runtime.entityId,
|
|
190
|
+
metadata: { // Optional
|
|
191
|
+
source: 'upload',
|
|
192
|
+
author: 'John Doe'
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
// Search knowledge
|
|
197
|
+
const searchResults = await knowledgeService.searchKnowledge({
|
|
198
|
+
query: 'quantum computing',
|
|
199
|
+
agentId: runtime.agentId,
|
|
200
|
+
limit: 10
|
|
176
201
|
});
|
|
177
202
|
```
|
|
178
203
|
|
|
179
204
|
</details>
|
|
180
205
|
|
|
206
|
+
<details>
|
|
207
|
+
<summary><strong>🐛 Troubleshooting</strong></summary>
|
|
208
|
+
|
|
209
|
+
### Common Issues
|
|
210
|
+
|
|
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
|
|
214
|
+
|
|
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
|
|
219
|
+
|
|
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
|
|
224
|
+
|
|
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`
|
|
229
|
+
|
|
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
|
|
234
|
+
|
|
235
|
+
</details>
|
|
236
|
+
|
|
181
237
|
## 📝 License
|
|
182
238
|
|
|
183
|
-
See the ElizaOS license for details.
|
|
239
|
+
MIT License - See the main ElizaOS license for details.
|
package/dist/.vite/manifest.json
CHANGED