@absolutejs/absolute 0.19.0-beta.551 → 0.19.0-beta.553
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/dist/ai/index.js +84 -4
- package/dist/ai/index.js.map +4 -4
- package/dist/src/ai/rag/lexical.d.ts +1 -8
- package/dist/src/vue/ai/useRAG.d.ts +10 -0
- package/dist/src/vue/ai/useRAGEvaluate.d.ts +6 -0
- package/dist/src/vue/ai/useRAGSearch.d.ts +4 -0
- package/dist/types/ai.d.ts +6 -1
- package/package.json +7 -7
package/dist/ai/index.js
CHANGED
|
@@ -2551,6 +2551,7 @@ var resolveRAGHybridSearchOptions = (retrieval) => {
|
|
|
2551
2551
|
fusionConstant: DEFAULT_FUSION_CONSTANT,
|
|
2552
2552
|
lexicalTopK: undefined,
|
|
2553
2553
|
lexicalWeight: 2,
|
|
2554
|
+
sourceBalanceStrategy: "cap",
|
|
2554
2555
|
mode: "vector",
|
|
2555
2556
|
vectorWeight: 1
|
|
2556
2557
|
};
|
|
@@ -2561,6 +2562,7 @@ var resolveRAGHybridSearchOptions = (retrieval) => {
|
|
|
2561
2562
|
fusionConstant: DEFAULT_FUSION_CONSTANT,
|
|
2562
2563
|
lexicalTopK: undefined,
|
|
2563
2564
|
lexicalWeight: 2,
|
|
2565
|
+
sourceBalanceStrategy: "cap",
|
|
2564
2566
|
mode: retrieval,
|
|
2565
2567
|
vectorWeight: 1
|
|
2566
2568
|
};
|
|
@@ -2569,8 +2571,10 @@ var resolveRAGHybridSearchOptions = (retrieval) => {
|
|
|
2569
2571
|
fusion: retrieval.fusion ?? "rrf",
|
|
2570
2572
|
fusionConstant: Math.max(1, Math.floor(retrieval.fusionConstant ?? DEFAULT_FUSION_CONSTANT)),
|
|
2571
2573
|
lexicalTopK: retrieval.lexicalTopK,
|
|
2574
|
+
maxResultsPerSource: typeof retrieval.maxResultsPerSource === "number" ? Math.max(1, Math.floor(retrieval.maxResultsPerSource)) : undefined,
|
|
2572
2575
|
lexicalWeight: Math.max(0, retrieval.lexicalWeight ?? 2),
|
|
2573
2576
|
mode: retrieval.mode ?? "vector",
|
|
2577
|
+
sourceBalanceStrategy: retrieval.sourceBalanceStrategy === "round_robin" ? "round_robin" : "cap",
|
|
2574
2578
|
vectorWeight: Math.max(0, retrieval.vectorWeight ?? 1)
|
|
2575
2579
|
};
|
|
2576
2580
|
};
|
|
@@ -4314,6 +4318,64 @@ var mergeQueryResults = (results) => {
|
|
|
4314
4318
|
return left.chunkId.localeCompare(right.chunkId);
|
|
4315
4319
|
});
|
|
4316
4320
|
};
|
|
4321
|
+
var getRAGSourceDiversityKey = (result) => {
|
|
4322
|
+
const documentId = typeof result.metadata?.documentId === "string" ? result.metadata.documentId : undefined;
|
|
4323
|
+
return result.source ?? documentId ?? result.title ?? result.chunkId;
|
|
4324
|
+
};
|
|
4325
|
+
var applyRAGSourceDiversity = (results, maxResultsPerSource, strategy = "cap") => {
|
|
4326
|
+
if (typeof maxResultsPerSource !== "number") {
|
|
4327
|
+
return results;
|
|
4328
|
+
}
|
|
4329
|
+
if (strategy === "round_robin") {
|
|
4330
|
+
const grouped = new Map;
|
|
4331
|
+
const order = [];
|
|
4332
|
+
for (const result of results) {
|
|
4333
|
+
const key = getRAGSourceDiversityKey(result);
|
|
4334
|
+
const entries = grouped.get(key);
|
|
4335
|
+
if (entries) {
|
|
4336
|
+
entries.push(result);
|
|
4337
|
+
continue;
|
|
4338
|
+
}
|
|
4339
|
+
grouped.set(key, [result]);
|
|
4340
|
+
order.push(key);
|
|
4341
|
+
}
|
|
4342
|
+
const counts2 = new Map;
|
|
4343
|
+
const balanced = [];
|
|
4344
|
+
let remaining = true;
|
|
4345
|
+
while (remaining) {
|
|
4346
|
+
remaining = false;
|
|
4347
|
+
for (const key of order) {
|
|
4348
|
+
const entries = grouped.get(key);
|
|
4349
|
+
if (!entries || entries.length === 0) {
|
|
4350
|
+
continue;
|
|
4351
|
+
}
|
|
4352
|
+
if ((counts2.get(key) ?? 0) >= maxResultsPerSource) {
|
|
4353
|
+
continue;
|
|
4354
|
+
}
|
|
4355
|
+
const next = entries.shift();
|
|
4356
|
+
if (!next) {
|
|
4357
|
+
continue;
|
|
4358
|
+
}
|
|
4359
|
+
counts2.set(key, (counts2.get(key) ?? 0) + 1);
|
|
4360
|
+
balanced.push(next);
|
|
4361
|
+
remaining = true;
|
|
4362
|
+
}
|
|
4363
|
+
}
|
|
4364
|
+
return balanced;
|
|
4365
|
+
}
|
|
4366
|
+
const limited = [];
|
|
4367
|
+
const counts = new Map;
|
|
4368
|
+
for (const result of results) {
|
|
4369
|
+
const key = getRAGSourceDiversityKey(result);
|
|
4370
|
+
const count = counts.get(key) ?? 0;
|
|
4371
|
+
if (count >= maxResultsPerSource) {
|
|
4372
|
+
continue;
|
|
4373
|
+
}
|
|
4374
|
+
counts.set(key, count + 1);
|
|
4375
|
+
limited.push(result);
|
|
4376
|
+
}
|
|
4377
|
+
return limited;
|
|
4378
|
+
};
|
|
4317
4379
|
var weightQueryResults = (results, queryIndex) => {
|
|
4318
4380
|
if (queryIndex === 0) {
|
|
4319
4381
|
return results;
|
|
@@ -4369,9 +4431,11 @@ var createRAGCollection = (options) => {
|
|
|
4369
4431
|
candidateTopK,
|
|
4370
4432
|
hasQueryTransform,
|
|
4371
4433
|
hasReranker,
|
|
4434
|
+
maxResultsPerSource: retrieval.maxResultsPerSource ?? null,
|
|
4372
4435
|
mode: retrieval.mode,
|
|
4373
4436
|
runLexical,
|
|
4374
4437
|
runVector,
|
|
4438
|
+
sourceBalanceStrategy: retrieval.sourceBalanceStrategy,
|
|
4375
4439
|
topK
|
|
4376
4440
|
},
|
|
4377
4441
|
stage: "input"
|
|
@@ -4486,7 +4550,19 @@ var createRAGCollection = (options) => {
|
|
|
4486
4550
|
},
|
|
4487
4551
|
stage: "rerank"
|
|
4488
4552
|
});
|
|
4489
|
-
const
|
|
4553
|
+
const diversified = applyRAGSourceDiversity(reranked, retrieval.maxResultsPerSource, retrieval.sourceBalanceStrategy);
|
|
4554
|
+
if (typeof retrieval.maxResultsPerSource === "number") {
|
|
4555
|
+
steps.push({
|
|
4556
|
+
count: diversified.length,
|
|
4557
|
+
label: "Balanced candidates across sources",
|
|
4558
|
+
metadata: {
|
|
4559
|
+
maxResultsPerSource: retrieval.maxResultsPerSource,
|
|
4560
|
+
strategy: retrieval.sourceBalanceStrategy
|
|
4561
|
+
},
|
|
4562
|
+
stage: "source_balance"
|
|
4563
|
+
});
|
|
4564
|
+
}
|
|
4565
|
+
const limited = diversified.slice(0, topK);
|
|
4490
4566
|
if (typeof input.scoreThreshold !== "number") {
|
|
4491
4567
|
steps.push({
|
|
4492
4568
|
count: limited.length,
|
|
@@ -4501,17 +4577,19 @@ var createRAGCollection = (options) => {
|
|
|
4501
4577
|
trace: {
|
|
4502
4578
|
candidateTopK,
|
|
4503
4579
|
lexicalTopK,
|
|
4580
|
+
maxResultsPerSource: retrieval.maxResultsPerSource,
|
|
4504
4581
|
mode: retrieval.mode,
|
|
4505
4582
|
query: input.query,
|
|
4506
4583
|
resultCounts: {
|
|
4507
4584
|
final: limited.length,
|
|
4508
4585
|
fused: results.length,
|
|
4509
4586
|
lexical: lexicalResults.length,
|
|
4510
|
-
reranked:
|
|
4587
|
+
reranked: diversified.length,
|
|
4511
4588
|
vector: vectorResults.length
|
|
4512
4589
|
},
|
|
4513
4590
|
runLexical,
|
|
4514
4591
|
runVector,
|
|
4592
|
+
sourceBalanceStrategy: retrieval.sourceBalanceStrategy,
|
|
4515
4593
|
steps,
|
|
4516
4594
|
topK,
|
|
4517
4595
|
transformedQuery: transformed.query,
|
|
@@ -4542,18 +4620,20 @@ var createRAGCollection = (options) => {
|
|
|
4542
4620
|
trace: {
|
|
4543
4621
|
candidateTopK,
|
|
4544
4622
|
lexicalTopK,
|
|
4623
|
+
maxResultsPerSource: retrieval.maxResultsPerSource,
|
|
4545
4624
|
mode: retrieval.mode,
|
|
4546
4625
|
query: input.query,
|
|
4547
4626
|
resultCounts: {
|
|
4548
4627
|
final: filtered.length,
|
|
4549
4628
|
fused: results.length,
|
|
4550
4629
|
lexical: lexicalResults.length,
|
|
4551
|
-
reranked:
|
|
4630
|
+
reranked: diversified.length,
|
|
4552
4631
|
vector: vectorResults.length
|
|
4553
4632
|
},
|
|
4554
4633
|
runLexical,
|
|
4555
4634
|
runVector,
|
|
4556
4635
|
scoreThreshold,
|
|
4636
|
+
sourceBalanceStrategy: retrieval.sourceBalanceStrategy,
|
|
4557
4637
|
steps,
|
|
4558
4638
|
topK,
|
|
4559
4639
|
transformedQuery: transformed.query,
|
|
@@ -12505,5 +12585,5 @@ export {
|
|
|
12505
12585
|
aiChat
|
|
12506
12586
|
};
|
|
12507
12587
|
|
|
12508
|
-
//# debugId=
|
|
12588
|
+
//# debugId=BD4F3B903BF6366564756E2164756E21
|
|
12509
12589
|
//# sourceMappingURL=index.js.map
|