@absolutejs/absolute 0.19.0-beta.554 → 0.19.0-beta.556
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 +73 -4
- package/dist/ai/index.js.map +6 -6
- package/dist/src/ai/rag/lexical.d.ts +2 -1
- 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 +7 -1
- package/package.json +7 -7
package/dist/ai/index.js
CHANGED
|
@@ -2551,7 +2551,9 @@ var resolveRAGHybridSearchOptions = (retrieval) => {
|
|
|
2551
2551
|
fusionConstant: DEFAULT_FUSION_CONSTANT,
|
|
2552
2552
|
lexicalTopK: undefined,
|
|
2553
2553
|
lexicalWeight: 2,
|
|
2554
|
+
mmrLambda: 0.7,
|
|
2554
2555
|
sourceBalanceStrategy: "cap",
|
|
2556
|
+
diversityStrategy: "none",
|
|
2555
2557
|
mode: "vector",
|
|
2556
2558
|
vectorWeight: 1
|
|
2557
2559
|
};
|
|
@@ -2562,7 +2564,9 @@ var resolveRAGHybridSearchOptions = (retrieval) => {
|
|
|
2562
2564
|
fusionConstant: DEFAULT_FUSION_CONSTANT,
|
|
2563
2565
|
lexicalTopK: undefined,
|
|
2564
2566
|
lexicalWeight: 2,
|
|
2567
|
+
mmrLambda: 0.7,
|
|
2565
2568
|
sourceBalanceStrategy: "cap",
|
|
2569
|
+
diversityStrategy: "none",
|
|
2566
2570
|
mode: retrieval,
|
|
2567
2571
|
vectorWeight: 1
|
|
2568
2572
|
};
|
|
@@ -2573,7 +2577,9 @@ var resolveRAGHybridSearchOptions = (retrieval) => {
|
|
|
2573
2577
|
lexicalTopK: retrieval.lexicalTopK,
|
|
2574
2578
|
maxResultsPerSource: typeof retrieval.maxResultsPerSource === "number" ? Math.max(1, Math.floor(retrieval.maxResultsPerSource)) : undefined,
|
|
2575
2579
|
lexicalWeight: Math.max(0, retrieval.lexicalWeight ?? 2),
|
|
2580
|
+
mmrLambda: Math.min(1, Math.max(0, retrieval.mmrLambda ?? 0.7)),
|
|
2576
2581
|
mode: retrieval.mode ?? "vector",
|
|
2582
|
+
diversityStrategy: retrieval.diversityStrategy === "mmr" ? "mmr" : "none",
|
|
2577
2583
|
sourceBalanceStrategy: retrieval.sourceBalanceStrategy === "round_robin" ? "round_robin" : "cap",
|
|
2578
2584
|
vectorWeight: Math.max(0, retrieval.vectorWeight ?? 1)
|
|
2579
2585
|
};
|
|
@@ -4376,6 +4382,47 @@ var applyRAGSourceDiversity = (results, maxResultsPerSource, strategy = "cap") =
|
|
|
4376
4382
|
}
|
|
4377
4383
|
return limited;
|
|
4378
4384
|
};
|
|
4385
|
+
var dotProduct = (left, right) => {
|
|
4386
|
+
const length = Math.min(left.length, right.length);
|
|
4387
|
+
let total = 0;
|
|
4388
|
+
for (let index = 0;index < length; index += 1) {
|
|
4389
|
+
total += (left[index] ?? 0) * (right[index] ?? 0);
|
|
4390
|
+
}
|
|
4391
|
+
return total;
|
|
4392
|
+
};
|
|
4393
|
+
var applyRAGMMRDiversity = (results, queryVector, lambda) => {
|
|
4394
|
+
const withEmbeddings = results.filter((result) => Array.isArray(result.embedding) && result.embedding.length > 0);
|
|
4395
|
+
if (withEmbeddings.length < 2 || queryVector.length === 0) {
|
|
4396
|
+
return results;
|
|
4397
|
+
}
|
|
4398
|
+
const selected = [];
|
|
4399
|
+
const remaining = [...withEmbeddings];
|
|
4400
|
+
while (remaining.length > 0) {
|
|
4401
|
+
let bestIndex = 0;
|
|
4402
|
+
let bestScore = Number.NEGATIVE_INFINITY;
|
|
4403
|
+
for (let index = 0;index < remaining.length; index += 1) {
|
|
4404
|
+
const candidate = remaining[index];
|
|
4405
|
+
if (!candidate) {
|
|
4406
|
+
continue;
|
|
4407
|
+
}
|
|
4408
|
+
const relevance = dotProduct(queryVector, candidate.embedding);
|
|
4409
|
+
const redundancy = selected.length > 0 ? Math.max(...selected.map((entry) => dotProduct(entry.embedding, candidate.embedding))) : 0;
|
|
4410
|
+
const mmrScore = lambda * relevance - (1 - lambda) * redundancy;
|
|
4411
|
+
if (mmrScore > bestScore) {
|
|
4412
|
+
bestScore = mmrScore;
|
|
4413
|
+
bestIndex = index;
|
|
4414
|
+
}
|
|
4415
|
+
}
|
|
4416
|
+
const next = remaining.splice(bestIndex, 1)[0];
|
|
4417
|
+
if (!next) {
|
|
4418
|
+
break;
|
|
4419
|
+
}
|
|
4420
|
+
selected.push(next);
|
|
4421
|
+
}
|
|
4422
|
+
const selectedIds = new Set(selected.map((entry) => entry.chunkId));
|
|
4423
|
+
const tail = results.filter((entry) => !selectedIds.has(entry.chunkId));
|
|
4424
|
+
return [...selected, ...tail];
|
|
4425
|
+
};
|
|
4379
4426
|
var weightQueryResults = (results, queryIndex) => {
|
|
4380
4427
|
if (queryIndex === 0) {
|
|
4381
4428
|
return results;
|
|
@@ -4432,7 +4479,9 @@ var createRAGCollection = (options) => {
|
|
|
4432
4479
|
hasQueryTransform,
|
|
4433
4480
|
hasReranker,
|
|
4434
4481
|
maxResultsPerSource: retrieval.maxResultsPerSource ?? null,
|
|
4482
|
+
mmrLambda: retrieval.mmrLambda,
|
|
4435
4483
|
mode: retrieval.mode,
|
|
4484
|
+
diversityStrategy: retrieval.diversityStrategy,
|
|
4436
4485
|
runLexical,
|
|
4437
4486
|
runVector,
|
|
4438
4487
|
sourceBalanceStrategy: retrieval.sourceBalanceStrategy,
|
|
@@ -4550,7 +4599,19 @@ var createRAGCollection = (options) => {
|
|
|
4550
4599
|
},
|
|
4551
4600
|
stage: "rerank"
|
|
4552
4601
|
});
|
|
4553
|
-
const
|
|
4602
|
+
const diversityAdjusted = retrieval.diversityStrategy === "mmr" ? applyRAGMMRDiversity(reranked, queryVector, retrieval.mmrLambda) : reranked;
|
|
4603
|
+
if (retrieval.diversityStrategy === "mmr") {
|
|
4604
|
+
steps.push({
|
|
4605
|
+
count: diversityAdjusted.length,
|
|
4606
|
+
label: "Applied MMR diversity reordering",
|
|
4607
|
+
metadata: {
|
|
4608
|
+
applied: queryVector.length > 0 && diversityAdjusted.some((entry) => Array.isArray(entry.embedding)),
|
|
4609
|
+
mmrLambda: retrieval.mmrLambda
|
|
4610
|
+
},
|
|
4611
|
+
stage: "diversity"
|
|
4612
|
+
});
|
|
4613
|
+
}
|
|
4614
|
+
const diversified = applyRAGSourceDiversity(diversityAdjusted, retrieval.maxResultsPerSource, retrieval.sourceBalanceStrategy);
|
|
4554
4615
|
if (typeof retrieval.maxResultsPerSource === "number") {
|
|
4555
4616
|
steps.push({
|
|
4556
4617
|
count: diversified.length,
|
|
@@ -4578,7 +4639,9 @@ var createRAGCollection = (options) => {
|
|
|
4578
4639
|
candidateTopK,
|
|
4579
4640
|
lexicalTopK,
|
|
4580
4641
|
maxResultsPerSource: retrieval.maxResultsPerSource,
|
|
4642
|
+
mmrLambda: retrieval.mmrLambda,
|
|
4581
4643
|
mode: retrieval.mode,
|
|
4644
|
+
diversityStrategy: retrieval.diversityStrategy,
|
|
4582
4645
|
query: input.query,
|
|
4583
4646
|
resultCounts: {
|
|
4584
4647
|
final: limited.length,
|
|
@@ -4621,7 +4684,9 @@ var createRAGCollection = (options) => {
|
|
|
4621
4684
|
candidateTopK,
|
|
4622
4685
|
lexicalTopK,
|
|
4623
4686
|
maxResultsPerSource: retrieval.maxResultsPerSource,
|
|
4687
|
+
mmrLambda: retrieval.mmrLambda,
|
|
4624
4688
|
mode: retrieval.mode,
|
|
4689
|
+
diversityStrategy: retrieval.diversityStrategy,
|
|
4625
4690
|
query: input.query,
|
|
4626
4691
|
resultCounts: {
|
|
4627
4692
|
final: filtered.length,
|
|
@@ -10704,6 +10769,7 @@ var createInMemoryRAGStore = (options = {}) => {
|
|
|
10704
10769
|
return results.slice(0, input.topK).map((entry) => ({
|
|
10705
10770
|
chunkId: entry.chunk.chunkId,
|
|
10706
10771
|
chunkText: entry.chunk.text,
|
|
10772
|
+
embedding: entry.chunk.vector,
|
|
10707
10773
|
metadata: entry.chunk.metadata,
|
|
10708
10774
|
score: entry.score,
|
|
10709
10775
|
source: entry.chunk.source,
|
|
@@ -10856,7 +10922,7 @@ var IDENTIFIER_RE = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
|
10856
10922
|
var isParsedMetadata = (value) => Boolean(value) && typeof value === "object";
|
|
10857
10923
|
var isObjectRecord2 = (value) => Boolean(value) && typeof value === "object";
|
|
10858
10924
|
var isStoredRow = (value) => isObjectRecord2(value) && typeof value.chunk_id === "string" && typeof value.text === "string" && (typeof value.title === "string" || value.title === null) && (typeof value.source === "string" || value.source === null) && (typeof value.metadata === "string" || value.metadata === null) && typeof value.embedding === "string";
|
|
10859
|
-
var isNativeStoredRow = (value) => isObjectRecord2(value) && typeof value.chunk_id === "string" && typeof value.chunk_text === "string" && (typeof value.title === "string" || value.title === null) && (typeof value.source === "string" || value.source === null) && (typeof value.metadata === "string" || value.metadata === null) && typeof value.distance === "number";
|
|
10925
|
+
var isNativeStoredRow = (value) => isObjectRecord2(value) && typeof value.chunk_id === "string" && typeof value.chunk_text === "string" && (typeof value.title === "string" || value.title === null) && (typeof value.source === "string" || value.source === null) && (typeof value.metadata === "string" || value.metadata === null) && typeof value.embedding === "string" && typeof value.distance === "number";
|
|
10860
10926
|
var toStoredRows = (value) => Array.isArray(value) ? value.filter((row) => isStoredRow(row)) : [];
|
|
10861
10927
|
var toNativeStoredRows = (value) => Array.isArray(value) ? value.filter((row) => isNativeStoredRow(row)) : [];
|
|
10862
10928
|
var createSQLiteStatus = (dimensions, nativeDiagnostics, useNative) => ({
|
|
@@ -11020,6 +11086,7 @@ var createNativeVec0Statements = (db, tableName) => {
|
|
|
11020
11086
|
const querySql = `
|
|
11021
11087
|
SELECT
|
|
11022
11088
|
chunk_id,
|
|
11089
|
+
embedding,
|
|
11023
11090
|
chunk_text,
|
|
11024
11091
|
title,
|
|
11025
11092
|
source,
|
|
@@ -11297,6 +11364,7 @@ var createSQLiteRAGStore = (options = {}) => {
|
|
|
11297
11364
|
return filtered.slice(0, input.topK).map(({ chunk, score }) => ({
|
|
11298
11365
|
chunkId: chunk.chunkId,
|
|
11299
11366
|
chunkText: chunk.text,
|
|
11367
|
+
embedding: chunk.vector,
|
|
11300
11368
|
metadata: chunk.metadata,
|
|
11301
11369
|
score,
|
|
11302
11370
|
source: chunk.source,
|
|
@@ -11318,7 +11386,7 @@ var createSQLiteRAGStore = (options = {}) => {
|
|
|
11318
11386
|
source: row.source ?? undefined,
|
|
11319
11387
|
text: row.chunk_text,
|
|
11320
11388
|
title: row.title ?? undefined,
|
|
11321
|
-
vector:
|
|
11389
|
+
vector: parseVector(row.embedding)
|
|
11322
11390
|
};
|
|
11323
11391
|
return {
|
|
11324
11392
|
chunk,
|
|
@@ -11327,6 +11395,7 @@ var createSQLiteRAGStore = (options = {}) => {
|
|
|
11327
11395
|
}).filter(({ chunk }) => matchesFilter(chunk, input.filter)).map((entry) => ({
|
|
11328
11396
|
chunkId: entry.chunk.chunkId,
|
|
11329
11397
|
chunkText: entry.chunk.text,
|
|
11398
|
+
embedding: entry.chunk.vector,
|
|
11330
11399
|
metadata: entry.chunk.metadata,
|
|
11331
11400
|
score: entry.score,
|
|
11332
11401
|
source: entry.chunk.source,
|
|
@@ -12644,5 +12713,5 @@ export {
|
|
|
12644
12713
|
aiChat
|
|
12645
12714
|
};
|
|
12646
12715
|
|
|
12647
|
-
//# debugId=
|
|
12716
|
+
//# debugId=9DF63A32267D961C64756E2164756E21
|
|
12648
12717
|
//# sourceMappingURL=index.js.map
|