@elizaos/plugin-knowledge 1.0.6 → 1.0.8

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 CHANGED
@@ -1,183 +1,277 @@
1
1
  # Knowledge Plugin for ElizaOS
2
2
 
3
- This plugin gives your agent the ability to learn from documents and answer questions based on that knowledge.
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
- ## 🚀 Quick Start (No Configuration Needed!)
5
+ ## 🚀 Getting Started (Beginner-Friendly)
6
6
 
7
- If you already have **plugin-openai** configured in your agent, this plugin works automatically! Just add it to your agent and you're done.
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
- import { knowledgePlugin } from '@elizaos/plugin-knowledge';
11
-
12
- // Add to your agent's plugins
13
- plugins: [
14
- '@elizaos/plugin-knowledge',
15
- // ... other plugins
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! Your agent can now process and learn from documents.
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
- 2. **Create a `docs` folder in your project root and add your documents:**
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/ <-- Create this folder
32
+ ├── docs/ Create this folder
37
33
  │ ├── guide.pdf
38
34
  │ ├── manual.txt
39
35
  │ └── notes.md
40
- └── ... other files
36
+ └── package.json
41
37
  ```
42
38
 
43
- 3. **Start your agent** - it will automatically load all documents from the `docs` folder!
39
+ 2. **Add this line to your `.env` file:**
40
+ ```env
41
+ LOAD_DOCS_ON_STARTUP=true
42
+ ```
44
43
 
45
- ### Supported File Types
44
+ 3. **Start your agent** - it will automatically learn from all documents in the `docs` folder!
46
45
 
47
- - 📄 **Documents:** PDF, TXT, MD, DOC, DOCX
48
- - 💻 **Code:** JS, TS, PY, and many more
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
- ## 💬 How to Use
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
- Once documents are loaded, just ask your agent questions naturally:
53
+ Your agent will search through all loaded documents and give you relevant answers!
54
54
 
55
- - "What does the guide say about setup?"
56
- - "Search your knowledge for information about configuration"
57
- - "What do you know about [topic]?"
55
+ ## 📁 Supported File Types
58
56
 
59
- Your agent will search through all loaded documents and provide relevant answers!
57
+ The plugin can read almost any document:
60
58
 
61
- ## 🎯 Actions Available
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
- The plugin provides these actions that your agent can use:
63
+ ## 💬 Using the Web Interface
64
64
 
65
- 1. **PROCESS_KNOWLEDGE** - Add new documents or text to the knowledge base
65
+ The plugin includes a web interface for managing documents!
66
66
 
67
- - "Process the document at /path/to/file.pdf"
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
- 2. **SEARCH_KNOWLEDGE** - Search the knowledge base
71
- - "Search your knowledge for quantum computing"
69
+ You can upload, view, and delete documents directly from your browser.
72
70
 
73
- ## 🌐 Web Interface
71
+ ## 🎯 Agent Actions
74
72
 
75
- The plugin includes a web interface for managing documents! Access it at:
73
+ Your agent automatically gets these new abilities:
76
74
 
77
- ```
78
- http://localhost:3000/api/agents/[your-agent-id]/plugins/knowledge/display
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
- ## ⚠️ Advanced Configuration (Developers Only)
80
+ **Q: Do I need any API keys?**
81
+ A: No! It uses your existing OpenAI/Google/Anthropic setup automatically.
84
82
 
85
- **Note: If you're not a developer, don't use the settings below! The plugin works great with just the quick start setup above.**
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
- <details>
88
- <summary>Click to show advanced configuration options</summary>
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
- ### Custom Document Path
89
+ **Q: How much does this cost?**
90
+ A: Only the cost of generating embeddings (usually pennies per document).
91
91
 
92
- Change where documents are loaded from:
92
+ ---
93
93
 
94
- ```env
95
- KNOWLEDGE_PATH=/path/to/your/documents
96
- ```
94
+ ## 🔧 Advanced Configuration (Developers)
97
95
 
98
- ### Enhanced Contextual Knowledge
96
+ > **⚠️ Note for Beginners:** The settings below are for advanced users only. The plugin works great without any of this configuration!
99
97
 
100
- For better understanding of complex documents:
98
+ <details>
99
+ <summary><strong>🚀 Enhanced Contextual Knowledge (Recommended for Developers)</strong></summary>
100
+
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
- ### Custom Embedding Configuration
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
- If not using plugin-openai:
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
- ```env
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
- ### All Configuration Options
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
- # Embedding Provider (if not using plugin-openai)
130
- EMBEDDING_PROVIDER=openai # or google
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
- # Text Generation Provider (for contextual mode)
135
- TEXT_PROVIDER=openai # or anthropic, openrouter, google
136
- TEXT_MODEL=gpt-4o # Model name for your provider
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
- # API Keys (based on providers used)
139
- OPENAI_API_KEY=your-key
140
- ANTHROPIC_API_KEY=your-key
141
- OPENROUTER_API_KEY=your-key
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
- # Rate Limiting
145
- MAX_CONCURRENT_REQUESTS=30
146
- REQUESTS_PER_MINUTE=60
147
- TOKENS_PER_MINUTE=150000
148
-
149
- # Token Limits
150
- MAX_INPUT_TOKENS=4000
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
- ### API Routes Reference
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: 'world-id',
174
- roomId: 'room-id',
175
- entityId: 'entity-id',
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
+ ### File Upload Configuration
236
+
237
+ #### Automatic MIME Type Correction
238
+ The frontend automatically corrects MIME types for code and document files to ensure proper processing:
239
+
240
+ ```typescript
241
+ const getCorrectMimeType = (file: File): string => {
242
+ const filename = file.name.toLowerCase();
243
+ const ext = filename.split('.').pop() || '';
244
+
245
+ // Map common text file extensions to text/plain
246
+ const textExtensions = [
247
+ 'ts', 'tsx', 'js', 'jsx', 'mjs', 'cjs',
248
+ 'py', 'pyw', 'pyi', 'java', 'c', 'cpp', 'cc', 'cxx', 'h', 'hpp',
249
+ 'cs', 'php', 'rb', 'go', 'rs', 'swift', 'kt', 'kts', 'scala',
250
+ // ... and many more
251
+ ];
252
+
253
+ if (textExtensions.includes(ext)) {
254
+ return 'text/plain';
255
+ } else if (['md', 'markdown'].includes(ext)) {
256
+ return 'text/markdown';
257
+ } else if (ext === 'json') {
258
+ return 'application/json';
259
+ }
260
+ // ... additional mappings
261
+
262
+ return file.type || 'application/octet-stream';
263
+ };
264
+ ```
265
+
266
+ #### Supported File Types
267
+
268
+ - **Documents**: PDF, DOC, DOCX
269
+ - **Code**: JS, TS, PY, JAVA, C, CPP, etc.
270
+ - **Text**: TXT, MD, CSV, JSON, XML, HTML
271
+ - **Configuration**: ENV, CFG, INI, YAML, YML
272
+
273
+ </details>
274
+
181
275
  ## 📝 License
182
276
 
183
- See the ElizaOS license for details.
277
+ MIT License - See the main ElizaOS license for details.
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "index.html": {
3
- "file": "assets/index-DlJcnv-R.js",
3
+ "file": "assets/index-BMDX6vvo.js",
4
4
  "name": "index",
5
5
  "src": "index.html",
6
6
  "isEntry": true,
7
7
  "css": [
8
- "assets/index-DiVvUMt0.css"
8
+ "assets/index-o1rKIvUo.css"
9
9
  ]
10
10
  }
11
11
  }