mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-22 04:06:18 +00:00

* update: Add type * fix: update import statement for NextApiRequest type * fix: update imports to use type for LexicalEditor and EditorState * Refactor imports to use 'import type' for type-only imports across multiple files - Updated imports in various components and API files to use 'import type' for better clarity and to optimize TypeScript's type checking. - Ensured consistent usage of type imports in files related to chat, dataset, workflow, and user management. - Improved code readability and maintainability by distinguishing between value and type imports. * refactor: remove old ESLint configuration and add new rules - Deleted the old ESLint configuration file from the app project. - Added a new ESLint configuration file with updated rules and settings. - Changed imports to use type-only imports in various files for better clarity and performance. - Updated TypeScript configuration to remove unnecessary options. - Added an ESLint ignore file to exclude build and dependency directories from linting. * fix: update imports to use 'import type' for type-only imports in schema files
73 lines
2.0 KiB
TypeScript
73 lines
2.0 KiB
TypeScript
import { SearchScoreTypeEnum } from '../constants';
|
|
import { type SearchDataResponseItemType } from '../type';
|
|
|
|
/* dataset search result concat */
|
|
export const datasetSearchResultConcat = (
|
|
arr: { k: number; list: SearchDataResponseItemType[] }[]
|
|
): SearchDataResponseItemType[] => {
|
|
arr = arr.filter((item) => item.list.length > 0);
|
|
|
|
if (arr.length === 0) return [];
|
|
if (arr.length === 1) return arr[0].list;
|
|
|
|
const map = new Map<string, SearchDataResponseItemType & { rrfScore: number }>();
|
|
|
|
// rrf
|
|
arr.forEach((item) => {
|
|
const k = item.k;
|
|
|
|
item.list.forEach((data, index) => {
|
|
const rank = index + 1;
|
|
const score = 1 / (k + rank);
|
|
|
|
const record = map.get(data.id);
|
|
if (record) {
|
|
// 合并两个score,有相同type的score,取最大值
|
|
const concatScore = [...record.score];
|
|
for (const dataItem of data.score) {
|
|
const sameScore = concatScore.find((item) => item.type === dataItem.type);
|
|
if (sameScore) {
|
|
sameScore.value = Math.max(sameScore.value, dataItem.value);
|
|
} else {
|
|
concatScore.push(dataItem);
|
|
}
|
|
}
|
|
|
|
map.set(data.id, {
|
|
...record,
|
|
score: concatScore,
|
|
rrfScore: record.rrfScore + score
|
|
});
|
|
} else {
|
|
map.set(data.id, {
|
|
...data,
|
|
rrfScore: score
|
|
});
|
|
}
|
|
});
|
|
});
|
|
|
|
// sort
|
|
const mapArray = Array.from(map.values());
|
|
const results = mapArray.sort((a, b) => b.rrfScore - a.rrfScore);
|
|
|
|
return results.map((item, index) => {
|
|
// if SearchScoreTypeEnum.rrf exist, reset score
|
|
const rrfScore = item.score.find((item) => item.type === SearchScoreTypeEnum.rrf);
|
|
if (rrfScore) {
|
|
rrfScore.value = item.rrfScore;
|
|
rrfScore.index = index;
|
|
} else {
|
|
item.score.push({
|
|
type: SearchScoreTypeEnum.rrf,
|
|
value: item.rrfScore,
|
|
index
|
|
});
|
|
}
|
|
|
|
// @ts-ignore
|
|
delete item.rrfScore;
|
|
return item;
|
|
});
|
|
};
|