@librechat/agents 2.4.30 → 2.4.311
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/cjs/common/enum.cjs +1 -0
- package/dist/cjs/common/enum.cjs.map +1 -1
- package/dist/cjs/main.cjs +2 -0
- package/dist/cjs/main.cjs.map +1 -1
- package/dist/cjs/tools/search/firecrawl.cjs +149 -0
- package/dist/cjs/tools/search/firecrawl.cjs.map +1 -0
- package/dist/cjs/tools/search/format.cjs +116 -0
- package/dist/cjs/tools/search/format.cjs.map +1 -0
- package/dist/cjs/tools/search/highlights.cjs +194 -0
- package/dist/cjs/tools/search/highlights.cjs.map +1 -0
- package/dist/cjs/tools/search/rerankers.cjs +187 -0
- package/dist/cjs/tools/search/rerankers.cjs.map +1 -0
- package/dist/cjs/tools/search/search.cjs +410 -0
- package/dist/cjs/tools/search/search.cjs.map +1 -0
- package/dist/cjs/tools/search/tool.cjs +103 -0
- package/dist/cjs/tools/search/tool.cjs.map +1 -0
- package/dist/esm/common/enum.mjs +1 -0
- package/dist/esm/common/enum.mjs.map +1 -1
- package/dist/esm/main.mjs +1 -0
- package/dist/esm/main.mjs.map +1 -1
- package/dist/esm/tools/search/firecrawl.mjs +145 -0
- package/dist/esm/tools/search/firecrawl.mjs.map +1 -0
- package/dist/esm/tools/search/format.mjs +114 -0
- package/dist/esm/tools/search/format.mjs.map +1 -0
- package/dist/esm/tools/search/highlights.mjs +192 -0
- package/dist/esm/tools/search/highlights.mjs.map +1 -0
- package/dist/esm/tools/search/rerankers.mjs +181 -0
- package/dist/esm/tools/search/rerankers.mjs.map +1 -0
- package/dist/esm/tools/search/search.mjs +407 -0
- package/dist/esm/tools/search/search.mjs.map +1 -0
- package/dist/esm/tools/search/tool.mjs +101 -0
- package/dist/esm/tools/search/tool.mjs.map +1 -0
- package/dist/types/common/enum.d.ts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/scripts/search.d.ts +1 -0
- package/dist/types/tools/search/firecrawl.d.ts +117 -0
- package/dist/types/tools/search/format.d.ts +2 -0
- package/dist/types/tools/search/highlights.d.ts +13 -0
- package/dist/types/tools/search/index.d.ts +2 -0
- package/dist/types/tools/search/rerankers.d.ts +32 -0
- package/dist/types/tools/search/search.d.ts +9 -0
- package/dist/types/tools/search/tool.d.ts +12 -0
- package/dist/types/tools/search/types.d.ts +150 -0
- package/package.json +2 -1
- package/src/common/enum.ts +1 -0
- package/src/index.ts +1 -0
- package/src/scripts/search.ts +141 -0
- package/src/tools/search/firecrawl.ts +270 -0
- package/src/tools/search/format.ts +121 -0
- package/src/tools/search/highlights.ts +238 -0
- package/src/tools/search/index.ts +2 -0
- package/src/tools/search/rerankers.ts +248 -0
- package/src/tools/search/search.ts +567 -0
- package/src/tools/search/tool.ts +151 -0
- package/src/tools/search/types.ts +179 -0
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
// 2. Pre-compile all regular expressions (only do this once)
|
|
2
|
+
// Group patterns by priority for early returns
|
|
3
|
+
const priorityPatterns = [
|
|
4
|
+
// High priority patterns (structural)
|
|
5
|
+
[
|
|
6
|
+
{ regex: /\n\n/g }, // Double newline (paragraph break)
|
|
7
|
+
{ regex: /\n/g }, // Single newline
|
|
8
|
+
{ regex: /={3,}\s*\n|-{3,}\s*\n/g }, // Section separators
|
|
9
|
+
],
|
|
10
|
+
// Medium priority (semantic)
|
|
11
|
+
[
|
|
12
|
+
{ regex: /[.!?][")\]]?\s/g }, // End of sentence
|
|
13
|
+
{ regex: /;\s/g }, // Semicolon
|
|
14
|
+
{ regex: /:\s/g }, // Colon
|
|
15
|
+
],
|
|
16
|
+
// Low priority (any breaks)
|
|
17
|
+
[
|
|
18
|
+
{ regex: /,\s/g }, // Comma
|
|
19
|
+
{ regex: /\s-\s/g }, // Dash surrounded by spaces
|
|
20
|
+
{ regex: /\s/g }, // Any space
|
|
21
|
+
],
|
|
22
|
+
];
|
|
23
|
+
function findFirstMatch(text, regex) {
|
|
24
|
+
// Reset regex
|
|
25
|
+
regex.lastIndex = 0;
|
|
26
|
+
// For very long texts, try chunking
|
|
27
|
+
if (text.length > 10000) {
|
|
28
|
+
const chunkSize = 2000;
|
|
29
|
+
let position = 0;
|
|
30
|
+
while (position < text.length) {
|
|
31
|
+
const chunk = text.substring(position, position + chunkSize);
|
|
32
|
+
regex.lastIndex = 0;
|
|
33
|
+
const match = regex.exec(chunk);
|
|
34
|
+
if (match) {
|
|
35
|
+
return position + match.index;
|
|
36
|
+
}
|
|
37
|
+
// Move to next chunk with some overlap
|
|
38
|
+
position += chunkSize - 100;
|
|
39
|
+
if (position >= text.length)
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
return -1;
|
|
43
|
+
}
|
|
44
|
+
// For shorter texts, normal regex search
|
|
45
|
+
const match = regex.exec(text);
|
|
46
|
+
return match ? match.index : -1;
|
|
47
|
+
}
|
|
48
|
+
// 3. Optimized boundary finding functions
|
|
49
|
+
function findLastMatch(text, regex) {
|
|
50
|
+
// Reset regex state
|
|
51
|
+
regex.lastIndex = 0;
|
|
52
|
+
let lastIndex = -1;
|
|
53
|
+
let lastLength = 0;
|
|
54
|
+
let match;
|
|
55
|
+
// For very long texts, use a different approach to avoid regex engine slowdowns
|
|
56
|
+
if (text.length > 10000) {
|
|
57
|
+
// Try dividing the text into chunks for faster processing
|
|
58
|
+
const chunkSize = 2000;
|
|
59
|
+
let startPosition = Math.max(0, text.length - chunkSize);
|
|
60
|
+
while (startPosition >= 0) {
|
|
61
|
+
const chunk = text.substring(startPosition, startPosition + chunkSize);
|
|
62
|
+
regex.lastIndex = 0;
|
|
63
|
+
let chunkLastIndex = -1;
|
|
64
|
+
let chunkLastLength = 0;
|
|
65
|
+
while ((match = regex.exec(chunk)) !== null) {
|
|
66
|
+
chunkLastIndex = match.index;
|
|
67
|
+
chunkLastLength = match[0].length;
|
|
68
|
+
}
|
|
69
|
+
if (chunkLastIndex !== -1) {
|
|
70
|
+
return startPosition + chunkLastIndex + chunkLastLength;
|
|
71
|
+
}
|
|
72
|
+
// Move to previous chunk with some overlap
|
|
73
|
+
startPosition = Math.max(0, startPosition - chunkSize + 100) - 1;
|
|
74
|
+
if (startPosition <= 0)
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
return -1;
|
|
78
|
+
}
|
|
79
|
+
// For shorter texts, normal regex search
|
|
80
|
+
while ((match = regex.exec(text)) !== null) {
|
|
81
|
+
lastIndex = match.index;
|
|
82
|
+
lastLength = match[0].length;
|
|
83
|
+
}
|
|
84
|
+
return lastIndex === -1 ? -1 : lastIndex + lastLength;
|
|
85
|
+
}
|
|
86
|
+
// 4. Find the best boundary with priority groups
|
|
87
|
+
function findBestBoundary(text, direction = 'backward') {
|
|
88
|
+
if (!text || text.length === 0)
|
|
89
|
+
return 0;
|
|
90
|
+
// Try each priority group
|
|
91
|
+
for (const patternGroup of priorityPatterns) {
|
|
92
|
+
for (const pattern of patternGroup) {
|
|
93
|
+
const position = direction === 'backward'
|
|
94
|
+
? findLastMatch(text, pattern.regex)
|
|
95
|
+
: findFirstMatch(text, pattern.regex);
|
|
96
|
+
if (position !== -1) {
|
|
97
|
+
return position;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// No match found, use character boundary
|
|
102
|
+
return direction === 'backward' ? text.length : 0;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Expand highlights in search results using smart boundary detection.
|
|
106
|
+
*
|
|
107
|
+
* This implementation finds natural text boundaries like paragraphs, sentences,
|
|
108
|
+
* and phrases to provide context while maintaining readability.
|
|
109
|
+
*
|
|
110
|
+
* @param searchResults - Search results object
|
|
111
|
+
* @param mainExpandBy - Primary expansion size on each side (default: 300)
|
|
112
|
+
* @param separatorExpandBy - Additional range to look for separators (default: 150)
|
|
113
|
+
* @returns Copy of search results with expanded highlights
|
|
114
|
+
*/
|
|
115
|
+
function expandHighlights(searchResults, mainExpandBy = 300, separatorExpandBy = 150) {
|
|
116
|
+
// 1. Avoid full deep copy - only copy what we modify
|
|
117
|
+
const resultCopy = { ...searchResults };
|
|
118
|
+
// Only deep copy the relevant arrays
|
|
119
|
+
if (resultCopy.organic) {
|
|
120
|
+
resultCopy.organic = [...resultCopy.organic];
|
|
121
|
+
}
|
|
122
|
+
if (resultCopy.topStories) {
|
|
123
|
+
resultCopy.topStories = [...resultCopy.topStories];
|
|
124
|
+
}
|
|
125
|
+
// 5. Process the results efficiently
|
|
126
|
+
const processResultTypes = ['organic', 'topStories'];
|
|
127
|
+
for (const resultType of processResultTypes) {
|
|
128
|
+
if (!resultCopy[resultType])
|
|
129
|
+
continue;
|
|
130
|
+
// Map results to new array with modified highlights
|
|
131
|
+
resultCopy[resultType] = resultCopy[resultType]?.map((result) => {
|
|
132
|
+
if (result.content == null ||
|
|
133
|
+
result.content === '' ||
|
|
134
|
+
!result.highlights ||
|
|
135
|
+
result.highlights.length === 0) {
|
|
136
|
+
return result; // No modification needed
|
|
137
|
+
}
|
|
138
|
+
// Create a shallow copy with expanded highlights
|
|
139
|
+
const resultCopy = { ...result };
|
|
140
|
+
const content = result.content;
|
|
141
|
+
const highlights = [];
|
|
142
|
+
// Process each highlight
|
|
143
|
+
for (const highlight of result.highlights) {
|
|
144
|
+
const highlightText = highlight.text;
|
|
145
|
+
let startPos = content.indexOf(highlightText);
|
|
146
|
+
let highlightLen = highlightText.length;
|
|
147
|
+
if (startPos === -1) {
|
|
148
|
+
// Try with stripped whitespace
|
|
149
|
+
const strippedHighlight = highlightText.trim();
|
|
150
|
+
startPos = content.indexOf(strippedHighlight);
|
|
151
|
+
if (startPos === -1) {
|
|
152
|
+
highlights.push({
|
|
153
|
+
text: highlight.text,
|
|
154
|
+
score: highlight.score,
|
|
155
|
+
});
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
highlightLen = strippedHighlight.length;
|
|
159
|
+
}
|
|
160
|
+
// Calculate boundaries
|
|
161
|
+
const mainStart = Math.max(0, startPos - mainExpandBy);
|
|
162
|
+
const mainEnd = Math.min(content.length, startPos + highlightLen + mainExpandBy);
|
|
163
|
+
const separatorStart = Math.max(0, mainStart - separatorExpandBy);
|
|
164
|
+
const separatorEnd = Math.min(content.length, mainEnd + separatorExpandBy);
|
|
165
|
+
// Extract text segments
|
|
166
|
+
const headText = content.substring(separatorStart, mainStart);
|
|
167
|
+
const tailText = content.substring(mainEnd, separatorEnd);
|
|
168
|
+
// Find natural boundaries
|
|
169
|
+
const bestHeadBoundary = findBestBoundary(headText, 'backward');
|
|
170
|
+
const bestTailBoundary = findBestBoundary(tailText, 'forward');
|
|
171
|
+
// Calculate final positions
|
|
172
|
+
const finalStart = separatorStart + bestHeadBoundary;
|
|
173
|
+
const finalEnd = mainEnd + bestTailBoundary;
|
|
174
|
+
// Extract the expanded highlight
|
|
175
|
+
const expandedHighlightText = content
|
|
176
|
+
.substring(finalStart, finalEnd)
|
|
177
|
+
.trim();
|
|
178
|
+
highlights.push({
|
|
179
|
+
text: expandedHighlightText,
|
|
180
|
+
score: highlight.score,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
delete resultCopy.content;
|
|
184
|
+
resultCopy.highlights = highlights;
|
|
185
|
+
return resultCopy;
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
return resultCopy;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export { expandHighlights };
|
|
192
|
+
//# sourceMappingURL=highlights.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"highlights.mjs","sources":["../../../../src/tools/search/highlights.ts"],"sourcesContent":["import type * as t from './types';\n\n// 2. Pre-compile all regular expressions (only do this once)\n// Group patterns by priority for early returns\nconst priorityPatterns = [\n // High priority patterns (structural)\n [\n { regex: /\\n\\n/g }, // Double newline (paragraph break)\n { regex: /\\n/g }, // Single newline\n { regex: /={3,}\\s*\\n|-{3,}\\s*\\n/g }, // Section separators\n ],\n // Medium priority (semantic)\n [\n { regex: /[.!?][\")\\]]?\\s/g }, // End of sentence\n { regex: /;\\s/g }, // Semicolon\n { regex: /:\\s/g }, // Colon\n ],\n // Low priority (any breaks)\n [\n { regex: /,\\s/g }, // Comma\n { regex: /\\s-\\s/g }, // Dash surrounded by spaces\n { regex: /\\s/g }, // Any space\n ],\n];\n\nfunction findFirstMatch(text: string, regex: RegExp): number {\n // Reset regex\n regex.lastIndex = 0;\n\n // For very long texts, try chunking\n if (text.length > 10000) {\n const chunkSize = 2000;\n let position = 0;\n\n while (position < text.length) {\n const chunk = text.substring(position, position + chunkSize);\n regex.lastIndex = 0;\n\n const match = regex.exec(chunk);\n if (match) {\n return position + match.index;\n }\n\n // Move to next chunk with some overlap\n position += chunkSize - 100;\n if (position >= text.length) break;\n }\n return -1;\n }\n\n // For shorter texts, normal regex search\n const match = regex.exec(text);\n return match ? match.index : -1;\n}\n\n// 3. Optimized boundary finding functions\nfunction findLastMatch(text: string, regex: RegExp): number {\n // Reset regex state\n regex.lastIndex = 0;\n\n let lastIndex = -1;\n let lastLength = 0;\n let match;\n\n // For very long texts, use a different approach to avoid regex engine slowdowns\n if (text.length > 10000) {\n // Try dividing the text into chunks for faster processing\n const chunkSize = 2000;\n let startPosition = Math.max(0, text.length - chunkSize);\n\n while (startPosition >= 0) {\n const chunk = text.substring(startPosition, startPosition + chunkSize);\n regex.lastIndex = 0;\n\n let chunkLastIndex = -1;\n let chunkLastLength = 0;\n\n while ((match = regex.exec(chunk)) !== null) {\n chunkLastIndex = match.index;\n chunkLastLength = match[0].length;\n }\n\n if (chunkLastIndex !== -1) {\n return startPosition + chunkLastIndex + chunkLastLength;\n }\n\n // Move to previous chunk with some overlap\n startPosition = Math.max(0, startPosition - chunkSize + 100) - 1;\n if (startPosition <= 0) break;\n }\n return -1;\n }\n\n // For shorter texts, normal regex search\n while ((match = regex.exec(text)) !== null) {\n lastIndex = match.index;\n lastLength = match[0].length;\n }\n\n return lastIndex === -1 ? -1 : lastIndex + lastLength;\n}\n\n// 4. Find the best boundary with priority groups\nfunction findBestBoundary(text: string, direction = 'backward'): number {\n if (!text || text.length === 0) return 0;\n\n // Try each priority group\n for (const patternGroup of priorityPatterns) {\n for (const pattern of patternGroup) {\n const position =\n direction === 'backward'\n ? findLastMatch(text, pattern.regex)\n : findFirstMatch(text, pattern.regex);\n\n if (position !== -1) {\n return position;\n }\n }\n }\n\n // No match found, use character boundary\n return direction === 'backward' ? text.length : 0;\n}\n\n/**\n * Expand highlights in search results using smart boundary detection.\n *\n * This implementation finds natural text boundaries like paragraphs, sentences,\n * and phrases to provide context while maintaining readability.\n *\n * @param searchResults - Search results object\n * @param mainExpandBy - Primary expansion size on each side (default: 300)\n * @param separatorExpandBy - Additional range to look for separators (default: 150)\n * @returns Copy of search results with expanded highlights\n */\nexport function expandHighlights(\n searchResults: t.SearchResultData,\n mainExpandBy = 300,\n separatorExpandBy = 150\n): t.SearchResultData {\n // 1. Avoid full deep copy - only copy what we modify\n const resultCopy = { ...searchResults };\n\n // Only deep copy the relevant arrays\n if (resultCopy.organic) {\n resultCopy.organic = [...resultCopy.organic];\n }\n if (resultCopy.topStories) {\n resultCopy.topStories = [...resultCopy.topStories];\n }\n\n // 5. Process the results efficiently\n const processResultTypes = ['organic', 'topStories'] as const;\n\n for (const resultType of processResultTypes) {\n if (!resultCopy[resultType as 'organic' | 'topStories']) continue;\n\n // Map results to new array with modified highlights\n resultCopy[resultType] = resultCopy[resultType]?.map((result) => {\n if (\n result.content == null ||\n result.content === '' ||\n !result.highlights ||\n result.highlights.length === 0\n ) {\n return result; // No modification needed\n }\n\n // Create a shallow copy with expanded highlights\n const resultCopy = { ...result };\n const content = result.content;\n const highlights = [];\n\n // Process each highlight\n for (const highlight of result.highlights) {\n const highlightText = highlight.text;\n\n let startPos = content.indexOf(highlightText);\n let highlightLen = highlightText.length;\n\n if (startPos === -1) {\n // Try with stripped whitespace\n const strippedHighlight = highlightText.trim();\n startPos = content.indexOf(strippedHighlight);\n\n if (startPos === -1) {\n highlights.push({\n text: highlight.text,\n score: highlight.score,\n });\n continue;\n }\n highlightLen = strippedHighlight.length;\n }\n\n // Calculate boundaries\n const mainStart = Math.max(0, startPos - mainExpandBy);\n const mainEnd = Math.min(\n content.length,\n startPos + highlightLen + mainExpandBy\n );\n\n const separatorStart = Math.max(0, mainStart - separatorExpandBy);\n const separatorEnd = Math.min(\n content.length,\n mainEnd + separatorExpandBy\n );\n\n // Extract text segments\n const headText = content.substring(separatorStart, mainStart);\n const tailText = content.substring(mainEnd, separatorEnd);\n\n // Find natural boundaries\n const bestHeadBoundary = findBestBoundary(headText, 'backward');\n const bestTailBoundary = findBestBoundary(tailText, 'forward');\n\n // Calculate final positions\n const finalStart = separatorStart + bestHeadBoundary;\n const finalEnd = mainEnd + bestTailBoundary;\n\n // Extract the expanded highlight\n const expandedHighlightText = content\n .substring(finalStart, finalEnd)\n .trim();\n highlights.push({\n text: expandedHighlightText,\n score: highlight.score,\n });\n }\n\n delete resultCopy.content;\n resultCopy.highlights = highlights;\n return resultCopy;\n });\n }\n\n return resultCopy;\n}\n"],"names":[],"mappings":"AAEA;AACA;AACA,MAAM,gBAAgB,GAAG;;AAEvB,IAAA;AACE,QAAA,EAAE,KAAK,EAAE,OAAO,EAAE;AAClB,QAAA,EAAE,KAAK,EAAE,KAAK,EAAE;AAChB,QAAA,EAAE,KAAK,EAAE,wBAAwB,EAAE;AACpC,KAAA;;AAED,IAAA;AACE,QAAA,EAAE,KAAK,EAAE,iBAAiB,EAAE;AAC5B,QAAA,EAAE,KAAK,EAAE,MAAM,EAAE;AACjB,QAAA,EAAE,KAAK,EAAE,MAAM,EAAE;AAClB,KAAA;;AAED,IAAA;AACE,QAAA,EAAE,KAAK,EAAE,MAAM,EAAE;AACjB,QAAA,EAAE,KAAK,EAAE,QAAQ,EAAE;AACnB,QAAA,EAAE,KAAK,EAAE,KAAK,EAAE;AACjB,KAAA;CACF;AAED,SAAS,cAAc,CAAC,IAAY,EAAE,KAAa,EAAA;;AAEjD,IAAA,KAAK,CAAC,SAAS,GAAG,CAAC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CAAC,QAAQ,EAAE,SAAS,CAAC;;AAG9D,gBAAA,MAAM,UAAU,GAAG,cAAc,GAAG,gBAAgB;AACpD,gBAAA,MAAM,QAAQ,GAAG,OAAO,GAAG,gBAAgB;;gBAG3C,MAAM,qBAAqB,GAAG;AAC3B,qBAAA,SAAS,CAAC,UAAU,EAAE,QAAQ;AAC9B,qBAAA,IAAI,EAAE;gBACT,UAAU,CAAC,IAAI,CAAC;AACd,oBAAA,IAAI,EAAE,qBAAqB;oBAC3B,KAAK,EAAE,SAAS,CAAC,KAAK;AACvB,iBAAA,CAAC;;YAGJ,OAAO,UAAU,CAAC,OAAO;AACzB,YAAA,UAAU,CAAC,UAAU,GAAG,UAAU;AAClC,YAAA,OAAO,UAAU;AACnB,SAAC,CAAC;;AAGJ,IAAA,OAAO,UAAU;AACnB;;;;"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
|
|
3
|
+
/* eslint-disable no-console */
|
|
4
|
+
class BaseReranker {
|
|
5
|
+
apiKey;
|
|
6
|
+
constructor() {
|
|
7
|
+
// Each specific reranker will set its API key
|
|
8
|
+
}
|
|
9
|
+
getDefaultRanking(documents, topK) {
|
|
10
|
+
return documents
|
|
11
|
+
.slice(0, Math.min(topK, documents.length))
|
|
12
|
+
.map((doc) => ({ text: doc, score: 0 }));
|
|
13
|
+
}
|
|
14
|
+
logDocumentSamples(documents) {
|
|
15
|
+
console.log('Sample documents being sent to API:');
|
|
16
|
+
for (let i = 0; i < Math.min(3, documents.length); i++) {
|
|
17
|
+
console.log(`Document ${i}: ${documents[i].substring(0, 100)}...`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
class JinaReranker extends BaseReranker {
|
|
22
|
+
constructor({ apiKey = process.env.JINA_API_KEY }) {
|
|
23
|
+
super();
|
|
24
|
+
this.apiKey = apiKey;
|
|
25
|
+
}
|
|
26
|
+
async rerank(query, documents, topK = 5) {
|
|
27
|
+
console.log(`Reranking ${documents.length} documents with Jina`);
|
|
28
|
+
try {
|
|
29
|
+
if (this.apiKey == null || this.apiKey === '') {
|
|
30
|
+
console.warn('JINA_API_KEY is not set. Using default ranking.');
|
|
31
|
+
return this.getDefaultRanking(documents, topK);
|
|
32
|
+
}
|
|
33
|
+
this.logDocumentSamples(documents);
|
|
34
|
+
const requestData = {
|
|
35
|
+
model: 'jina-reranker-v2-base-multilingual',
|
|
36
|
+
query: query,
|
|
37
|
+
top_n: topK,
|
|
38
|
+
documents: documents,
|
|
39
|
+
return_documents: true,
|
|
40
|
+
};
|
|
41
|
+
const response = await axios.post('https://api.jina.ai/v1/rerank', requestData, {
|
|
42
|
+
headers: {
|
|
43
|
+
'Content-Type': 'application/json',
|
|
44
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
// Log the response data structure
|
|
48
|
+
console.log('Jina API response structure:');
|
|
49
|
+
console.log('Model:', response.data?.model);
|
|
50
|
+
console.log('Usage:', response.data?.usage);
|
|
51
|
+
console.log('Results count:', response.data?.results.length);
|
|
52
|
+
// Log a sample of the results
|
|
53
|
+
if ((response.data?.results.length ?? 0) > 0) {
|
|
54
|
+
console.log('Sample result:', JSON.stringify(response.data?.results[0], null, 2));
|
|
55
|
+
}
|
|
56
|
+
if (response.data && response.data.results.length) {
|
|
57
|
+
return response.data.results.map((result) => {
|
|
58
|
+
const docIndex = result.index;
|
|
59
|
+
const score = result.relevance_score;
|
|
60
|
+
let text = '';
|
|
61
|
+
// If return_documents is true, the document field will be present
|
|
62
|
+
if (result.document != null) {
|
|
63
|
+
const doc = result.document;
|
|
64
|
+
if (typeof doc === 'object' && 'text' in doc) {
|
|
65
|
+
text = doc.text;
|
|
66
|
+
}
|
|
67
|
+
else if (typeof doc === 'string') {
|
|
68
|
+
text = doc;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
// Otherwise, use the index to get the document
|
|
73
|
+
text = documents[docIndex];
|
|
74
|
+
}
|
|
75
|
+
return { text, score };
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
console.warn('Unexpected response format from Jina API. Using default ranking.');
|
|
80
|
+
return this.getDefaultRanking(documents, topK);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
console.error('Error using Jina reranker:', error);
|
|
85
|
+
// Fallback to default ranking on error
|
|
86
|
+
return this.getDefaultRanking(documents, topK);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
class CohereReranker extends BaseReranker {
|
|
91
|
+
constructor({ apiKey = process.env.COHERE_API_KEY }) {
|
|
92
|
+
super();
|
|
93
|
+
this.apiKey = apiKey;
|
|
94
|
+
}
|
|
95
|
+
async rerank(query, documents, topK = 5) {
|
|
96
|
+
console.log(`Reranking ${documents.length} documents with Cohere`);
|
|
97
|
+
try {
|
|
98
|
+
if (this.apiKey == null || this.apiKey === '') {
|
|
99
|
+
console.warn('COHERE_API_KEY is not set. Using default ranking.');
|
|
100
|
+
return this.getDefaultRanking(documents, topK);
|
|
101
|
+
}
|
|
102
|
+
this.logDocumentSamples(documents);
|
|
103
|
+
const requestData = {
|
|
104
|
+
model: 'rerank-v3.5',
|
|
105
|
+
query: query,
|
|
106
|
+
top_n: topK,
|
|
107
|
+
documents: documents,
|
|
108
|
+
};
|
|
109
|
+
const response = await axios.post('https://api.cohere.com/v2/rerank', requestData, {
|
|
110
|
+
headers: {
|
|
111
|
+
'Content-Type': 'application/json',
|
|
112
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
// Log the response data structure
|
|
116
|
+
console.log('Cohere API response structure:');
|
|
117
|
+
console.log('ID:', response.data?.id);
|
|
118
|
+
console.log('Meta:', response.data?.meta);
|
|
119
|
+
console.log('Results count:', response.data?.results.length);
|
|
120
|
+
// Log a sample of the results
|
|
121
|
+
if ((response.data?.results.length ?? 0) > 0) {
|
|
122
|
+
console.log('Sample result:', JSON.stringify(response.data?.results[0], null, 2));
|
|
123
|
+
}
|
|
124
|
+
if (response.data && response.data.results.length) {
|
|
125
|
+
return response.data.results.map((result) => {
|
|
126
|
+
const docIndex = result.index;
|
|
127
|
+
const score = result.relevance_score;
|
|
128
|
+
const text = documents[docIndex];
|
|
129
|
+
return { text, score };
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
console.warn('Unexpected response format from Cohere API. Using default ranking.');
|
|
134
|
+
return this.getDefaultRanking(documents, topK);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
console.error('Error using Cohere reranker:', error);
|
|
139
|
+
// Fallback to default ranking on error
|
|
140
|
+
return this.getDefaultRanking(documents, topK);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
class InfinityReranker extends BaseReranker {
|
|
145
|
+
constructor() {
|
|
146
|
+
super();
|
|
147
|
+
// No API key needed for the placeholder implementation
|
|
148
|
+
}
|
|
149
|
+
async rerank(query, documents, topK = 5) {
|
|
150
|
+
console.log(`Reranking ${documents.length} documents with Infinity (placeholder)`);
|
|
151
|
+
// This would be replaced with actual Infinity reranker implementation
|
|
152
|
+
return this.getDefaultRanking(documents, topK);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Creates the appropriate reranker based on type and configuration
|
|
157
|
+
*/
|
|
158
|
+
const createReranker = (config) => {
|
|
159
|
+
const { rerankerType, jinaApiKey, cohereApiKey } = config;
|
|
160
|
+
switch (rerankerType.toLowerCase()) {
|
|
161
|
+
case 'jina':
|
|
162
|
+
return new JinaReranker({ apiKey: jinaApiKey });
|
|
163
|
+
case 'cohere':
|
|
164
|
+
return new CohereReranker({ apiKey: cohereApiKey });
|
|
165
|
+
case 'infinity':
|
|
166
|
+
return new InfinityReranker();
|
|
167
|
+
case 'none':
|
|
168
|
+
console.log('Skipping reranking as reranker is set to "none"');
|
|
169
|
+
return undefined;
|
|
170
|
+
default:
|
|
171
|
+
console.warn(`Unknown reranker type: ${rerankerType}. Defaulting to InfinityReranker.`);
|
|
172
|
+
return new JinaReranker({ apiKey: jinaApiKey });
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
// Example usage:
|
|
176
|
+
// const jinaReranker = new JinaReranker();
|
|
177
|
+
// const cohereReranker = new CohereReranker();
|
|
178
|
+
// const infinityReranker = new InfinityReranker();
|
|
179
|
+
|
|
180
|
+
export { BaseReranker, CohereReranker, InfinityReranker, JinaReranker, createReranker };
|
|
181
|
+
//# sourceMappingURL=rerankers.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rerankers.mjs","sources":["../../../../src/tools/search/rerankers.ts"],"sourcesContent":["/* eslint-disable no-console */\nimport axios from 'axios';\nimport type * as t from './types';\n\nexport abstract class BaseReranker {\n protected apiKey: string | undefined;\n\n constructor() {\n // Each specific reranker will set its API key\n }\n\n abstract rerank(\n query: string,\n documents: string[],\n topK?: number\n ): Promise<t.Highlight[]>;\n\n protected getDefaultRanking(\n documents: string[],\n topK: number\n ): t.Highlight[] {\n return documents\n .slice(0, Math.min(topK, documents.length))\n .map((doc) => ({ text: doc, score: 0 }));\n }\n\n protected logDocumentSamples(documents: string[]): void {\n console.log('Sample documents being sent to API:');\n for (let i = 0; i < Math.min(3, documents.length); i++) {\n console.log(`Document ${i}: ${documents[i].substring(0, 100)}...`);\n }\n }\n}\n\nexport class JinaReranker extends BaseReranker {\n constructor({ apiKey = process.env.JINA_API_KEY }: { apiKey?: string }) {\n super();\n this.apiKey = apiKey;\n }\n\n async rerank(\n query: string,\n documents: string[],\n topK: number = 5\n ): Promise<t.Highlight[]> {\n console.log(`Reranking ${documents.length} documents with Jina`);\n\n try {\n if (this.apiKey == null || this.apiKey === '') {\n console.warn('JINA_API_KEY is not set. Using default ranking.');\n return this.getDefaultRanking(documents, topK);\n }\n\n this.logDocumentSamples(documents);\n\n const requestData = {\n model: 'jina-reranker-v2-base-multilingual',\n query: query,\n top_n: topK,\n documents: documents,\n return_documents: true,\n };\n\n const response = await axios.post<t.JinaRerankerResponse | undefined>(\n 'https://api.jina.ai/v1/rerank',\n requestData,\n {\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${this.apiKey}`,\n },\n }\n );\n\n // Log the response data structure\n console.log('Jina API response structure:');\n console.log('Model:', response.data?.model);\n console.log('Usage:', response.data?.usage);\n console.log('Results count:', response.data?.results.length);\n\n // Log a sample of the results\n if ((response.data?.results.length ?? 0) > 0) {\n console.log(\n 'Sample result:',\n JSON.stringify(response.data?.results[0], null, 2)\n );\n }\n\n if (response.data && response.data.results.length) {\n return response.data.results.map((result) => {\n const docIndex = result.index;\n const score = result.relevance_score;\n let text = '';\n\n // If return_documents is true, the document field will be present\n if (result.document != null) {\n const doc = result.document;\n if (typeof doc === 'object' && 'text' in doc) {\n text = doc.text;\n } else if (typeof doc === 'string') {\n text = doc;\n }\n } else {\n // Otherwise, use the index to get the document\n text = documents[docIndex];\n }\n\n return { text, score };\n });\n } else {\n console.warn(\n 'Unexpected response format from Jina API. Using default ranking.'\n );\n return this.getDefaultRanking(documents, topK);\n }\n } catch (error) {\n console.error('Error using Jina reranker:', error);\n // Fallback to default ranking on error\n return this.getDefaultRanking(documents, topK);\n }\n }\n}\n\nexport class CohereReranker extends BaseReranker {\n constructor({ apiKey = process.env.COHERE_API_KEY }: { apiKey?: string }) {\n super();\n this.apiKey = apiKey;\n }\n\n async rerank(\n query: string,\n documents: string[],\n topK: number = 5\n ): Promise<t.Highlight[]> {\n console.log(`Reranking ${documents.length} documents with Cohere`);\n\n try {\n if (this.apiKey == null || this.apiKey === '') {\n console.warn('COHERE_API_KEY is not set. Using default ranking.');\n return this.getDefaultRanking(documents, topK);\n }\n\n this.logDocumentSamples(documents);\n\n const requestData = {\n model: 'rerank-v3.5',\n query: query,\n top_n: topK,\n documents: documents,\n };\n\n const response = await axios.post<t.CohereRerankerResponse | undefined>(\n 'https://api.cohere.com/v2/rerank',\n requestData,\n {\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${this.apiKey}`,\n },\n }\n );\n\n // Log the response data structure\n console.log('Cohere API response structure:');\n console.log('ID:', response.data?.id);\n console.log('Meta:', response.data?.meta);\n console.log('Results count:', response.data?.results.length);\n\n // Log a sample of the results\n if ((response.data?.results.length ?? 0) > 0) {\n console.log(\n 'Sample result:',\n JSON.stringify(response.data?.results[0], null, 2)\n );\n }\n\n if (response.data && response.data.results.length) {\n return response.data.results.map((result) => {\n const docIndex = result.index;\n const score = result.relevance_score;\n const text = documents[docIndex];\n return { text, score };\n });\n } else {\n console.warn(\n 'Unexpected response format from Cohere API. Using default ranking.'\n );\n return this.getDefaultRanking(documents, topK);\n }\n } catch (error) {\n console.error('Error using Cohere reranker:', error);\n // Fallback to default ranking on error\n return this.getDefaultRanking(documents, topK);\n }\n }\n}\n\nexport class InfinityReranker extends BaseReranker {\n constructor() {\n super();\n // No API key needed for the placeholder implementation\n }\n\n async rerank(\n query: string,\n documents: string[],\n topK: number = 5\n ): Promise<t.Highlight[]> {\n console.log(\n `Reranking ${documents.length} documents with Infinity (placeholder)`\n );\n // This would be replaced with actual Infinity reranker implementation\n return this.getDefaultRanking(documents, topK);\n }\n}\n\n/**\n * Creates the appropriate reranker based on type and configuration\n */\nexport const createReranker = (config: {\n rerankerType: t.RerankerType;\n jinaApiKey?: string;\n cohereApiKey?: string;\n}): BaseReranker | undefined => {\n const { rerankerType, jinaApiKey, cohereApiKey } = config;\n\n switch (rerankerType.toLowerCase()) {\n case 'jina':\n return new JinaReranker({ apiKey: jinaApiKey });\n case 'cohere':\n return new CohereReranker({ apiKey: cohereApiKey });\n case 'infinity':\n return new InfinityReranker();\n case 'none':\n console.log('Skipping reranking as reranker is set to \"none\"');\n return undefined;\n default:\n console.warn(\n `Unknown reranker type: ${rerankerType}. Defaulting to InfinityReranker.`\n );\n return new JinaReranker({ apiKey: jinaApiKey });\n }\n};\n\n// Example usage:\n// const jinaReranker = new JinaReranker();\n// const cohereReranker = new CohereReranker();\n// const infinityReranker = new InfinityReranker();\n"],"names":[],"mappings":";;AAAA;MAIsB,YAAY,CAAA;AACtB,IAAA,MAAM;AAEhB,IAAA,WAAA,GAAA;;;IAUU,iBAAiB,CACzB,SAAmB,EACnB,IAAY,EAAA;AAEZ,QAAA,OAAO;AACJ,aAAA,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC;AACzC,aAAA,GAAG,CAAC,CAAC,GAAG,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;;AAGlC,IAAA,kBAAkB,CAAC,SAAmB,EAAA;AAC9C,QAAA,OAAO,CAAC,GAAG,CAAC,qCAAqC,CAAC;QAClD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,EAAE;AACtD,YAAA,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAA,EAAA,EAAK,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA,GAAA,CAAK,CAAC;;;AAGvE;AAEK,MAAO,YAAa,SAAQ,YAAY,CAAA;IAC5C,WAAY,CAAA,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,EAAuB,EAAA;AACpE,QAAA,KAAK,EAAE;AACP,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM;;IAGtB,MAAM,MAAM,CACV,KAAa,EACb,SAAmB,EACnB,OAAe,CAAC,EAAA;QAEhB,OAAO,CAAC,GAAG,CAAC,CAAA,UAAA,EAAa,SAAS,CAAC,MAAM,CAAsB,oBAAA,CAAA,CAAC;AAEh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