perf: 改用hash索引

This commit is contained in:
archer
2023-03-31 02:58:09 +08:00
parent 5ec8aac3ac
commit ed1f93d836
10 changed files with 92 additions and 35 deletions

View File

@@ -3,6 +3,7 @@ import { httpsAgent } from '@/service/utils/tools';
import { ModelData } from '../models/modelData';
import { connectRedis } from '../redis';
import { VecModelDataIndex } from '@/constants/redis';
import { vectorToBuffer } from '@/utils/tools';
export async function generateVector(next = false): Promise<any> {
if (global.generatingVector && !next) return;
@@ -47,14 +48,14 @@ export async function generateVector(next = false): Promise<any> {
.then((res) => res?.data?.data?.[0]?.embedding || [])
.then((vector) =>
redis.sendCommand([
'JSON.SET',
'HMSET',
`${VecModelDataIndex}:${item.id}`,
'$',
JSON.stringify({
dataId,
modelId: String(dataItem.modelId),
vector
})
'vector',
vectorToBuffer(vector),
'modelId',
String(dataItem.modelId),
'dataId',
String(dataId)
])
)
)