@dyingc/brave-search-mcp-server 2.1.1 → 2.1.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.
@@ -157,18 +157,21 @@ class ApiKeyManager {
157
157
  /**
158
158
  * Calculate soft max probabilities for key selection
159
159
  * Uses standard soft max formula: softmax_i(z;T) = exp(z_i/T) / sum(exp(z_j/T))
160
- * where z_i = -remainingQuota (lower remaining = higher selection probability)
160
+ * where z_i = -remainingQuota / 2000 (lower remaining = higher selection probability)
161
+ *
162
+ * Normalization by 2000 (FREE_TIER_MONTHLY_QUOTA) keeps scores in reasonable range [-1, 0]
161
163
  *
162
164
  * Example with T=1:
163
- * - Key with 1 remaining: score = -1, exp(-1) ≈ 0.368
164
- * - Key with 10 remaining: score = -10, exp(-10) ≈ 0.000045
165
- * - Key with 1 remaining has much higher selection probability
165
+ * - Key with 1 remaining: score = -1/2000 ≈ -0.0005, exp ≈ 0.9995
166
+ * - Key with 10 remaining: score = -10/2000 ≈ -0.005, exp ≈ 0.995
167
+ * - Key with 1000 remaining: score = -1000/2000 = -0.5, exp ≈ 0.607
168
+ * - Lower remaining quota yields higher selection probability
166
169
  *
167
170
  * Probabilities always sum to 1 by definition of softmax formula
168
171
  */
169
172
  calculateSoftMaxProbabilities(keys, temperature) {
170
- // Use negative remaining quota as score: lower remaining = higher score
171
- const scores = keys.map((k) => -k.remainingQuota);
173
+ // Normalize by 2000 and negate: lower remaining = higher score
174
+ const scores = keys.map((k) => -k.remainingQuota / FREE_TIER_MONTHLY_QUOTA);
172
175
  // Standard soft max: scale by temperature
173
176
  const scaledScores = scores.map((s) => s / temperature);
174
177
  // Numerical stability: subtract max value
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@dyingc/brave-search-mcp-server",
3
3
  "mcpName": "io.github.brave/brave-search-mcp-server",
4
4
  "private": false,
5
- "version": "2.1.1",
5
+ "version": "2.1.2",
6
6
  "description": "Brave Search MCP Server: web results, images, videos, rich results, AI summaries, and more.",
7
7
  "keywords": [
8
8
  "api",