Skip to content

Commit 603c5a2

Browse files
authored
fix: build (#5791)
* fix: build * vector cache code
1 parent cd66814 commit 603c5a2

File tree

3 files changed

+42
-16
lines changed

3 files changed

+42
-16
lines changed

document/content/docs/upgrading/4-13/4132.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ S3_PUBLIC_BUCKET=S3公开桶名称(公开读私有写)
1515

1616
1. HTTP 工具集支持手动创建模式。
1717
2. 项目 OpenAPI 框架引入。
18-
3. APIKey 有消息检测接口
18+
3. APIKey 有效性检测接口
1919
4. 导出对话日志,末尾跟随当前版本全局变量。
2020

2121
## ⚙️ 优化

packages/service/common/vectorDB/controller.ts

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,36 @@ const getVectorObj = () => {
2626
return new PgVectorCtrl();
2727
};
2828

29-
const getChcheKey = (teamId: string) => `${CacheKeyEnum.team_vector_count}:${teamId}`;
30-
const onDelCache = throttle((teamId: string) => delRedisCache(getChcheKey(teamId)), 30000, {
31-
leading: true,
32-
trailing: true
33-
});
34-
const onIncrCache = (teamId: string) => incrValueToCache(getChcheKey(teamId), 1);
29+
const teamVectorCache = {
30+
getKey: function (teamId: string) {
31+
return `${CacheKeyEnum.team_vector_count}:${teamId}`;
32+
},
33+
get: async function (teamId: string) {
34+
const countStr = await getRedisCache(teamVectorCache.getKey(teamId));
35+
if (countStr) {
36+
return Number(countStr);
37+
}
38+
return undefined;
39+
},
40+
set: function ({ teamId, count }: { teamId: string; count: number }) {
41+
retryFn(() =>
42+
setRedisCache(teamVectorCache.getKey(teamId), count, CacheKeyEnumTime.team_vector_count)
43+
).catch();
44+
},
45+
delete: throttle(
46+
function (teamId: string) {
47+
return retryFn(() => delRedisCache(teamVectorCache.getKey(teamId))).catch();
48+
},
49+
30000,
50+
{
51+
leading: true,
52+
trailing: true
53+
}
54+
),
55+
incr: function (teamId: string, count: number) {
56+
retryFn(() => incrValueToCache(teamVectorCache.getKey(teamId), count)).catch();
57+
}
58+
};
3559

3660
const Vector = getVectorObj();
3761

@@ -41,16 +65,17 @@ export const recallFromVectorStore = (props: EmbeddingRecallCtrlProps) =>
4165
export const getVectorDataByTime = Vector.getVectorDataByTime;
4266

4367
export const getVectorCountByTeamId = async (teamId: string) => {
44-
const key = getChcheKey(teamId);
45-
46-
const countStr = await getRedisCache(key);
47-
if (countStr) {
48-
return Number(countStr);
68+
const cacheCount = await teamVectorCache.get(teamId);
69+
if (cacheCount !== undefined) {
70+
return cacheCount;
4971
}
5072

5173
const count = await Vector.getVectorCountByTeamId(teamId);
5274

53-
await setRedisCache(key, count, CacheKeyEnumTime.team_vector_count);
75+
teamVectorCache.set({
76+
teamId,
77+
count
78+
});
5479

5580
return count;
5681
};
@@ -78,7 +103,7 @@ export const insertDatasetDataVector = async ({
78103
})
79104
);
80105

81-
onIncrCache(props.teamId);
106+
teamVectorCache.incr(props.teamId, insertIds.length);
82107

83108
return {
84109
tokens,
@@ -88,6 +113,6 @@ export const insertDatasetDataVector = async ({
88113

89114
export const deleteDatasetDataVector = async (props: DelDatasetVectorCtrlProps) => {
90115
const result = await retryFn(() => Vector.delete(props));
91-
onDelCache(props.teamId);
116+
teamVectorCache.delete(props.teamId);
92117
return result;
93118
};

projects/app/next.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ const nextConfig = {
136136
'pg',
137137
'bullmq',
138138
'@zilliz/milvus2-sdk-node',
139-
'tiktoken'
139+
'tiktoken',
140+
'@opentelemetry/api-logs'
140141
],
141142
outputFileTracingRoot: path.join(__dirname, '../../'),
142143
instrumentationHook: true,

0 commit comments

Comments
 (0)