perf: 过滤器
This commit is contained in:
parent
a98c56f968
commit
088a90de10
@ -7,7 +7,12 @@ import { ChatItemType } from '@/types/chat';
|
|||||||
import { jsonRes } from '@/service/response';
|
import { jsonRes } from '@/service/response';
|
||||||
import type { ModelSchema } from '@/types/mongoSchema';
|
import type { ModelSchema } from '@/types/mongoSchema';
|
||||||
import { PassThrough } from 'stream';
|
import { PassThrough } from 'stream';
|
||||||
import { modelList, ModelVectorSearchModeMap, ModelVectorSearchModeEnum } from '@/constants/model';
|
import {
|
||||||
|
modelList,
|
||||||
|
ModelVectorSearchModeMap,
|
||||||
|
ModelVectorSearchModeEnum,
|
||||||
|
ModelDataStatusEnum
|
||||||
|
} from '@/constants/model';
|
||||||
import { pushChatBill } from '@/service/events/pushBill';
|
import { pushChatBill } from '@/service/events/pushBill';
|
||||||
import { openaiCreateEmbedding, gpt35StreamResponse } from '@/service/utils/openai';
|
import { openaiCreateEmbedding, gpt35StreamResponse } from '@/service/utils/openai';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
@ -66,7 +71,13 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||||||
const similarity = ModelVectorSearchModeMap[model.search.mode]?.similarity || 0.22;
|
const similarity = ModelVectorSearchModeMap[model.search.mode]?.similarity || 0.22;
|
||||||
const vectorSearch = await PgClient.select<{ id: string; q: string; a: string }>('modelData', {
|
const vectorSearch = await PgClient.select<{ id: string; q: string; a: string }>('modelData', {
|
||||||
fields: ['id', 'q', 'a'],
|
fields: ['id', 'q', 'a'],
|
||||||
where: [['model_id', model._id], 'AND', `vector <=> '[${promptVector}]' < ${similarity}`],
|
where: [
|
||||||
|
['status', ModelDataStatusEnum.ready],
|
||||||
|
'AND',
|
||||||
|
['model_id', model._id],
|
||||||
|
'AND',
|
||||||
|
`vector <=> '[${promptVector}]' < ${similarity}`
|
||||||
|
],
|
||||||
order: [{ field: 'vector', mode: `<=> '[${promptVector}]'` }],
|
order: [{ field: 'vector', mode: `<=> '[${promptVector}]'` }],
|
||||||
limit: 30
|
limit: 30
|
||||||
});
|
});
|
||||||
|
|||||||
@ -5,7 +5,12 @@ import { ChatCompletionRequestMessage, ChatCompletionRequestMessageRoleEnum } fr
|
|||||||
import { ChatItemType } from '@/types/chat';
|
import { ChatItemType } from '@/types/chat';
|
||||||
import { jsonRes } from '@/service/response';
|
import { jsonRes } from '@/service/response';
|
||||||
import { PassThrough } from 'stream';
|
import { PassThrough } from 'stream';
|
||||||
import { modelList, ModelVectorSearchModeMap, ModelVectorSearchModeEnum } from '@/constants/model';
|
import {
|
||||||
|
modelList,
|
||||||
|
ModelVectorSearchModeMap,
|
||||||
|
ModelVectorSearchModeEnum,
|
||||||
|
ModelDataStatusEnum
|
||||||
|
} from '@/constants/model';
|
||||||
import { pushChatBill } from '@/service/events/pushBill';
|
import { pushChatBill } from '@/service/events/pushBill';
|
||||||
import { openaiCreateEmbedding, gpt35StreamResponse } from '@/service/utils/openai';
|
import { openaiCreateEmbedding, gpt35StreamResponse } from '@/service/utils/openai';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
@ -80,7 +85,13 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||||||
const similarity = ModelVectorSearchModeMap[model.search.mode]?.similarity || 0.22;
|
const similarity = ModelVectorSearchModeMap[model.search.mode]?.similarity || 0.22;
|
||||||
const vectorSearch = await PgClient.select<{ id: string; q: string; a: string }>('modelData', {
|
const vectorSearch = await PgClient.select<{ id: string; q: string; a: string }>('modelData', {
|
||||||
fields: ['id', 'q', 'a'],
|
fields: ['id', 'q', 'a'],
|
||||||
where: [['model_id', model._id], 'AND', `vector <=> '[${promptVector}]' < ${similarity}`],
|
where: [
|
||||||
|
['status', ModelDataStatusEnum.ready],
|
||||||
|
'AND',
|
||||||
|
['model_id', model._id],
|
||||||
|
'AND',
|
||||||
|
`vector <=> '[${promptVector}]' < ${similarity}`
|
||||||
|
],
|
||||||
order: [{ field: 'vector', mode: `<=> '[${promptVector}]'` }],
|
order: [{ field: 'vector', mode: `<=> '[${promptVector}]'` }],
|
||||||
limit: 30
|
limit: 30
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user