feat: self vector search

This commit is contained in:
archer
2023-08-26 18:24:16 +08:00
parent 13439c5183
commit be33794a5f
22 changed files with 151 additions and 71 deletions

View File

@@ -1,4 +1,3 @@
import { openaiAccountError } from '../errorCode';
import { insertKbItem } from '@/service/pg';
import { getVector } from '@/pages/api/openapi/plugin/vector';
import { TrainingData } from '../models/trainingData';

View File

@@ -65,7 +65,7 @@ const AppSchema = new Schema({
},
searchSimilarity: {
type: Number,
default: 0.8
default: 0.4
},
searchLimit: {
type: Number,

View File

@@ -1,5 +1,5 @@
import { PgClient } from '@/service/pg';
import type { ChatHistoryItemResType, ChatItemType } from '@/types/chat';
import type { ChatHistoryItemResType } from '@/types/chat';
import { ChatModuleEnum, TaskResponseKeyEnum } from '@/constants/chat';
import { getVector } from '@/pages/api/openapi/plugin/vector';
import { countModelPrice } from '@/service/events/pushBill';
@@ -21,7 +21,7 @@ export type KBSearchResponse = {
};
export async function dispatchKBSearch(props: Record<string, any>): Promise<KBSearchResponse> {
const { kbList = [], similarity = 0.8, limit = 5, userChatInput } = props as KBSearchProps;
const { kbList = [], similarity = 0.4, limit = 5, userChatInput } = props as KBSearchProps;
if (kbList.length === 0) {
return Promise.reject("You didn't choose the knowledge base");
@@ -32,7 +32,7 @@ export async function dispatchKBSearch(props: Record<string, any>): Promise<KBSe
}
// get vector
const vectorModel = global.vectorModels[0];
const vectorModel = kbList[0]?.vectorModel;
const { vectors, tokenLen } = await getVector({
model: vectorModel.model,
input: [userChatInput]

View File

@@ -2,7 +2,7 @@ export const getChatModel = (model?: string) => {
return global.chatModels.find((item) => item.model === model);
};
export const getVectorModel = (model?: string) => {
return global.vectorModels.find((item) => item.model === model);
return global.vectorModels.find((item) => item.model === model) || global.vectorModels[0];
};
export const getModel = (model?: string) => {