@absolutejs/absolute 0.19.0-beta.496 → 0.19.0-beta.497
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 +64 -9
- package/dist/ai/index.js.map +4 -4
- package/package.json +1 -1
package/dist/ai/index.js
CHANGED
|
@@ -2165,6 +2165,31 @@ var collectMetadataStrings = (value) => {
|
|
|
2165
2165
|
};
|
|
2166
2166
|
var normalizeSourceForLexical = (source) => source.replace(/[#/_.-]+/g, " ").replace(/\bmd\b/g, "markdown").replace(/\bpptx\b/g, "presentation").replace(/\bxlsx\b/g, "spreadsheet workbook sheet").replace(/\bmp3\b/g, "audio transcript media").replace(/\bmp4\b/g, "video transcript media").replace(/\bzip\b/g, "archive bundle");
|
|
2167
2167
|
var toFieldText = (value) => collectMetadataStrings(value).filter(Boolean).join(" ");
|
|
2168
|
+
var normalizeLooseText = (value) => value.toLowerCase().replace(/[^a-z0-9]+/g, " ").trim().replace(/\s+/g, " ");
|
|
2169
|
+
var scoreLoosePhraseMatch = (query, text) => {
|
|
2170
|
+
const normalizedQuery = normalizeLooseText(query);
|
|
2171
|
+
const normalizedText = normalizeLooseText(text ?? "");
|
|
2172
|
+
if (normalizedQuery.length === 0 || normalizedText.length === 0) {
|
|
2173
|
+
return 0;
|
|
2174
|
+
}
|
|
2175
|
+
if (normalizedText.includes(normalizedQuery)) {
|
|
2176
|
+
return 1;
|
|
2177
|
+
}
|
|
2178
|
+
const words = normalizedQuery.split(" ").filter(Boolean);
|
|
2179
|
+
for (let size = Math.min(5, words.length);size >= 2; size -= 1) {
|
|
2180
|
+
for (let index = 0;index <= words.length - size; index += 1) {
|
|
2181
|
+
const phraseWords = words.slice(index, index + size);
|
|
2182
|
+
if (phraseWords.every((word) => STOP_WORDS.has(word))) {
|
|
2183
|
+
continue;
|
|
2184
|
+
}
|
|
2185
|
+
const phrase = phraseWords.join(" ");
|
|
2186
|
+
if (normalizedText.includes(phrase)) {
|
|
2187
|
+
return Math.min(1, size / 4);
|
|
2188
|
+
}
|
|
2189
|
+
}
|
|
2190
|
+
}
|
|
2191
|
+
return 0;
|
|
2192
|
+
};
|
|
2168
2193
|
var scoreTokenCoverage = (queryTokens, text) => {
|
|
2169
2194
|
const normalizedText = (text ?? "").toLowerCase();
|
|
2170
2195
|
if (normalizedText.length === 0) {
|
|
@@ -2181,10 +2206,8 @@ var scoreTokenCoverage = (queryTokens, text) => {
|
|
|
2181
2206
|
var scorePhraseMatch = (query, text) => {
|
|
2182
2207
|
const normalizedQuery = tokenize(query).join(" ");
|
|
2183
2208
|
const normalizedText = tokenize(text ?? "").join(" ");
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
}
|
|
2187
|
-
return normalizedText.includes(normalizedQuery) ? 1 : 0;
|
|
2209
|
+
const tokenPhraseMatch = normalizedQuery.length > 0 && normalizedText.length > 0 ? normalizedText.includes(normalizedQuery) ? 1 : 0 : 0;
|
|
2210
|
+
return Math.max(tokenPhraseMatch, scoreLoosePhraseMatch(query, text ?? ""));
|
|
2188
2211
|
};
|
|
2189
2212
|
var scoreWeightedField = ({
|
|
2190
2213
|
coverageWeight,
|
|
@@ -2774,7 +2797,36 @@ var collectMetadataStrings2 = (value) => {
|
|
|
2774
2797
|
}
|
|
2775
2798
|
return [];
|
|
2776
2799
|
};
|
|
2777
|
-
var
|
|
2800
|
+
var normalizeLooseText2 = (value) => value.toLowerCase().replace(/[^a-z0-9]+/g, " ").trim().replace(/\s+/g, " ");
|
|
2801
|
+
var scoreLoosePhraseMatch2 = (query, text) => {
|
|
2802
|
+
const normalizedQuery = normalizeLooseText2(query);
|
|
2803
|
+
const normalizedText = normalizeLooseText2(text);
|
|
2804
|
+
if (normalizedQuery.length === 0 || normalizedText.length === 0) {
|
|
2805
|
+
return 0;
|
|
2806
|
+
}
|
|
2807
|
+
if (normalizedText.includes(normalizedQuery)) {
|
|
2808
|
+
return 1;
|
|
2809
|
+
}
|
|
2810
|
+
const words = normalizedQuery.split(" ").filter(Boolean);
|
|
2811
|
+
for (let size = Math.min(5, words.length);size >= 2; size -= 1) {
|
|
2812
|
+
for (let index = 0;index <= words.length - size; index += 1) {
|
|
2813
|
+
const phraseWords = words.slice(index, index + size);
|
|
2814
|
+
if (phraseWords.every((word) => STOP_WORDS3.has(word))) {
|
|
2815
|
+
continue;
|
|
2816
|
+
}
|
|
2817
|
+
const phrase = phraseWords.join(" ");
|
|
2818
|
+
if (normalizedText.includes(phrase)) {
|
|
2819
|
+
return Math.min(1, size / 4);
|
|
2820
|
+
}
|
|
2821
|
+
}
|
|
2822
|
+
}
|
|
2823
|
+
return 0;
|
|
2824
|
+
};
|
|
2825
|
+
var scoreHeuristicMatch = ({
|
|
2826
|
+
query,
|
|
2827
|
+
queryTokens,
|
|
2828
|
+
result
|
|
2829
|
+
}) => {
|
|
2778
2830
|
if (queryTokens.length === 0) {
|
|
2779
2831
|
return result.score;
|
|
2780
2832
|
}
|
|
@@ -2783,8 +2835,7 @@ var scoreHeuristicMatch = (queryTokens, result) => {
|
|
|
2783
2835
|
const haystackSet = new Set(haystack);
|
|
2784
2836
|
const overlap = queryTokens.filter((token) => haystackSet.has(token)).length;
|
|
2785
2837
|
const overlapBoost = overlap / queryTokens.length;
|
|
2786
|
-
const
|
|
2787
|
-
const exactPhraseBoost = normalizeText([result.title, result.source, result.chunkText, ...metadataValues].filter(Boolean).join(" ")).includes(normalizedQuery) ? 1 : 0;
|
|
2838
|
+
const exactPhraseBoost = Math.max(normalizeText([result.title, result.source, result.chunkText, ...metadataValues].filter(Boolean).join(" ")).includes(queryTokens.join(" ")) ? 1 : 0, scoreLoosePhraseMatch2(query, [result.title, result.source, result.chunkText, ...metadataValues].filter(Boolean).join(" ")));
|
|
2788
2839
|
const sourcePathBoost = typeof result.source === "string" && queryTokens.some((token) => result.source?.toLowerCase().includes(token)) ? 0.5 : 0;
|
|
2789
2840
|
const metadataBoost = metadataValues.length > 0 ? queryTokens.filter((token) => metadataValues.some((value) => value.toLowerCase().includes(token))).length / queryTokens.length : 0;
|
|
2790
2841
|
return result.score + overlapBoost + exactPhraseBoost + sourcePathBoost + metadataBoost;
|
|
@@ -2812,7 +2863,11 @@ var createHeuristicRAGReranker = (options = {}) => createRAGReranker({
|
|
|
2812
2863
|
return [...results].map((result, index) => ({
|
|
2813
2864
|
index,
|
|
2814
2865
|
result,
|
|
2815
|
-
score: scoreHeuristicMatch(
|
|
2866
|
+
score: scoreHeuristicMatch({
|
|
2867
|
+
query,
|
|
2868
|
+
queryTokens,
|
|
2869
|
+
result
|
|
2870
|
+
})
|
|
2816
2871
|
})).sort((left, right) => {
|
|
2817
2872
|
if (right.score !== left.score) {
|
|
2818
2873
|
return right.score - left.score;
|
|
@@ -8900,5 +8955,5 @@ export {
|
|
|
8900
8955
|
aiChat
|
|
8901
8956
|
};
|
|
8902
8957
|
|
|
8903
|
-
//# debugId=
|
|
8958
|
+
//# debugId=55FD05298CEAFBDB64756E2164756E21
|
|
8904
8959
|
//# sourceMappingURL=index.js.map
|