claude-flow 3.7.0-alpha.50 → 3.7.0-alpha.51
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-flow",
|
|
3
|
-
"version": "3.7.0-alpha.
|
|
3
|
+
"version": "3.7.0-alpha.51",
|
|
4
4
|
"description": "Ruflo - Enterprise AI agent orchestration for Claude Code. Deploy 60+ specialized agents in coordinated swarms with self-learning, fault-tolerant consensus, vector memory, and MCP integration",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -1279,5 +1279,147 @@ export const embeddingsTools = [
|
|
|
1279
1279
|
};
|
|
1280
1280
|
},
|
|
1281
1281
|
},
|
|
1282
|
+
// ============================================================
|
|
1283
|
+
// ADR-121 Phase 10 — MMR diversity rerank (alpha.51 CLI)
|
|
1284
|
+
// ============================================================
|
|
1285
|
+
//
|
|
1286
|
+
// Plain top-k often returns near-duplicate chunks. MMR picks a
|
|
1287
|
+
// diversified top-k by trading off relevance against redundancy
|
|
1288
|
+
// (Carbonell & Goldstein 1998). Fetches `fetchMultiplier * k`
|
|
1289
|
+
// candidates from AnnRouter, then reranks to k via mmrRerank.
|
|
1290
|
+
//
|
|
1291
|
+
// Pairs with embeddings_search_text (relevance only). Same caller
|
|
1292
|
+
// contract — text + handle name + k — plus optional `lambda` and
|
|
1293
|
+
// `fetchMultiplier`. Returns diversity stats so callers can
|
|
1294
|
+
// confirm the rerank actually spread the result.
|
|
1295
|
+
{
|
|
1296
|
+
name: 'embeddings_search_text_diverse',
|
|
1297
|
+
description: "Embed a text query, fetch a wider candidate pool from a named AnnRouter handle, and rerank with MMR (Maximal Marginal Relevance) to return a diverse top-k. Use when plain top-k tends to return near-duplicates (e.g. corpora with many paraphrased chunks). λ controls relevance/diversity tradeoff: 1.0 = same as embeddings_search_text, 0.5 = balanced (default), 0.0 = pure diversity. fetchMultiplier controls how many candidates to consider before reranking (default 5×k). Returns hits + diversification stats (averagePairwiseSimilarity — lower is more diverse). For plain (non-diversified) RAG use embeddings_search_text.",
|
|
1298
|
+
category: 'embeddings',
|
|
1299
|
+
inputSchema: {
|
|
1300
|
+
type: 'object',
|
|
1301
|
+
properties: {
|
|
1302
|
+
text: { type: 'string', description: 'Query text. Will be embedded inline.' },
|
|
1303
|
+
name: { type: 'string', description: 'AnnRouter handle name (set by embeddings_ann_router_build).' },
|
|
1304
|
+
k: { type: 'number', description: 'Number of diverse nearest neighbors to return.' },
|
|
1305
|
+
lambda: {
|
|
1306
|
+
type: 'number',
|
|
1307
|
+
description: 'Relevance/diversity tradeoff in [0,1]. 1=pure relevance, 0=pure diversity. Default 0.5.',
|
|
1308
|
+
},
|
|
1309
|
+
fetchMultiplier: {
|
|
1310
|
+
type: 'number',
|
|
1311
|
+
description: 'Candidate pool size = fetchMultiplier * k. Larger = more candidates to diversify from, more compute. Default 5.',
|
|
1312
|
+
},
|
|
1313
|
+
},
|
|
1314
|
+
required: ['text', 'name', 'k'],
|
|
1315
|
+
},
|
|
1316
|
+
handler: async (input) => {
|
|
1317
|
+
const config = loadConfig();
|
|
1318
|
+
if (!config) {
|
|
1319
|
+
return { success: false, error: 'Embeddings not initialized. Run embeddings_init first.' };
|
|
1320
|
+
}
|
|
1321
|
+
const text = input.text;
|
|
1322
|
+
const name = input.name;
|
|
1323
|
+
const k = input.k;
|
|
1324
|
+
const lambda = typeof input.lambda === 'number' ? input.lambda : 0.5;
|
|
1325
|
+
const fetchMultiplier = typeof input.fetchMultiplier === 'number' && input.fetchMultiplier >= 1
|
|
1326
|
+
? input.fetchMultiplier
|
|
1327
|
+
: 5;
|
|
1328
|
+
const tv = validateText(text, 'text');
|
|
1329
|
+
if (!tv.valid)
|
|
1330
|
+
return { success: false, error: tv.error };
|
|
1331
|
+
if (!Number.isInteger(k) || k < 1) {
|
|
1332
|
+
return { success: false, error: 'k must be a positive integer' };
|
|
1333
|
+
}
|
|
1334
|
+
// Stage 1 — embed the query.
|
|
1335
|
+
const embedT0 = Date.now();
|
|
1336
|
+
let embedding;
|
|
1337
|
+
try {
|
|
1338
|
+
embedding = await generateRealEmbedding(text, config.dimension);
|
|
1339
|
+
}
|
|
1340
|
+
catch (err) {
|
|
1341
|
+
return { success: false, error: `embed failed: ${err instanceof Error ? err.message : String(err)}` };
|
|
1342
|
+
}
|
|
1343
|
+
const embeddingMs = Date.now() - embedT0;
|
|
1344
|
+
const queryVec = new Float32Array(embedding);
|
|
1345
|
+
// Stage 2 — fetch a wider pool of candidates from the router.
|
|
1346
|
+
const { getAnnRouterRegistry } = await import('../memory/ann-router-registry.js');
|
|
1347
|
+
const registry = getAnnRouterRegistry();
|
|
1348
|
+
const fetchK = Math.max(k, Math.floor(k * fetchMultiplier));
|
|
1349
|
+
const searchT0 = Date.now();
|
|
1350
|
+
let candidatesRaw;
|
|
1351
|
+
try {
|
|
1352
|
+
candidatesRaw = await registry.search(name, queryVec, fetchK);
|
|
1353
|
+
}
|
|
1354
|
+
catch (err) {
|
|
1355
|
+
return {
|
|
1356
|
+
success: false,
|
|
1357
|
+
name,
|
|
1358
|
+
error: err instanceof Error ? err.message : String(err),
|
|
1359
|
+
latency: { embeddingMs, searchMs: 0, rerankMs: 0 },
|
|
1360
|
+
};
|
|
1361
|
+
}
|
|
1362
|
+
const searchMs = Date.now() - searchT0;
|
|
1363
|
+
// Filter to candidates that have a vector (MMR needs it).
|
|
1364
|
+
// Routers that don't surface vectors (rare) degrade to
|
|
1365
|
+
// plain top-k for safety rather than throwing.
|
|
1366
|
+
const candidatesWithVec = candidatesRaw.filter(c => c.vector != null);
|
|
1367
|
+
if (candidatesWithVec.length === 0) {
|
|
1368
|
+
return {
|
|
1369
|
+
success: true,
|
|
1370
|
+
name,
|
|
1371
|
+
k,
|
|
1372
|
+
hits: candidatesRaw.slice(0, k),
|
|
1373
|
+
mmr: { applied: false, reason: 'no candidate vectors available — degraded to plain top-k' },
|
|
1374
|
+
latency: { embeddingMs, searchMs, rerankMs: 0, totalMs: embeddingMs + searchMs },
|
|
1375
|
+
};
|
|
1376
|
+
}
|
|
1377
|
+
// Stage 3 — MMR rerank.
|
|
1378
|
+
// Sub-path import bypasses the index barrel — TS resolves the
|
|
1379
|
+
// mmr.d.ts directly via the './*' export condition, which
|
|
1380
|
+
// sidesteps a stale-cache issue with the aggregate index.d.ts.
|
|
1381
|
+
const { mmrRerank, averagePairwiseSimilarity } = await import('@claude-flow/embeddings/mmr');
|
|
1382
|
+
const rerankT0 = Date.now();
|
|
1383
|
+
const picked = mmrRerank(candidatesWithVec.map(c => ({
|
|
1384
|
+
id: c.id,
|
|
1385
|
+
vector: c.vector,
|
|
1386
|
+
score: c.score,
|
|
1387
|
+
payload: c.payload,
|
|
1388
|
+
})), queryVec, { k, lambda });
|
|
1389
|
+
const rerankMs = Date.now() - rerankT0;
|
|
1390
|
+
const avgPairSim = averagePairwiseSimilarity(picked);
|
|
1391
|
+
// Strip vectors from the response to keep stdout sane.
|
|
1392
|
+
// Callers wanting the vectors can re-fetch via search.
|
|
1393
|
+
const hits = picked.map(p => ({
|
|
1394
|
+
id: p.id,
|
|
1395
|
+
score: p.relevance,
|
|
1396
|
+
mmrScore: p.mmrScore,
|
|
1397
|
+
relevance: p.relevance,
|
|
1398
|
+
redundancy: p.redundancy,
|
|
1399
|
+
pickOrder: p.pickOrder,
|
|
1400
|
+
payload: p.payload,
|
|
1401
|
+
}));
|
|
1402
|
+
return {
|
|
1403
|
+
success: true,
|
|
1404
|
+
name,
|
|
1405
|
+
k,
|
|
1406
|
+
hits,
|
|
1407
|
+
mmr: {
|
|
1408
|
+
applied: true,
|
|
1409
|
+
lambda,
|
|
1410
|
+
fetchMultiplier,
|
|
1411
|
+
candidatesConsidered: candidatesWithVec.length,
|
|
1412
|
+
averagePairwiseSimilarity: avgPairSim,
|
|
1413
|
+
},
|
|
1414
|
+
latency: {
|
|
1415
|
+
embeddingMs,
|
|
1416
|
+
searchMs,
|
|
1417
|
+
rerankMs,
|
|
1418
|
+
totalMs: embeddingMs + searchMs + rerankMs,
|
|
1419
|
+
},
|
|
1420
|
+
embeddingDimension: embedding.length,
|
|
1421
|
+
};
|
|
1422
|
+
},
|
|
1423
|
+
},
|
|
1282
1424
|
];
|
|
1283
1425
|
//# sourceMappingURL=embeddings-tools.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@claude-flow/cli",
|
|
3
|
-
"version": "3.7.0-alpha.
|
|
3
|
+
"version": "3.7.0-alpha.51",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Ruflo CLI - Enterprise AI agent orchestration with 60+ specialized agents, swarm coordination, MCP server, self-learning hooks, and vector memory for Claude Code",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -104,14 +104,14 @@
|
|
|
104
104
|
"semver": "^7.6.0",
|
|
105
105
|
"yaml": "^2.8.0",
|
|
106
106
|
"@claude-flow/memory": "^3.0.0-alpha.17",
|
|
107
|
-
"@claude-flow/embeddings": "^3.0.0-alpha.
|
|
107
|
+
"@claude-flow/embeddings": "^3.0.0-alpha.31",
|
|
108
108
|
"@claude-flow/security": "^3.0.0-alpha.8",
|
|
109
109
|
"@claude-flow/swarm": "^3.0.0-alpha.8"
|
|
110
110
|
},
|
|
111
111
|
"optionalDependencies": {
|
|
112
112
|
"@claude-flow/aidefence": "^3.0.2",
|
|
113
113
|
"@claude-flow/codex": "^3.0.0-alpha.8",
|
|
114
|
-
"@claude-flow/embeddings": "^3.0.0-alpha.
|
|
114
|
+
"@claude-flow/embeddings": "^3.0.0-alpha.31",
|
|
115
115
|
"@claude-flow/guidance": "^3.0.0-alpha.1",
|
|
116
116
|
"@claude-flow/memory": "^3.0.0-alpha.17",
|
|
117
117
|
"@claude-flow/plugin-gastown-bridge": "^0.1.3",
|