feat: pg vector 0.8.0;perf: app pdf enhance parse (#3962)

* perf: app pdf enhance parse

* feat: pg vector 0.8.0

* update schema default

* model sort and default image

* perf: i18n

* perf: ui tip
This commit is contained in:
Archer
2025-03-04 13:43:50 +08:00
committed by archer
parent adf5377ebe
commit 54eb5c0547
33 changed files with 181 additions and 66 deletions

View File

@@ -188,6 +188,7 @@ export type AppAutoExecuteConfigType = {
// File
export type AppFileSelectConfigType = {
canSelectFile: boolean;
customPdfParse?: boolean;
canSelectImg: boolean;
maxFiles: number;
};

View File

@@ -164,34 +164,22 @@ export class PgVectorCtrl {
}
try {
// const explan: any = await PgClient.query(
// `BEGIN;
// SET LOCAL hnsw.ef_search = ${global.systemEnv?.pgHNSWEfSearch || 100};
// EXPLAIN ANALYZE select id, collection_id, vector <#> '[${vector}]' AS score
// from ${DatasetVectorTableName}
// where team_id='${teamId}'
// AND dataset_id IN (${datasetIds.map((id) => `'${String(id)}'`).join(',')})
// ${forbidCollectionSql}
// order by score limit ${limit};
// COMMIT;`
// );
// console.log(explan[2].rows);
const results: any = await PgClient.query(
`
BEGIN;
`BEGIN;
SET LOCAL hnsw.ef_search = ${global.systemEnv?.pgHNSWEfSearch || 100};
select id, collection_id, vector <#> '[${vector}]' AS score
from ${DatasetVectorTableName}
where team_id='${teamId}'
AND dataset_id IN (${datasetIds.map((id) => `'${String(id)}'`).join(',')})
${filterCollectionIdSql}
${forbidCollectionSql}
order by score limit ${limit};
SET LOCAL hnsw.iterative_scan = relaxed_order;
WITH relaxed_results AS MATERIALIZED (
select id, collection_id, vector <#> '[${vector}]' AS score
from ${DatasetVectorTableName}
where team_id='${teamId}'
AND dataset_id IN (${datasetIds.map((id) => `'${String(id)}'`).join(',')})
${filterCollectionIdSql}
${forbidCollectionSql}
order by score limit ${limit}
) SELECT id, collection_id, score FROM relaxed_results ORDER BY score;
COMMIT;`
);
const rows = results?.[2]?.rows as PgSearchRawType[];
const rows = results?.[3]?.rows as PgSearchRawType[];
return {
results: rows.map((item) => ({

View File

@@ -163,6 +163,13 @@ export const loadSystemModels = async (init = false) => {
global.systemDefaultModel.rerank = Array.from(global.reRankModelMap.values())[0];
}
// Sort model list
global.systemActiveModelList.sort((a, b) => {
const providerA = getModelProvider(a.provider);
const providerB = getModelProvider(b.provider);
return providerA.order - providerB.order;
});
console.log('Load models success', JSON.stringify(global.systemActiveModelList, null, 2));
} catch (error) {
console.error('Load models error', error);

View File

@@ -45,8 +45,7 @@ const DatasetDataSchema = new Schema({
{
// Abandon
defaultIndex: {
type: Boolean,
default: false
type: Boolean
},
type: {
type: String,

View File

@@ -11,6 +11,7 @@ import { addLog } from '../../../common/system/log';
import { getCollectionWithDataset } from '../controller';
import { mongoSessionRun } from '../../../common/mongo/sessionRun';
import { PushDataToTrainingQueueProps } from '@fastgpt/global/core/dataset/training/type';
import { i18nT } from '../../../../web/i18n/utils';
export const lockTrainingDataByTeamId = async (teamId: string): Promise<any> => {
try {
@@ -71,7 +72,7 @@ export async function pushDataListToTrainingQueue({
if (mode === TrainingModeEnum.chunk) {
const vectorModelData = getEmbeddingModel(vectorModel);
if (!vectorModelData) {
return Promise.reject(`Vector model ${vectorModel} is inValid`);
return Promise.reject(i18nT('common:error_embedding_not_config'));
}
return {
maxToken: vectorModelData.maxToken * 1.5,
@@ -83,7 +84,7 @@ export async function pushDataListToTrainingQueue({
if (mode === TrainingModeEnum.qa || mode === TrainingModeEnum.auto) {
const agentModelData = getLLMModel(agentModel);
if (!agentModelData) {
return Promise.reject(`File model ${agentModel} is inValid`);
return Promise.reject(i18nT('common:error_llm_not_config'));
}
return {
maxToken: agentModelData.maxContext * 0.8,
@@ -95,7 +96,7 @@ export async function pushDataListToTrainingQueue({
if (mode === TrainingModeEnum.image) {
const vllmModelData = getVlmModel(vlmModel);
if (!vllmModelData) {
return Promise.reject(`Vlm model ${vlmModel} is inValid`);
return Promise.reject(i18nT('common:error_vlm_not_config'));
}
return {
maxToken: vllmModelData.maxContext * 0.8,

View File

@@ -104,6 +104,7 @@ export const dispatchRunTools = async (props: DispatchToolModuleProps): Promise<
histories: chatHistories,
requestOrigin,
maxFiles: chatConfig?.fileSelectConfig?.maxFiles || 20,
customPdfParse: chatConfig?.fileSelectConfig?.customPdfParse,
fileLinks,
inputFiles: globalFiles,
hasReadFilesTool
@@ -295,6 +296,7 @@ const getMultiInput = async ({
fileLinks,
requestOrigin,
maxFiles,
customPdfParse,
inputFiles,
hasReadFilesTool
}: {
@@ -303,6 +305,7 @@ const getMultiInput = async ({
fileLinks?: string[];
requestOrigin?: string;
maxFiles: number;
customPdfParse?: boolean;
inputFiles: UserChatItemValueItemType['file'][];
hasReadFilesTool: boolean;
}) => {
@@ -330,6 +333,7 @@ const getMultiInput = async ({
urls,
requestOrigin,
maxFiles,
customPdfParse,
teamId: runningUserInfo.teamId,
tmbId: runningUserInfo.tmbId
});

View File

@@ -124,6 +124,7 @@ export const dispatchChatCompletion = async (props: ChatProps): Promise<ChatResp
stringQuoteText,
requestOrigin,
maxFiles: chatConfig?.fileSelectConfig?.maxFiles || 20,
customPdfParse: chatConfig?.fileSelectConfig?.customPdfParse,
runningUserInfo
})
]);
@@ -358,6 +359,7 @@ async function getMultiInput({
stringQuoteText,
requestOrigin,
maxFiles,
customPdfParse,
runningUserInfo
}: {
histories: ChatItemType[];
@@ -366,6 +368,7 @@ async function getMultiInput({
stringQuoteText?: string; // file quote
requestOrigin?: string;
maxFiles: number;
customPdfParse?: boolean;
runningUserInfo: ChatDispatchProps['runningUserInfo'];
}) {
// 旧版本适配====>
@@ -403,6 +406,7 @@ async function getMultiInput({
urls,
requestOrigin,
maxFiles,
customPdfParse,
teamId: runningUserInfo.teamId,
tmbId: runningUserInfo.tmbId
});

View File

@@ -52,6 +52,7 @@ export const dispatchReadFiles = async (props: Props): Promise<Response> => {
params: { fileUrlList = [] }
} = props;
const maxFiles = chatConfig?.fileSelectConfig?.maxFiles || 20;
const customPdfParse = chatConfig?.fileSelectConfig?.customPdfParse || false;
// Get files from histories
const filesFromHistories = version !== '489' ? [] : getHistoryFileLinks(histories);
@@ -62,7 +63,8 @@ export const dispatchReadFiles = async (props: Props): Promise<Response> => {
requestOrigin,
maxFiles,
teamId,
tmbId
tmbId,
customPdfParse
});
return {
@@ -107,13 +109,15 @@ export const getFileContentFromLinks = async ({
requestOrigin,
maxFiles,
teamId,
tmbId
tmbId,
customPdfParse
}: {
urls: string[];
requestOrigin?: string;
maxFiles: number;
teamId: string;
tmbId: string;
customPdfParse?: boolean;
}) => {
const parseUrlList = urls
// Remove invalid urls
@@ -210,7 +214,8 @@ export const getFileContentFromLinks = async ({
teamId,
tmbId,
buffer,
encoding
encoding,
customPdfParse
});
// Add to buffer

View File

@@ -43,5 +43,7 @@
"selected_model_empty": "Choose at least one model",
"start_test": "Start testing {{num}} models",
"test_failed": "There are {{num}} models that report errors",
"vlm_model": "Vlm",
"vlm_model_tip": "Used to generate additional indexing of images in a document in the knowledge base",
"waiting_test": "Waiting for testing"
}

View File

@@ -105,6 +105,9 @@
"open_vision_function_tip": "Models with icon switches have image recognition capabilities. \nAfter being turned on, the model will parse the pictures in the file link and automatically parse the pictures in the user's question (user question ≤ 500 words).",
"or_drag_JSON": "or drag in JSON file",
"paste_config_or_drag": "Paste config or drag JSON file here",
"pdf_enhance_parse": "PDF enhancement analysis",
"pdf_enhance_parse_price": "{{price}}Points/page",
"pdf_enhance_parse_tips": "Calling PDF recognition model for parsing, you can convert it into Markdown and retain pictures in the document. At the same time, you can also identify scanned documents, which will take a long time to identify them.",
"permission.des.manage": "Based on write permissions, you can configure publishing channels, view conversation logs, and assign permissions to the application.",
"permission.des.read": "Use the app to have conversations",
"permission.des.write": "Can view and edit apps",

View File

@@ -883,6 +883,9 @@
"error.upload_image_error": "File upload failed",
"error.username_empty": "Account cannot be empty",
"error_collection_not_exist": "The collection does not exist",
"error_embedding_not_config": "Unconfigured index model",
"error_llm_not_config": "Unconfigured file understanding model",
"error_vlm_not_config": "Image comprehension model not configured",
"extraction_results": "Extraction Results",
"field_name": "Field Name",
"free": "Free",

View File

@@ -76,7 +76,7 @@
"params_setting": "Parameter settings",
"pdf_enhance_parse": "PDF enhancement analysis",
"pdf_enhance_parse_price": "{{price}} points/page",
"pdf_enhance_parse_tips": "When parsing a PDF file, the PDF recognition model is called for recognition, which can be converted into Markdown and retained the pictures in the document, and can also identify the scanned files.",
"pdf_enhance_parse_tips": "Calling PDF recognition model for parsing, you can convert it into Markdown and retain pictures in the document. At the same time, you can also identify scanned documents, which will take a long time to identify them.",
"permission.des.manage": "Can manage the entire knowledge base data and information",
"permission.des.read": "View knowledge base content",
"permission.des.write": "Ability to add and change knowledge base content",

View File

@@ -43,5 +43,7 @@
"selected_model_empty": "至少选择一个模型",
"start_test": "开始测试{{num}}个模型",
"test_failed": "有{{num}}个模型报错",
"vlm_model": "图片理解模型",
"vlm_model_tip": "用于知识库中对文档中的图片进行额外的索引生成",
"waiting_test": "等待测试"
}

View File

@@ -105,6 +105,9 @@
"open_vision_function_tip": "有图示开关的模型即拥有图片识别能力。若开启模型会解析文件链接里的图片并自动解析用户问题中的图片用户问题≤500字时生效。",
"or_drag_JSON": "或拖入JSON文件",
"paste_config_or_drag": "粘贴配置或拖入 JSON 文件",
"pdf_enhance_parse": "PDF增强解析",
"pdf_enhance_parse_price": "{{price}}积分/页",
"pdf_enhance_parse_tips": "调用 PDF 识别模型进行解析,可以将其转换成 Markdown 并保留文档中的图片,同时也可以对扫描件进行识别,识别时间较长。",
"permission.des.manage": "写权限基础上,可配置发布渠道、查看对话日志、分配该应用权限",
"permission.des.read": "可使用该应用进行对话",
"permission.des.write": "可查看和编辑应用",

View File

@@ -886,6 +886,9 @@
"error.upload_image_error": "上传文件失败",
"error.username_empty": "账号不能为空",
"error_collection_not_exist": "集合不存在",
"error_embedding_not_config": "未配置索引模型",
"error_llm_not_config": "未配置文件理解模型",
"error_vlm_not_config": "未配置图片理解模型",
"extraction_results": "提取结果",
"field_name": "字段名",
"free": "免费",

View File

@@ -76,7 +76,7 @@
"params_setting": "参数设置",
"pdf_enhance_parse": "PDF增强解析",
"pdf_enhance_parse_price": "{{price}}积分/页",
"pdf_enhance_parse_tips": "解析 PDF 文件时,调用 PDF 识别模型进行识别,可以将其转换成 Markdown 并保留文档中的图片,同时也可以对扫描件进行识别。",
"pdf_enhance_parse_tips": "调用 PDF 识别模型进行解析,可以将其转换成 Markdown 并保留文档中的图片,同时也可以对扫描件进行识别,识别时间较长。",
"permission.des.manage": "可管理整个知识库数据和信息",
"permission.des.read": "可查看知识库内容",
"permission.des.write": "可增加和变更知识库内容",

View File

@@ -41,5 +41,7 @@
"selected_model_empty": "至少選擇一個模型",
"start_test": "開始測試{{num}}個模型",
"test_failed": "有{{num}}個模型報錯",
"vlm_model": "圖片理解模型",
"vlm_model_tip": "用於知識庫中對文檔中的圖片進行額外的索引生成",
"waiting_test": "等待測試"
}

View File

@@ -105,6 +105,9 @@
"open_vision_function_tip": "有圖示開關的模型即擁有圖片辨識功能。若開啟,模型會解析檔案連結中的圖片,並自動解析使用者問題中的圖片(使用者問題 ≤ 500 字時生效)。",
"or_drag_JSON": "或拖曳 JSON 檔案",
"paste_config_or_drag": "貼上配置或拖入 JSON 文件",
"pdf_enhance_parse": "PDF增強解析",
"pdf_enhance_parse_price": "{{price}}積分/頁",
"pdf_enhance_parse_tips": "調用 PDF 識別模型進行解析,可以將其轉換成 Markdown 並保留文檔中的圖片,同時也可以對掃描件進行識別,識別時間較長。",
"permission.des.manage": "在寫入權限基礎上,可以設定發布通道、檢視對話紀錄、分配這個應用程式的權限",
"permission.des.read": "可以使用這個應用程式進行對話",
"permission.des.write": "可以檢視和編輯應用程式",

View File

@@ -883,6 +883,9 @@
"error.upload_image_error": "上傳文件失敗",
"error.username_empty": "帳號不能為空",
"error_collection_not_exist": "集合不存在",
"error_embedding_not_config": "未配置索引模型",
"error_llm_not_config": "未配置文件理解模型",
"error_vlm_not_config": "未配置圖片理解模型",
"extraction_results": "提取結果",
"field_name": "欄位名稱",
"free": "免費",

View File

@@ -76,7 +76,7 @@
"params_setting": "參數設置",
"pdf_enhance_parse": "PDF增強解析",
"pdf_enhance_parse_price": "{{price}}積分/頁",
"pdf_enhance_parse_tips": "解析 PDF 文件時,調用 PDF 識別模型進行識別,可以將其轉換成 Markdown 並保留文檔中的圖片,同時也可以對掃描件進行識別。",
"pdf_enhance_parse_tips": "調用 PDF 識別模型進行解析,可以將其轉換成 Markdown 並保留文檔中的圖片,同時也可以對掃描件進行識別,識別時間較長。",
"permission.des.manage": "可管理整個資料集的資料和資訊",
"permission.des.read": "可檢視資料集內容",
"permission.des.write": "可新增和變更資料集內容",