mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-22 20:37:48 +00:00
feat: maxlink and search sql
This commit is contained in:
@@ -91,16 +91,17 @@ export async function appKbSearch({
|
||||
});
|
||||
|
||||
// search kb
|
||||
const { rows: searchRes } = await PgClient.select<QuoteItemType>('modelData', {
|
||||
fields: ['id', 'q', 'a', 'source'],
|
||||
where: [
|
||||
`kb_id IN (${model.chat.relatedKbs.map((item) => `'${item}'`).join(',')})`,
|
||||
'AND',
|
||||
`vector <#> '[${promptVector[0]}]' < ${similarity}`
|
||||
],
|
||||
order: [{ field: 'vector', mode: `<#> '[${promptVector[0]}]'` }],
|
||||
limit: 8
|
||||
});
|
||||
const res: any = await PgClient.query(
|
||||
`BEGIN;
|
||||
SET LOCAL ivfflat.probes = ${process.env.PG_IVFFLAT_PROBE || 100};
|
||||
select id,q,a,source from modelData where kb_id IN (${model.chat.relatedKbs
|
||||
.map((item) => `'${item}'`)
|
||||
.join(',')}) AND vector <#> '[${promptVector[0]}]' < ${similarity} order by vector <#> '[${
|
||||
promptVector[0]
|
||||
}]' limit 8;
|
||||
COMMIT;`
|
||||
);
|
||||
const searchRes: QuoteItemType[] = res?.[2]?.rows || [];
|
||||
|
||||
// filter same search result
|
||||
const idSet = new Set<string>();
|
||||
|
@@ -13,7 +13,7 @@ export const connectPg = async () => {
|
||||
user: process.env.PG_USER,
|
||||
password: process.env.PG_PASSWORD,
|
||||
database: process.env.PG_DB_NAME,
|
||||
max: maxLink,
|
||||
max: Math.floor(maxLink * 0.5),
|
||||
idleTimeoutMillis: 60000,
|
||||
connectionTimeoutMillis: 20000
|
||||
});
|
||||
|
Reference in New Issue
Block a user