@maiyunnet/kebab 5.2.0 → 5.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/lib/db/pool.js +1 -1
- package/lib/vector.d.ts +16 -2
- package/lib/vector.js +42 -2
- package/package.json +1 -1
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* --- 本文件用来定义每个目录实体地址的常量 ---
|
|
7
7
|
*/
|
|
8
8
|
/** --- 当前系统版本号 --- */
|
|
9
|
-
export const VER = '5.
|
|
9
|
+
export const VER = '5.3.1';
|
|
10
10
|
// --- 服务端用的路径 ---
|
|
11
11
|
const imu = decodeURIComponent(import.meta.url).replace('file://', '').replace(/^\/(\w:)/, '$1');
|
|
12
12
|
/** --- /xxx/xxx --- */
|
package/lib/db/pool.js
CHANGED
|
@@ -57,7 +57,7 @@ async function checkConnection() {
|
|
|
57
57
|
return lSql.format(item.sql, item.values);
|
|
58
58
|
});
|
|
59
59
|
const msg = `[DB][checkConnection] There is a transactional connection[${i}] that is not closed, last sql: ${newarr.join(', ')}.`;
|
|
60
|
-
lCore.
|
|
60
|
+
lCore.debug(msg);
|
|
61
61
|
lCore.log({}, msg, '-error');
|
|
62
62
|
await connection.rollback();
|
|
63
63
|
}
|
package/lib/vector.d.ts
CHANGED
|
@@ -29,9 +29,9 @@ export declare class Vector {
|
|
|
29
29
|
'collection': string;
|
|
30
30
|
/** --- 查询的向量 --- */
|
|
31
31
|
'data': number[];
|
|
32
|
-
/** --- 过滤器,如 word_count > 0 --- */
|
|
32
|
+
/** --- 过滤器,如 word_count > 0 and book_id in [1, 2, 3] --- */
|
|
33
33
|
'filter'?: string;
|
|
34
|
-
/** --- 返回的结果数量,默认为
|
|
34
|
+
/** --- 返回的结果数量,默认为 3 --- */
|
|
35
35
|
'limit'?: number;
|
|
36
36
|
/** --- 计算两个向量相似度的度量,默认 L2 --- */
|
|
37
37
|
'metric'?: 'L2' | 'IP' | 'COSINE';
|
|
@@ -45,6 +45,20 @@ export declare class Vector {
|
|
|
45
45
|
metric_type: "L2" | "IP" | "COSINE";
|
|
46
46
|
output_fields: string[] | undefined;
|
|
47
47
|
}>>;
|
|
48
|
+
/** --- 插入数据 --- */
|
|
49
|
+
insert(data: {
|
|
50
|
+
/** --- 表名 --- */
|
|
51
|
+
'collection': string;
|
|
52
|
+
/** --- 要插入的数据 --- */
|
|
53
|
+
'data': milvus.RowData[];
|
|
54
|
+
}): Promise<milvus.MutationResult | false>;
|
|
55
|
+
/** --- 删除数据 --- */
|
|
56
|
+
delete(data: {
|
|
57
|
+
/** --- 表名 --- */
|
|
58
|
+
'collection': string;
|
|
59
|
+
/** --- 过滤器,如 word_count > 0 and book_id in [1, 2, 3] --- */
|
|
60
|
+
'filter': string;
|
|
61
|
+
}): Promise<milvus.MutationResult | false>;
|
|
48
62
|
/**
|
|
49
63
|
* --- 从连接池中获取一个符合要求的连接 ---
|
|
50
64
|
*/
|
package/lib/vector.js
CHANGED
|
@@ -24,13 +24,53 @@ export class Vector {
|
|
|
24
24
|
'collection_name': data.collection,
|
|
25
25
|
'data': data.data,
|
|
26
26
|
'filter': data.filter,
|
|
27
|
-
'limit': data.limit ??
|
|
27
|
+
'limit': data.limit ?? 3,
|
|
28
28
|
'metric_type': data.metric ?? 'L2',
|
|
29
29
|
'output_fields': data.fields,
|
|
30
30
|
});
|
|
31
31
|
return res;
|
|
32
32
|
}
|
|
33
|
-
catch {
|
|
33
|
+
catch (e) {
|
|
34
|
+
lCore.log({}, '[VECTOR][seach][error] ' + e.message, '-error');
|
|
35
|
+
lCore.debug('[VECTOR][seach]', e.code, e.message);
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** --- 插入数据 --- */
|
|
40
|
+
async insert(data) {
|
|
41
|
+
const link = await this._getConnection();
|
|
42
|
+
if (!link) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
const res = await link.insert({
|
|
47
|
+
'collection_name': data.collection,
|
|
48
|
+
'data': data.data,
|
|
49
|
+
});
|
|
50
|
+
return res;
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
lCore.log({}, '[VECTOR][insert][error] ' + e.message, '-error');
|
|
54
|
+
lCore.debug('[VECTOR][insert]', e.code, e.message);
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** --- 删除数据 --- */
|
|
59
|
+
async delete(data) {
|
|
60
|
+
const link = await this._getConnection();
|
|
61
|
+
if (!link) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
const res = await link.delete({
|
|
66
|
+
'collection_name': data.collection,
|
|
67
|
+
'filter': data.filter,
|
|
68
|
+
});
|
|
69
|
+
return res;
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
lCore.log({}, '[VECTOR][delete][error] ' + e.message, '-error');
|
|
73
|
+
lCore.debug('[VECTOR][delete]', e.code, e.message);
|
|
34
74
|
return false;
|
|
35
75
|
}
|
|
36
76
|
}
|