@avalw/search-worker 1.1.0 → 2.1.1

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,303 +1,295 @@
1
1
  # @avalw/search-worker
2
2
 
3
- Free privacy-focused search API in exchange for compute power.
3
+ > Distributed Cache Worker for AVALW Search Network
4
4
 
5
- [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
6
- [![Node.js Version](https://img.shields.io/badge/node-%3E%3D14.0.0-brightgreen)](https://nodejs.org)
5
+ Contribute your computer's cache storage to the AVALW search network and earn free API access in return.
7
6
 
8
- ## What is AVALW Worker?
7
+ ## How It Works
9
8
 
10
- AVALW Worker is a lightweight Node.js application that runs on your server and contributes CPU power to the AVALW distributed network. In return, you get **free access** to the AVALW Search API - a privacy-focused search engine that doesn't track users. Your API quota scales with your contribution.
9
+ ```
10
+ ┌─────────────────────────────────────────────────────────────────────────┐
11
+ │ AVALW DISTRIBUTED CACHE │
12
+ ├─────────────────────────────────────────────────────────────────────────┤
13
+ │ │
14
+ │ ┌─────────┐ ┌──────────────┐ ┌─────────────┐ │
15
+ │ │ User │────────▶│ avalw.org │────────▶│ Coordinator │ │
16
+ │ │ Search │ │ Server │ │ Server │ │
17
+ │ └─────────┘ └──────────────┘ └──────┬──────┘ │
18
+ │ │ │
19
+ │ ┌─────────────────────────┼───────┐ │
20
+ │ │ │ │ │
21
+ │ ▼ ▼ ▼ │
22
+ │ ┌──────────┐ ┌──────────┐ ┌──────┐ │
23
+ │ │ Worker 1 │ │ Worker 2 │ │ ... │ │
24
+ │ │ Cache │ │ Cache │ │ │ │
25
+ │ └──────────┘ └──────────┘ └──────┘ │
26
+ │ │
27
+ │ YOUR WORKER stores search results and serves them when requested │
28
+ │ │
29
+ └─────────────────────────────────────────────────────────────────────────┘
30
+ ```
11
31
 
12
- **No tracking. No ads. No data collection. Just search.**
32
+ ### The Flow
13
33
 
14
- ## How It Works
34
+ ```
35
+ 1. USER SEARCHES 2. CHECK CACHE 3. SERVE RESULT
36
+ "spotify"
37
+ ┌─────────────┐
38
+ ┌──────┐ │ Coordinator │ ┌──────────┐
39
+ │ User │──search──▶ │ checks │──hit──▶ │ Worker │──result──▶ User
40
+ └──────┘ │ workers │ │ serves │
41
+ └─────────────┘ └──────────┘
42
+
43
+ miss │
44
+
45
+ ┌──────────┐
46
+ │ Server │──result──▶ User + Distribute to Workers
47
+ │ process │
48
+ └──────────┘
49
+ ```
50
+
51
+ ### What Your Worker Does vs. Doesn't Do
15
52
 
16
53
  ```
17
- ┌─────────────────────────────────────────────────────────────────────────────┐
18
- │ AVALW WORKER SYSTEM │
19
- ├─────────────────────────────────────────────────────────────────────────────┤
20
- │ │
21
- YOUR SERVER AVALW NETWORK YOUR USERS │
22
- ─────────── ──────────── ────────── │
23
- │ │
24
- ┌─────────────┐ ┌─────────────┐ │
25
- │ │ Worker │ ───────────────►│ Compute │ │
26
- │ │ Process │ Contributes │ Pool │ │
27
- │ │ │ Core-Hours │ │ │
28
- │ │ CPU: ████░ │ │ ┌─┐┌─┐┌─┐┌─┐│ │
29
- │ │ 70% │ │ └─┘└─┘└─┘└─┘│ │
30
- │ └─────────────┘ └──────┬──────┘ │
31
- │ │ │ │
32
- │ │ Reports: │ Calculates: │
33
- │ │ • CPU cores │ • Core-hours │
34
- │ │ • CPU speed (GHz) │ • Your tier │
35
- │ │ • Usage % │ • API quota │
36
- │ │ • Online time │ │
37
- │ ▼ ▼ │
38
- │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
39
- │ │ Your App │◄────────────────│ Search API │◄───────│ Search │ │
40
- │ │ │ Free access │ (quota │ │ Query │ │
41
- │ │ // search │ based on │ based) │ │ │ │
42
- │ │ fetch(..); │ contribution │ │ │ "weather" │ │
43
- │ └─────────────┘ └─────────────┘ └─────────────┘ │
44
- │ │
45
- └─────────────────────────────────────────────────────────────────────────────┘
46
- ```
47
-
48
- ## Core-Hours System
49
-
50
- Unlike simple percentage-based systems, AVALW uses **Core-Hours** - a fair metric that accounts for your actual hardware contribution.
51
-
52
- ### What is a Core-Hour?
53
-
54
- ```
55
- ┌─────────────────────────────────────────────────────────────────────────────┐
56
- │ CORE-HOUR CALCULATION │
57
- ├─────────────────────────────────────────────────────────────────────────────┤
58
- │ │
59
- │ Core-Hours = CPU Cores × (CPU Speed ÷ 3.0 GHz) × Usage% × Hours Online │
60
- │ │
61
- │ ═══════════════════════════════════════════════════════════════════════ │
62
- │ │
63
- │ EXAMPLE: Intel i7-10700 running for 24 hours at 50% │
64
- │ │
65
- │ • Cores: 8 │
66
- │ • Speed: 2.9 GHz base (normalized to 3.0 GHz baseline) │
67
- │ • Usage: 50% │
68
- │ • Time: 24 hours │
69
- │ │
70
- │ Calculation: 8 × (2.9 ÷ 3.0) × 0.50 × 24 = 92.8 core-hours/day │
71
- │ │
72
- └─────────────────────────────────────────────────────────────────────────────┘
73
- ```
74
-
75
- ### Tiers Based on Core-Hours
76
-
77
- | Tier | Requests/Day | Core-Hours/Day | Minimum Cores |
78
- |------|--------------|----------------|---------------|
79
- | **Starter** | 1,000 | 3 | 3 cores |
80
- | **Basic** | 5,000 | 12 | 4 cores |
81
- | **Pro** | 20,000 | 36 | 6 cores |
82
- | **Business** | 50,000 | 72 | 8 cores |
83
- | **Enterprise** | 500,000 | 240 | 16 cores |
84
-
85
- ## Real CPU Examples
86
-
87
- ### Desktop CPUs
88
-
89
- ```
90
- ┌─────────────────────────────────────────────────────────────────────────────┐
91
- │ DESKTOP CPU EXAMPLES │
92
- ├─────────────────────────────────────────────────────────────────────────────┤
93
- │ │
94
- │ ┌─────────────────────────────────────────────────────────────────────┐ │
95
- │ │ Intel Core i5-10400 (6 cores @ 2.9 GHz) │ │
96
- │ ├─────────────────────────────────────────────────────────────────────┤ │
97
- │ │ At 50% for 24h: 6 × 0.97 × 0.50 × 24 = 69.8 core-hours │ │
98
- │ │ ✓ Qualifies for: PRO tier (20,000 requests/day) │ │
99
- │ │ │ │
100
- │ │ At 30% for 24h: 6 × 0.97 × 0.30 × 24 = 41.9 core-hours │ │
101
- │ │ ✓ Qualifies for: PRO tier (20,000 requests/day) │ │
102
- │ └─────────────────────────────────────────────────────────────────────┘ │
103
- │ │
104
- │ ┌─────────────────────────────────────────────────────────────────────┐ │
105
- │ │ Intel Core i7-10700 (8 cores @ 2.9 GHz) │ │
106
- │ ├─────────────────────────────────────────────────────────────────────┤ │
107
- │ │ At 50% for 24h: 8 × 0.97 × 0.50 × 24 = 93.1 core-hours │ │
108
- │ │ ✓ Qualifies for: BUSINESS tier (50,000 requests/day) │ │
109
- │ │ │ │
110
- │ │ At 25% for 24h: 8 × 0.97 × 0.25 × 24 = 46.6 core-hours │ │
111
- │ │ ✓ Qualifies for: PRO tier (20,000 requests/day) │ │
112
- │ └─────────────────────────────────────────────────────────────────────┘ │
113
- │ │
114
- │ ┌─────────────────────────────────────────────────────────────────────┐ │
115
- │ │ Intel Core i9-10900 (10 cores @ 2.8 GHz) │ │
116
- │ ├─────────────────────────────────────────────────────────────────────┤ │
117
- │ │ At 50% for 24h: 10 × 0.93 × 0.50 × 24 = 111.6 core-hours │ │
118
- │ │ ✓ Qualifies for: BUSINESS tier (50,000 requests/day) │ │
119
- │ │ │ │
120
- │ │ At 80% for 24h: 10 × 0.93 × 0.80 × 24 = 178.6 core-hours │ │
121
- │ │ ✓ Qualifies for: BUSINESS tier (50,000 requests/day) │ │
122
- │ └─────────────────────────────────────────────────────────────────────┘ │
123
- │ │
124
- │ ┌─────────────────────────────────────────────────────────────────────┐ │
125
- │ │ AMD Ryzen 5 5600X (6 cores @ 3.7 GHz) │ │
126
- │ ├─────────────────────────────────────────────────────────────────────┤ │
127
- │ │ At 50% for 24h: 6 × 1.23 × 0.50 × 24 = 88.6 core-hours │ │
128
- │ │ ✓ Qualifies for: BUSINESS tier (50,000 requests/day) │ │
129
- │ └─────────────────────────────────────────────────────────────────────┘ │
130
- │ │
131
- │ ┌─────────────────────────────────────────────────────────────────────┐ │
132
- │ │ AMD Ryzen 7 5800X (8 cores @ 3.8 GHz) │ │
133
- │ ├─────────────────────────────────────────────────────────────────────┤ │
134
- │ │ At 50% for 24h: 8 × 1.27 × 0.50 × 24 = 121.9 core-hours │ │
135
- │ │ ✓ Qualifies for: BUSINESS tier (50,000 requests/day) │ │
136
- │ └─────────────────────────────────────────────────────────────────────┘ │
137
- │ │
138
- └─────────────────────────────────────────────────────────────────────────────┘
139
- ```
140
-
141
- ### Server CPUs
142
-
143
- ```
144
- ┌─────────────────────────────────────────────────────────────────────────────┐
145
- │ SERVER CPU EXAMPLES │
146
- ├─────────────────────────────────────────────────────────────────────────────┤
147
- │ │
148
- │ ┌─────────────────────────────────────────────────────────────────────┐ │
149
- │ │ Intel Xeon E-2288G (8 cores @ 3.7 GHz) │ │
150
- │ ├─────────────────────────────────────────────────────────────────────┤ │
151
- │ │ At 30% for 24h: 8 × 1.23 × 0.30 × 24 = 70.8 core-hours │ │
152
- │ │ ✓ Qualifies for: PRO tier (20,000 requests/day) │ │
153
- │ │ │ │
154
- │ │ At 50% for 24h: 8 × 1.23 × 0.50 × 24 = 118.1 core-hours │ │
155
- │ │ ✓ Qualifies for: BUSINESS tier (50,000 requests/day) │ │
156
- │ └─────────────────────────────────────────────────────────────────────┘ │
157
- │ │
158
- │ ┌─────────────────────────────────────────────────────────────────────┐ │
159
- │ │ AMD EPYC 7302 (16 cores @ 3.0 GHz) │ │
160
- │ ├─────────────────────────────────────────────────────────────────────┤ │
161
- │ │ At 30% for 24h: 16 × 1.00 × 0.30 × 24 = 115.2 core-hours │ │
162
- │ │ ✓ Qualifies for: BUSINESS tier (50,000 requests/day) │ │
163
- │ │ │ │
164
- │ │ At 60% for 24h: 16 × 1.00 × 0.60 × 24 = 230.4 core-hours │ │
165
- │ │ ✓ Qualifies for: BUSINESS tier (50,000 requests/day) │ │
166
- │ └─────────────────────────────────────────────────────────────────────┘ │
167
- │ │
168
- │ ┌─────────────────────────────────────────────────────────────────────┐ │
169
- │ │ AMD EPYC 7742 (64 cores @ 2.25 GHz) │ │
170
- │ ├─────────────────────────────────────────────────────────────────────┤ │
171
- │ │ At 20% for 24h: 64 × 0.75 × 0.20 × 24 = 230.4 core-hours │ │
172
- │ │ ✓ Qualifies for: BUSINESS tier (50,000 requests/day) │ │
173
- │ │ │ │
174
- │ │ At 50% for 24h: 64 × 0.75 × 0.50 × 24 = 576.0 core-hours │ │
175
- │ │ ✓ Qualifies for: ENTERPRISE tier (500,000 requests/day) │ │
176
- │ └─────────────────────────────────────────────────────────────────────┘ │
177
- │ │
178
- └─────────────────────────────────────────────────────────────────────────────┘
179
- ```
180
-
181
- ### VPS / Cloud Examples
182
-
183
- ```
184
- ┌─────────────────────────────────────────────────────────────────────────────┐
185
- │ VPS / CLOUD EXAMPLES │
186
- ├─────────────────────────────────────────────────────────────────────────────┤
187
- │ │
188
- │ ┌─────────────────────────────────────────────────────────────────────┐ │
189
- │ │ Basic VPS (2 vCPU @ 2.5 GHz) - ~$5/month │ │
190
- │ ├─────────────────────────────────────────────────────────────────────┤ │
191
- │ │ At 80% for 24h: 2 × 0.83 × 0.80 × 24 = 31.9 core-hours │ │
192
- │ │ ✗ Not enough for Starter (needs 3 cores minimum) │ │
193
- │ └─────────────────────────────────────────────────────────────────────┘ │
194
- │ │
195
- │ ┌─────────────────────────────────────────────────────────────────────┐ │
196
- │ │ Standard VPS (4 vCPU @ 2.5 GHz) - ~$20/month │ │
197
- │ ├─────────────────────────────────────────────────────────────────────┤ │
198
- │ │ At 50% for 24h: 4 × 0.83 × 0.50 × 24 = 39.8 core-hours │ │
199
- │ │ ✓ Qualifies for: PRO tier (20,000 requests/day) │ │
200
- │ └─────────────────────────────────────────────────────────────────────┘ │
201
- │ │
202
- │ ┌─────────────────────────────────────────────────────────────────────┐ │
203
- │ │ Premium VPS (8 vCPU @ 3.0 GHz) - ~$80/month │ │
204
- │ ├─────────────────────────────────────────────────────────────────────┤ │
205
- │ │ At 50% for 24h: 8 × 1.00 × 0.50 × 24 = 96.0 core-hours │ │
206
- │ │ ✓ Qualifies for: BUSINESS tier (50,000 requests/day) │ │
207
- │ └─────────────────────────────────────────────────────────────────────┘ │
208
- │ │
209
- │ ┌─────────────────────────────────────────────────────────────────────┐ │
210
- │ │ AWS EC2 c5.4xlarge (16 vCPU @ 3.4 GHz) │ │
211
- │ ├─────────────────────────────────────────────────────────────────────┤ │
212
- │ │ At 40% for 24h: 16 × 1.13 × 0.40 × 24 = 173.6 core-hours │ │
213
- │ │ ✓ Qualifies for: BUSINESS tier (50,000 requests/day) │ │
214
- │ │ │ │
215
- │ │ At 70% for 24h: 16 × 1.13 × 0.70 × 24 = 303.7 core-hours │ │
216
- │ │ ✓ Qualifies for: ENTERPRISE tier (500,000 requests/day) │ │
217
- │ └─────────────────────────────────────────────────────────────────────┘ │
218
- │ │
219
- └─────────────────────────────────────────────────────────────────────────────┘
54
+ ✅ DOES ❌ DOESN'T
55
+ ───────────────────────────────── ─────────────────────────────────
56
+ • Store search RESULTS • Have the search INDEX
57
+ • Serve cached results • Process raw documents
58
+ Use 50-200MB RAM • Use significant CPU
59
+ • Use 500MB-2GB disk • Access your files
60
+ • Connect via WebSocket • Run arbitrary code
61
+ • Earn you API access • Collect your data
220
62
  ```
221
63
 
222
64
  ## Quick Start
223
65
 
224
- ### 1. Get Your Token
66
+ ```bash
67
+ # 1. Get your token at https://worker.avalw.org
68
+ # 2. Run the worker:
69
+ npx @avalw/search-worker --token YOUR_TOKEN
70
+ ```
225
71
 
226
- Visit [worker.avalw.org](https://worker.avalw.org) and create a free account. You'll receive:
227
- - **Account Hash** - Your unique identifier (save this!)
228
- - **Worker Token** - Used to run the worker
72
+ That's it! Your worker will connect and start contributing.
229
73
 
230
- ### 2. Install the Worker
74
+ ## Installation
231
75
 
232
76
  ```bash
77
+ # Global install
233
78
  npm install -g @avalw/search-worker
79
+
80
+ # Or use npx (no install needed)
81
+ npx @avalw/search-worker --token YOUR_TOKEN
234
82
  ```
235
83
 
236
- ### 3. Run the Worker
84
+ ## What's New in v2.1.0
237
85
 
238
- ```bash
239
- avalw-worker YOUR_WORKER_TOKEN
240
86
  ```
87
+ ┌────────────────────────────────────────────────────────────────┐
88
+ │ INTELLIGENT CACHE SYSTEM │
89
+ ├────────────────────────────────────────────────────────────────┤
90
+ │ │
91
+ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
92
+ │ │ Size Limits │ │ Time-Based │ │ Popularity │ │
93
+ │ │ 100MB - 2GB │ │ Eviction │ │ Scoring │ │
94
+ │ └─────────────┘ └─────────────┘ └─────────────┘ │
95
+ │ │
96
+ │ • Cache up to 2GB of search results │
97
+ │ • Auto-remove queries unused for 7+ days │
98
+ │ • Popular queries stay cached longer │
99
+ │ • Background cleanup every hour │
100
+ │ │
101
+ └────────────────────────────────────────────────────────────────┘
102
+ ```
103
+
104
+ ## Command Line Options
105
+
106
+ ```bash
107
+ # Basic usage (500MB cache, 7 day retention)
108
+ npx @avalw/search-worker --token abc123
241
109
 
242
- You'll see real-time stats:
110
+ # Custom cache size (100-2048 MB)
111
+ npx @avalw/search-worker --token abc123 --cache-size 1024
112
+
113
+ # Custom retention (1-30 days)
114
+ npx @avalw/search-worker --token abc123 --max-age 14
115
+
116
+ # Full customization
117
+ npx @avalw/search-worker \
118
+ --token abc123 \
119
+ --cache-size 1024 \
120
+ --max-age 14
243
121
  ```
244
- ╔═══════════════════════════════════════════════════════════════════╗
245
- ║ AVALW Search Worker v1.1.0 ║
246
- ╠═══════════════════════════════════════════════════════════════════╣
247
- ║ Free Search API in exchange for compute ║
248
- ╚═══════════════════════════════════════════════════════════════════╝
249
122
 
250
- System Info:
251
- ├─ CPU: Intel(R) Core(TM) i7-10700 @ 2.90GHz
252
- ├─ Cores: 8
253
- ├─ Speed Factor: 0.97x (normalized to 3.0 GHz)
254
- └─ Memory: 32 GB
123
+ ### All Options
255
124
 
256
- Worker Status:
257
- ├─ Token: abc123def456...
258
- ├─ API URL: https://worker.avalw.org
259
- └─ Target Usage: 50%
125
+ ```
126
+ ┌──────────────────┬─────────────────┬───────────────────────────────────┐
127
+ Option │ Default │ Description │
128
+ ├──────────────────┼─────────────────┼───────────────────────────────────┤
129
+ │ -t, --token │ $AVALW_TOKEN │ Your worker authentication token │
130
+ │ -s, --cache-size │ 500 │ Max cache size in MB (100-2048) │
131
+ │ -a, --max-age │ 7 │ Days to keep unused queries (1-30)│
132
+ │ -h, --help │ │ Show help │
133
+ │ -v, --version │ │ Show version │
134
+ └──────────────────┴─────────────────┴───────────────────────────────────┘
135
+ ```
260
136
 
261
- [10:30:45] Heartbeat OK
262
- ├─ Core-Hours Today: 46.5 / 72 needed for BUSINESS
263
- ├─ Current Tier: PRO (20,000 req/day)
264
- ├─ Usage Today: 1,234 / 20,000
265
- └─ Online: 12h 35m
137
+ ### Environment Variables
266
138
 
267
- Press Ctrl+C to stop.
139
+ ```bash
140
+ export AVALW_WORKER_TOKEN=your-token-here
141
+ export AVALW_CACHE_SIZE_MB=1024
142
+ export AVALW_MAX_AGE_DAYS=14
143
+ npx @avalw/search-worker
268
144
  ```
269
145
 
270
- ### 4. Use the Search API
146
+ ## Programmatic Usage
271
147
 
272
148
  ```javascript
273
- const response = await fetch(
274
- 'https://worker.avalw.org/api/search?q=your+query&token=YOUR_TOKEN'
275
- );
276
- const results = await response.json();
149
+ const { createWorker } = require('@avalw/search-worker');
150
+
151
+ const worker = createWorker({
152
+ workerToken: 'your-token-here',
153
+
154
+ // Cache configuration
155
+ cacheSizeMB: 1024, // 1GB cache
156
+ maxAgeDays: 14, // 14 day retention
157
+
158
+ // Event handlers
159
+ onConnected: (w) => console.log('Connected to coordinator'),
160
+ onDisconnected: (w) => console.log('Disconnected'),
161
+ onCacheHit: (key) => console.log('Served:', key),
162
+ onCacheStore: (key) => console.log('Cached:', key),
163
+ onError: (err) => console.error('Error:', err)
164
+ });
165
+
166
+ // Connect
167
+ worker.connect();
168
+
169
+ // Get stats
170
+ const stats = worker.getStats();
171
+ console.log(`Cache: ${stats.cache.sizeFormatted} / ${stats.cache.maxSizeFormatted}`);
172
+ console.log(`Hit rate: ${stats.hitRate}%`);
173
+
174
+ // Runtime configuration
175
+ worker.setCacheSize(2048); // Change to 2GB
176
+ worker.setCacheMaxAge(30); // Change to 30 days
177
+
178
+ // Cleanup
179
+ worker.disconnect();
277
180
  ```
278
181
 
279
- ## Running as a Service
182
+ ## API Tiers & Rewards
280
183
 
281
- ### Using PM2 (Recommended)
184
+ Your contribution is measured in Core-Hours:
282
185
 
283
- ```bash
284
- # Install PM2
285
- npm install -g pm2
186
+ ```
187
+ ┌─────────────────────────────────────────────────────────────────────┐
188
+ │ CORE-HOURS FORMULA │
189
+ ├─────────────────────────────────────────────────────────────────────┤
190
+ │ │
191
+ │ Core-Hours = Cores × (CPU Speed ÷ 3.0 GHz) × Usage% × Hours │
192
+ │ │
193
+ │ Example: 8 cores × (3.5 GHz ÷ 3.0 GHz) × 80% × 1 hour │
194
+ │ = 8 × 1.17 × 0.8 × 1 = 7.5 Core-Hours │
195
+ │ │
196
+ └─────────────────────────────────────────────────────────────────────┘
197
+ ```
286
198
 
287
- # Start worker with 50% CPU target
288
- pm2 start avalw-worker -- YOUR_WORKER_TOKEN
199
+ ### Tier Benefits
289
200
 
290
- # Or specify custom CPU percentage
291
- pm2 start avalw-worker -- YOUR_WORKER_TOKEN --cpu 30
201
+ ```
202
+ ┌─────────────┬────────────┬───────────┬─────────────────┐
203
+ │ Tier │ Core-Hours │ Min Cores │ API Requests │
204
+ ├─────────────┼────────────┼───────────┼─────────────────┤
205
+ │ Starter │ 3 │ 3 │ 1,000/day │
206
+ │ Basic │ 12 │ 4 │ 5,000/day │
207
+ │ Pro │ 36 │ 6 │ 20,000/day │
208
+ │ Business │ 72 │ 8 │ 50,000/day │
209
+ │ Enterprise │ 240 │ 16 │ 500,000/day │
210
+ └─────────────┴────────────┴───────────┴─────────────────┘
211
+ ```
212
+
213
+ ## Intelligent Cache Details
214
+
215
+ ### How Eviction Works
216
+
217
+ ```
218
+ ┌─────────────────────────────────────────────────────────────┐
219
+ │ EVICTION PRIORITY │
220
+ ├─────────────────────────────────────────────────────────────┤
221
+ │ │
222
+ │ 1. EXPIRED TTL │
223
+ │ └── Items past their time-to-live (5 min default) │
224
+ │ │
225
+ │ 2. MAX AGE EXCEEDED │
226
+ │ └── Items not accessed for N days (7 days default) │
227
+ │ │
228
+ │ 3. LOWEST POPULARITY │
229
+ │ └── Score = log2(accessCount) × recency × stability │
230
+ │ │
231
+ │ Priority: 1 > 2 > 3 (expired items removed first) │
232
+ │ │
233
+ └─────────────────────────────────────────────────────────────┘
234
+ ```
235
+
236
+ ### Popularity Scoring
237
+
238
+ ```
239
+ Score = log2(accessCount + 1) × recencyFactor × stabilityFactor
240
+
241
+ ┌─────────────────┬─────────────────────────────────────────┐
242
+ │ Factor │ Description │
243
+ ├─────────────────┼─────────────────────────────────────────┤
244
+ │ accessCount │ Number of times the query was accessed │
245
+ │ recencyFactor │ 1.0 → 0.0 over 7 days since last access │
246
+ │ stabilityFactor │ Higher for consistent access patterns │
247
+ └─────────────────┴─────────────────────────────────────────┘
248
+
249
+ Example: Query accessed 100 times, last accessed 1 day ago
250
+ Score = log2(101) × 0.86 × 1.2 = 6.65 × 0.86 × 1.2 = 6.86
251
+ ```
252
+
253
+ ## Resource Usage
254
+
255
+ ```
256
+ ┌──────────────────────────────────────────────────────────┐
257
+ │ TYPICAL RESOURCE USAGE │
258
+ ├──────────────────────────────────────────────────────────┤
259
+ │ │
260
+ │ CPU: 1-5% [▓░░░░░░░░░░░░░░░░░░░] minimal │
261
+ │ RAM: 50-200MB [▓▓▓▓░░░░░░░░░░░░░░░░] light │
262
+ │ Disk: 500MB-2GB [▓▓▓▓▓▓▓▓░░░░░░░░░░░░] configurable │
263
+ │ Network: Low [▓▓░░░░░░░░░░░░░░░░░░] WebSocket │
264
+ │ │
265
+ └──────────────────────────────────────────────────────────┘
266
+ ```
267
+
268
+ ## Privacy & Security
292
269
 
293
- # Save for auto-restart
294
- pm2 save
295
- pm2 startup
296
270
  ```
271
+ ┌────────────────────────────────────────────────────────────────┐
272
+ │ PRIVACY GUARANTEES │
273
+ ├────────────────────────────────────────────────────────────────┤
274
+ │ │
275
+ │ ✓ Workers cache RESULTS only, not the search index │
276
+ │ ✓ No IP addresses are logged │
277
+ │ ✓ Workers don't see who requested a search │
278
+ │ ✓ All communication encrypted (WSS/HTTPS) │
279
+ │ ✓ No access to your local files │
280
+ │ ✓ Open source - audit the code yourself │
281
+ │ │
282
+ └────────────────────────────────────────────────────────────────┘
283
+ ```
284
+
285
+ ## Running as a Service
297
286
 
298
- ### Using systemd (Linux)
287
+ ### Linux (systemd)
299
288
 
300
- Create `/etc/systemd/system/avalw-worker.service`:
289
+ ```bash
290
+ # Create service file
291
+ sudo nano /etc/systemd/system/avalw-worker.service
292
+ ```
301
293
 
302
294
  ```ini
303
295
  [Unit]
@@ -306,8 +298,11 @@ After=network.target
306
298
 
307
299
  [Service]
308
300
  Type=simple
309
- User=your-user
310
- ExecStart=/usr/bin/avalw-worker YOUR_WORKER_TOKEN
301
+ User=nobody
302
+ Environment=AVALW_WORKER_TOKEN=your-token-here
303
+ Environment=AVALW_CACHE_SIZE_MB=1024
304
+ Environment=AVALW_MAX_AGE_DAYS=14
305
+ ExecStart=/usr/bin/npx @avalw/search-worker
311
306
  Restart=always
312
307
  RestartSec=10
313
308
 
@@ -315,136 +310,103 @@ RestartSec=10
315
310
  WantedBy=multi-user.target
316
311
  ```
317
312
 
318
- Then:
319
313
  ```bash
314
+ # Enable and start
315
+ sudo systemctl daemon-reload
320
316
  sudo systemctl enable avalw-worker
321
317
  sudo systemctl start avalw-worker
318
+
319
+ # Check status
320
+ sudo systemctl status avalw-worker
322
321
  ```
323
322
 
324
- ### Using Docker
323
+ ### Docker
325
324
 
326
325
  ```dockerfile
327
- FROM node:20-alpine
326
+ FROM node:18-alpine
328
327
  RUN npm install -g @avalw/search-worker
329
- CMD ["avalw-worker", "YOUR_WORKER_TOKEN"]
328
+ ENV AVALW_WORKER_TOKEN=your-token-here
329
+ ENV AVALW_CACHE_SIZE_MB=1024
330
+ ENV AVALW_MAX_AGE_DAYS=14
331
+ CMD ["avalw-worker"]
330
332
  ```
331
333
 
332
334
  ```bash
333
335
  docker build -t avalw-worker .
334
- docker run -d --name avalw-worker avalw-worker
336
+ docker run -d --name avalw avalw-worker
335
337
  ```
336
338
 
337
- ## API Reference
338
-
339
- ### Search Endpoint
339
+ ### PM2
340
340
 
341
- ```
342
- GET https://worker.avalw.org/api/search
341
+ ```bash
342
+ pm2 start avalw-worker --name "avalw" -- --token YOUR_TOKEN --cache-size 1024
343
+ pm2 save
344
+ pm2 startup
343
345
  ```
344
346
 
345
- | Parameter | Type | Required | Description |
346
- |-----------|--------|----------|--------------------------------|
347
- | q | string | Yes | Search query |
348
- | token | string | Yes | Your worker token |
349
- | page | number | No | Page number (default: 1) |
350
- | limit | number | No | Results per page (default: 10) |
347
+ ### Windows (Task Scheduler)
351
348
 
352
- **Response:**
353
- ```json
354
- {
355
- "success": true,
356
- "results": [
357
- {
358
- "title": "Example Result",
359
- "url": "https://example.com",
360
- "snippet": "This is a snippet..."
361
- }
362
- ],
363
- "total": 100,
364
- "page": 1,
365
- "tier": "PRO",
366
- "usage": {
367
- "today": 1234,
368
- "limit": 20000,
369
- "core_hours": 46.5
370
- }
371
- }
349
+ ```batch
350
+ @echo off
351
+ set AVALW_WORKER_TOKEN=your-token-here
352
+ set AVALW_CACHE_SIZE_MB=1024
353
+ npx @avalw/search-worker
372
354
  ```
373
355
 
374
- ## FAQ
375
-
376
- ### Why do I need minimum 3 cores?
377
-
378
- The AVALW network requires meaningful contributions to remain sustainable. A 3-core minimum ensures:
379
- - Fair distribution of compute power
380
- - Quality of service for all users
381
- - Sustainable network operation
382
-
383
- ### Can I run on a 2-core VPS?
384
-
385
- Unfortunately, 2 cores don't meet the minimum requirement. Consider:
386
- - Upgrading to a 4-core VPS
387
- - Running on a different server with more cores
388
- - Combining with another server (coming soon: multi-worker support)
389
-
390
- ### How is my tier calculated?
391
-
392
- Your tier is recalculated every hour based on your rolling 24-hour core-hours contribution. The formula:
356
+ ## Troubleshooting
393
357
 
394
358
  ```
395
- Core-Hours = Cores × (Speed ÷ 3.0) × Usage% × Hours
359
+ ┌─────────────────────────────────────────────────────────────────┐
360
+ │ COMMON ISSUES │
361
+ ├─────────────────────────────────────────────────────────────────┤
362
+ │ │
363
+ │ "Connection refused" │
364
+ │ └── Check internet connection, firewall settings │
365
+ │ │
366
+ │ "Invalid token" │
367
+ │ └── Get a new token at https://worker.avalw.org │
368
+ │ │
369
+ │ "Cache full, high eviction rate" │
370
+ │ └── Increase --cache-size or decrease --max-age │
371
+ │ │
372
+ │ "Memory usage too high" │
373
+ │ └── Decrease --cache-size (minimum 100MB) │
374
+ │ │
375
+ │ "Worker keeps disconnecting" │
376
+ │ └── Check network stability, worker will auto-reconnect │
377
+ │ │
378
+ └─────────────────────────────────────────────────────────────────┘
396
379
  ```
397
380
 
398
- ### What if my server goes offline?
399
-
400
- Your core-hours accumulate only while online. If you go offline:
401
- - Your accumulated core-hours for the day remain
402
- - Your tier may drop if you don't maintain the required hours
403
- - API calls will fail until your worker reconnects
381
+ ## System Requirements
404
382
 
405
- ## Security
406
-
407
- - **No data collection**: We don't log search queries
408
- - **No tracking**: No cookies, no fingerprinting
409
- - **Open protocol**: Transparent heartbeat mechanism
410
- - **Your server, your control**: Worker runs on your infrastructure
383
+ ```
384
+ ┌────────────────┬────────────────────────────────────┐
385
+ Component │ Requirement │
386
+ ├────────────────┼────────────────────────────────────┤
387
+ Node.js │ 14.0.0 or higher │
388
+ CPU │ 3+ cores for Starter tier │
389
+ │ RAM │ 512MB+ free │
390
+ │ Disk │ 500MB - 2GB for cache │
391
+ │ Network │ Stable internet, WebSocket support │
392
+ │ OS │ Windows, macOS, Linux │
393
+ └────────────────┴────────────────────────────────────┘
394
+ ```
411
395
 
412
396
  ## Support
413
397
 
414
- - Website: [worker.avalw.org](https://worker.avalw.org)
398
+ - Dashboard: [worker.avalw.org](https://worker.avalw.org)
399
+ - Documentation: [worker.avalw.org/protocol](https://worker.avalw.org/protocol)
415
400
  - Email: contact@avalw.com
401
+ - Search Engine: [avalw.org](https://avalw.org)
416
402
 
417
403
  ## License
418
404
 
419
- MIT License
420
-
421
- Copyright (c) 2026 AVALW
422
-
423
- Permission is hereby granted, free of charge, to any person obtaining a copy
424
- of this software and associated documentation files (the "Software"), to deal
425
- in the Software without restriction, including without limitation the rights
426
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
427
- copies of the Software, and to permit persons to whom the Software is
428
- furnished to do so, subject to the following conditions:
429
-
430
- The above copyright notice and this permission notice shall be included in all
431
- copies or substantial portions of the Software.
432
-
433
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
434
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
435
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
436
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
437
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
438
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
439
- SOFTWARE.
405
+ MIT License - Free to use, modify, and distribute.
440
406
 
441
407
  ---
442
408
 
443
- Made with privacy in mind by [AVALW](https://cronos.avalw.com/about)
444
-
445
- ### Our Projects
446
-
447
- - [AVALW Search](https://avalw.org) - Privacy-focused search engine
448
- - [Cronos Browser](https://cronos.avalw.com) - Secure, private browser
449
- - [AVALW Protocol](https://avalw.com) - Decentralized communication protocol
450
- - [Worker API](https://worker.avalw.org) - This project
409
+ ```
410
+ Made with transparency in mind by AVALW
411
+ https://avalw.com
412
+ ```