@maiyunnet/kebab 9.7.3 → 9.9.0

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/doc/kebab-rag.md CHANGED
@@ -1360,7 +1360,7 @@ index/variables/VER.md
1360
1360
 
1361
1361
  # Variable: VER
1362
1362
 
1363
- > `const` **VER**: `"9.7.3"` = `'9.7.3'`
1363
+ > `const` **VER**: `"9.9.0"` = `'9.9.0'`
1364
1364
 
1365
1365
  Defined in: [index.ts:10](https://github.com/maiyunnet/kebab/blob/master/index.ts#L10)
1366
1366
 
@@ -3258,7 +3258,7 @@ lib/core/functions/clone.md
3258
3258
 
3259
3259
  > **clone**\<`T`\>(`obj`): `T`
3260
3260
 
3261
- Defined in: [lib/core.ts:1167](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L1167)
3261
+ Defined in: [lib/core.ts:1162](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L1162)
3262
3262
 
3263
3263
  完整的克隆一份数组/对象
3264
3264
 
@@ -3322,7 +3322,7 @@ lib/core/functions/debug.md
3322
3322
 
3323
3323
  > **debug**(`message?`, ...`optionalParams`): `void`
3324
3324
 
3325
- Defined in: [lib/core.ts:1201](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L1201)
3325
+ Defined in: [lib/core.ts:1196](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L1196)
3326
3326
 
3327
3327
  打印调试信息,线上环境不会打印
3328
3328
 
@@ -3357,7 +3357,7 @@ lib/core/functions/display.md
3357
3357
 
3358
3358
  > **display**(`message?`, ...`optionalParams`): `void`
3359
3359
 
3360
- Defined in: [lib/core.ts:1214](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L1214)
3360
+ Defined in: [lib/core.ts:1209](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L1209)
3361
3361
 
3362
3362
  向控制台直接显示内容,一般情况下禁止使用
3363
3363
 
@@ -3460,7 +3460,7 @@ lib/core/functions/getLog.md
3460
3460
 
3461
3461
  # Function: getLog()
3462
3462
 
3463
- > **getLog**(`opt`): `Promise`\<`false` \| `any`[] \| `string`[][] \| `null`\>
3463
+ > **getLog**(`opt`): `Promise`\<`false` \| \{ `list`: `any`[] \| `string`[][]; `total`: `number`; \}\>
3464
3464
 
3465
3465
  Defined in: [lib/core.ts:1074](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L1074)
3466
3466
 
@@ -3514,15 +3514,9 @@ Defined in: [lib/core.ts:1074](https://github.com/maiyunnet/kebab/blob/master/li
3514
3514
 
3515
3515
  仅显示被搜索到的行
3516
3516
 
3517
- #### start?
3518
-
3519
- `number`
3520
-
3521
- 跳过的字节数,默认不跳过
3522
-
3523
3517
  ## Returns
3524
3518
 
3525
- `Promise`\<`false` \| `any`[] \| `string`[][] \| `null`\>
3519
+ `Promise`\<`false` \| \{ `list`: `any`[] \| `string`[][]; `total`: `number`; \}\>
3526
3520
 
3527
3521
  lib/core/functions/ip.md
3528
3522
  ---
@@ -3603,7 +3597,7 @@ lib/core/functions/loadEnv.md
3603
3597
 
3604
3598
  > **loadEnv**(`dir`): `Promise`\<`void`\>
3605
3599
 
3606
- Defined in: [lib/core.ts:1266](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L1266)
3600
+ Defined in: [lib/core.ts:1261](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L1261)
3607
3601
 
3608
3602
  加载 .env 文件到 process.env,若文件不存在则跳过
3609
3603
 
@@ -3673,7 +3667,7 @@ lib/core/functions/ls.md
3673
3667
 
3674
3668
  > **ls**(`opt`): `Promise`\<`object`[]\>
3675
3669
 
3676
- Defined in: [lib/core.ts:1128](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L1128)
3670
+ Defined in: [lib/core.ts:1123](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L1123)
3677
3671
 
3678
3672
  获取目录内文件/文件夹列表
3679
3673
 
@@ -4034,7 +4028,7 @@ lib/core/functions/resolveEnvVars.md
4034
4028
 
4035
4029
  > **resolveEnvVars**(`obj`): `void`
4036
4030
 
4037
- Defined in: [lib/core.ts:1296](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L1296)
4031
+ Defined in: [lib/core.ts:1291](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L1291)
4038
4032
 
4039
4033
  将配置对象中的 ${ENV_VAR} 占位符替换为 process.env 的值
4040
4034
 
@@ -4476,7 +4470,7 @@ lib/core/functions/writeEventStreamHead.md
4476
4470
 
4477
4471
  > **writeEventStreamHead**(`res`): `void`
4478
4472
 
4479
- Defined in: [lib/core.ts:1236](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L1236)
4473
+ Defined in: [lib/core.ts:1231](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L1231)
4480
4474
 
4481
4475
  ## Parameters
4482
4476
 
@@ -4501,7 +4495,7 @@ lib/core/functions/writeHead.md
4501
4495
 
4502
4496
  > **writeHead**(`res`, `statusCode`, `headers?`): `void`
4503
4497
 
4504
- Defined in: [lib/core.ts:1225](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L1225)
4498
+ Defined in: [lib/core.ts:1220](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L1220)
4505
4499
 
4506
4500
  让 res 发送头部(前提是头部没有被发送才能调用本方法
4507
4501
 
@@ -4542,7 +4536,7 @@ lib/core/functions/write.md
4542
4536
 
4543
4537
  > **write**(`res`, `data`): `void`
4544
4538
 
4545
- Defined in: [lib/core.ts:1248](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L1248)
4539
+ Defined in: [lib/core.ts:1243](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L1243)
4546
4540
 
4547
4541
  向 res 发送数据
4548
4542
 
@@ -19387,7 +19381,7 @@ lib/vector/classes/Vector.md
19387
19381
 
19388
19382
  # Class: Vector
19389
19383
 
19390
- Defined in: [lib/vector.ts:31](https://github.com/maiyunnet/kebab/blob/master/lib/vector.ts#L31)
19384
+ Defined in: [lib/vector.ts:25](https://github.com/maiyunnet/kebab/blob/master/lib/vector.ts#L25)
19391
19385
 
19392
19386
  ## Constructors
19393
19387
 
@@ -19395,7 +19389,7 @@ Defined in: [lib/vector.ts:31](https://github.com/maiyunnet/kebab/blob/master/li
19395
19389
 
19396
19390
  > **new Vector**(`etc`): `Vector`
19397
19391
 
19398
- Defined in: [lib/vector.ts:36](https://github.com/maiyunnet/kebab/blob/master/lib/vector.ts#L36)
19392
+ Defined in: [lib/vector.ts:30](https://github.com/maiyunnet/kebab/blob/master/lib/vector.ts#L30)
19399
19393
 
19400
19394
  #### Parameters
19401
19395
 
@@ -19411,9 +19405,9 @@ Defined in: [lib/vector.ts:36](https://github.com/maiyunnet/kebab/blob/master/li
19411
19405
 
19412
19406
  ### delete()
19413
19407
 
19414
- > **delete**(`data`): `Promise`\<`false` \| `MutationResult`\>
19408
+ > **delete**(`data`): `Promise`\<`false` \| \{ `deletedCount`: `number`; \}\>
19415
19409
 
19416
- Defined in: [lib/vector.ts:104](https://github.com/maiyunnet/kebab/blob/master/lib/vector.ts#L104)
19410
+ Defined in: [lib/vector.ts:116](https://github.com/maiyunnet/kebab/blob/master/lib/vector.ts#L116)
19417
19411
 
19418
19412
  删除数据
19419
19413
 
@@ -19435,15 +19429,15 @@ Defined in: [lib/vector.ts:104](https://github.com/maiyunnet/kebab/blob/master/l
19435
19429
 
19436
19430
  #### Returns
19437
19431
 
19438
- `Promise`\<`false` \| `MutationResult`\>
19432
+ `Promise`\<`false` \| \{ `deletedCount`: `number`; \}\>
19439
19433
 
19440
19434
  ***
19441
19435
 
19442
19436
  ### insert()
19443
19437
 
19444
- > **insert**(`data`): `Promise`\<`false` \| `MutationResult`\>
19438
+ > **insert**(`data`): `Promise`\<`false` \| \{ `insertCount`: `number`; `insertIds`: (`string` \| `number`)[]; \}\>
19445
19439
 
19446
- Defined in: [lib/vector.ts:79](https://github.com/maiyunnet/kebab/blob/master/lib/vector.ts#L79)
19440
+ Defined in: [lib/vector.ts:85](https://github.com/maiyunnet/kebab/blob/master/lib/vector.ts#L85)
19447
19441
 
19448
19442
  插入数据
19449
19443
 
@@ -19459,21 +19453,21 @@ Defined in: [lib/vector.ts:79](https://github.com/maiyunnet/kebab/blob/master/li
19459
19453
 
19460
19454
  ###### data
19461
19455
 
19462
- `RowData`[]
19456
+ `Record`\<`string`, `any`\>[]
19463
19457
 
19464
19458
  要插入的数据
19465
19459
 
19466
19460
  #### Returns
19467
19461
 
19468
- `Promise`\<`false` \| `MutationResult`\>
19462
+ `Promise`\<`false` \| \{ `insertCount`: `number`; `insertIds`: (`string` \| `number`)[]; \}\>
19469
19463
 
19470
19464
  ***
19471
19465
 
19472
19466
  ### seach()
19473
19467
 
19474
- > **seach**(`data`): `Promise`\<`false` \| `SearchResults`\<\{ `collection_name`: `string`; `data`: `number`[]; `filter`: `string` \| `undefined`; `limit`: `number`; `metric_type`: `"L2"` \| `"IP"` \| `"COSINE"`; `output_fields`: `string`[] \| `undefined`; \}\>\>
19468
+ > **seach**(`data`): `Promise`\<`false` \| `object`[]\>
19475
19469
 
19476
- Defined in: [lib/vector.ts:42](https://github.com/maiyunnet/kebab/blob/master/lib/vector.ts#L42)
19470
+ Defined in: [lib/vector.ts:35](https://github.com/maiyunnet/kebab/blob/master/lib/vector.ts#L35)
19477
19471
 
19478
19472
  搜索
19479
19473
 
@@ -19519,7 +19513,7 @@ Defined in: [lib/vector.ts:42](https://github.com/maiyunnet/kebab/blob/master/li
19519
19513
 
19520
19514
  #### Returns
19521
19515
 
19522
- `Promise`\<`false` \| `SearchResults`\<\{ `collection_name`: `string`; `data`: `number`[]; `filter`: `string` \| `undefined`; `limit`: `number`; `metric_type`: `"L2"` \| `"IP"` \| `"COSINE"`; `output_fields`: `string`[] \| `undefined`; \}\>\>
19516
+ `Promise`\<`false` \| `object`[]\>
19523
19517
 
19524
19518
  lib/vector/functions/get.md
19525
19519
  ---
@@ -19534,7 +19528,7 @@ lib/vector/functions/get.md
19534
19528
 
19535
19529
  > **get**(`ctrEtc`): [`Vector`](../classes/Vector.md)
19536
19530
 
19537
- Defined in: [lib/vector.ts:165](https://github.com/maiyunnet/kebab/blob/master/lib/vector.ts#L165)
19531
+ Defined in: [lib/vector.ts:152](https://github.com/maiyunnet/kebab/blob/master/lib/vector.ts#L152)
19538
19532
 
19539
19533
  创建一个 Vector 对象
19540
19534
 
@@ -19584,7 +19578,7 @@ lib/vector/interfaces/IOptions.md
19584
19578
 
19585
19579
  # Interface: IOptions
19586
19580
 
19587
- Defined in: [lib/vector.ts:18](https://github.com/maiyunnet/kebab/blob/master/lib/vector.ts#L18)
19581
+ Defined in: [lib/vector.ts:12](https://github.com/maiyunnet/kebab/blob/master/lib/vector.ts#L12)
19588
19582
 
19589
19583
  选项
19590
19584
 
@@ -19594,7 +19588,7 @@ Defined in: [lib/vector.ts:18](https://github.com/maiyunnet/kebab/blob/master/li
19594
19588
 
19595
19589
  > `optional` **host?**: `string`
19596
19590
 
19597
- Defined in: [lib/vector.ts:20](https://github.com/maiyunnet/kebab/blob/master/lib/vector.ts#L20)
19591
+ Defined in: [lib/vector.ts:14](https://github.com/maiyunnet/kebab/blob/master/lib/vector.ts#L14)
19598
19592
 
19599
19593
  主机地址
19600
19594
 
@@ -19604,7 +19598,7 @@ Defined in: [lib/vector.ts:20](https://github.com/maiyunnet/kebab/blob/master/li
19604
19598
 
19605
19599
  > `optional` **name?**: `string`
19606
19600
 
19607
- Defined in: [lib/vector.ts:24](https://github.com/maiyunnet/kebab/blob/master/lib/vector.ts#L24)
19601
+ Defined in: [lib/vector.ts:18](https://github.com/maiyunnet/kebab/blob/master/lib/vector.ts#L18)
19608
19602
 
19609
19603
  数据库名称
19610
19604
 
@@ -19614,7 +19608,7 @@ Defined in: [lib/vector.ts:24](https://github.com/maiyunnet/kebab/blob/master/li
19614
19608
 
19615
19609
  > `optional` **port?**: `number`
19616
19610
 
19617
- Defined in: [lib/vector.ts:22](https://github.com/maiyunnet/kebab/blob/master/lib/vector.ts#L22)
19611
+ Defined in: [lib/vector.ts:16](https://github.com/maiyunnet/kebab/blob/master/lib/vector.ts#L16)
19618
19612
 
19619
19613
  端口号
19620
19614
 
@@ -19624,7 +19618,7 @@ Defined in: [lib/vector.ts:22](https://github.com/maiyunnet/kebab/blob/master/li
19624
19618
 
19625
19619
  > `optional` **pwd?**: `string`
19626
19620
 
19627
- Defined in: [lib/vector.ts:28](https://github.com/maiyunnet/kebab/blob/master/lib/vector.ts#L28)
19621
+ Defined in: [lib/vector.ts:22](https://github.com/maiyunnet/kebab/blob/master/lib/vector.ts#L22)
19628
19622
 
19629
19623
  密码
19630
19624
 
@@ -19634,7 +19628,7 @@ Defined in: [lib/vector.ts:28](https://github.com/maiyunnet/kebab/blob/master/li
19634
19628
 
19635
19629
  > `optional` **user?**: `string`
19636
19630
 
19637
- Defined in: [lib/vector.ts:26](https://github.com/maiyunnet/kebab/blob/master/lib/vector.ts#L26)
19631
+ Defined in: [lib/vector.ts:20](https://github.com/maiyunnet/kebab/blob/master/lib/vector.ts#L20)
19638
19632
 
19639
19633
  用户名
19640
19634
 
package/index.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * --- 本文件用来定义每个目录实体地址的常量 ---
6
6
  */
7
7
  /** --- 当前系统版本号 --- */
8
- export declare const VER = "9.7.3";
8
+ export declare const VER = "9.9.0";
9
9
  /** --- 框架根目录,以 / 结尾 --- */
10
10
  export declare const ROOT_PATH: string;
11
11
  /** --- 框架的 LIB,以 / 结尾 --- */
package/index.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * --- 本文件用来定义每个目录实体地址的常量 ---
7
7
  */
8
8
  /** --- 当前系统版本号 --- */
9
- export const VER = '9.7.3';
9
+ export const VER = '9.9.0';
10
10
  // --- 服务端用的路径 ---
11
11
  const imu = decodeURIComponent(import.meta.url).replace('file://', '').replace(/^\/(\w:)/, '$1');
12
12
  /** --- /xxx/xxx --- */
package/lib/core.d.ts CHANGED
@@ -284,15 +284,16 @@ export declare function getLog(opt: {
284
284
  'fend'?: string;
285
285
  /** --- 仅显示被搜索到的行 --- */
286
286
  'search'?: string;
287
- /** --- 跳过的字节数,默认不跳过 --- */
288
- 'start'?: number;
289
287
  /** --- 跳过条数 --- */
290
288
  'offset'?: number;
291
289
  /** --- 最大限制,默认 100 --- */
292
290
  'limit'?: number;
293
291
  /** --- 获取局域网服务器的日志,为空代表获取本机的 --- */
294
292
  'host'?: string;
295
- }): Promise<string[][] | kebab.Json[] | null | false>;
293
+ }): Promise<{
294
+ 'list': string[][] | kebab.Json[];
295
+ 'total': number;
296
+ } | false>;
296
297
  /**
297
298
  * --- 获取目录内文件/文件夹列表 ---
298
299
  * @param opt 参数
package/lib/core.js CHANGED
@@ -929,33 +929,27 @@ export async function getLog(opt) {
929
929
  opt.host ??= '127.0.0.1';
930
930
  // --- 局域网模式 ---
931
931
  const time = lTime.stamp();
932
- const res = await lUndici.get('http://' + opt.host + ':' + globalConfig.rpcPort.toString() + '/' + lCrypto.aesEncrypt(lText.stringifyJson({
932
+ const res = await lUndici.getResponseJson('http://' + opt.host + ':' + globalConfig.rpcPort.toString() + '/' + lCrypto.aesEncrypt(lText.stringifyJson({
933
933
  'action': 'log',
934
934
  'time': time,
935
935
  'hostname': opt.hostname,
936
936
  'path': opt.path,
937
937
  'fend': opt.fend,
938
938
  'search': opt.search,
939
- 'start': opt.start,
940
939
  'offset': opt.offset,
941
940
  'limit': opt.limit,
942
941
  }), globalConfig.rpcSecret), {
943
942
  'timeout': 2
944
943
  });
945
- const content = await res.getContent();
946
- if (!content) {
947
- // --- 连接失败,系统错误 ---
948
- debug('[CORE][getLog] rpc server error');
949
- return false;
950
- }
951
- const str = content.toString();
952
- const j = lText.parseJson(str);
953
- if (!j) {
944
+ if (!res) {
954
945
  // --- 解析失败,系统错误 ---
955
946
  debug('[CORE][getLog] rpc server content error');
956
947
  return false;
957
948
  }
958
- return j.data;
949
+ return {
950
+ 'list': res.list,
951
+ 'total': res.total,
952
+ };
959
953
  }
960
954
  /**
961
955
  * --- 获取目录内文件/文件夹列表 ---
package/lib/vector.d.ts CHANGED
@@ -1,9 +1,8 @@
1
1
  /**
2
2
  * Project: Kebab, User: JianSuoQiYue
3
3
  * Date: 2025-10-28 15:18:41
4
- * Last: 2025-10-28 15:18:44
4
+ * Last: 2025-10-28 15:18:44, 2026-5-20 23:31:45
5
5
  */
6
- import * as milvus from '@zilliz/milvus2-sdk-node';
7
6
  import * as kebab from '#kebab/index.js';
8
7
  import * as sCtr from '#kebab/sys/ctr.js';
9
8
  /** --- 选项 --- */
@@ -37,32 +36,30 @@ export declare class Vector {
37
36
  'metric'?: 'L2' | 'IP' | 'COSINE';
38
37
  /** --- 输出的字段,如 ['book_id', 'word_count'],默认全部 --- */
39
38
  'fields'?: string[];
40
- }): Promise<false | milvus.SearchResults<{
41
- collection_name: string;
42
- data: number[];
43
- filter: string | undefined;
44
- limit: number;
45
- metric_type: "L2" | "IP" | "COSINE";
46
- output_fields: string[] | undefined;
47
- }>>;
39
+ }): Promise<Array<{
40
+ 'id': string | number;
41
+ 'distance': number;
42
+ 'entity': Record<string, kebab.Json>;
43
+ }> | false>;
48
44
  /** --- 插入数据 --- */
49
45
  insert(data: {
50
46
  /** --- 表名 --- */
51
47
  'collection': string;
52
48
  /** --- 要插入的数据 --- */
53
- 'data': milvus.RowData[];
54
- }): Promise<milvus.MutationResult | false>;
49
+ 'data': Array<Record<string, kebab.Json>>;
50
+ }): Promise<{
51
+ 'insertCount': number;
52
+ 'insertIds': Array<string | number>;
53
+ } | false>;
55
54
  /** --- 删除数据 --- */
56
55
  delete(data: {
57
56
  /** --- 表名 --- */
58
57
  'collection': string;
59
58
  /** --- 过滤器,如 word_count > 0 and book_id in [1, 2, 3] --- */
60
59
  'filter': string;
61
- }): Promise<milvus.MutationResult | false>;
62
- /**
63
- * --- 从连接池中获取一个符合要求的连接 ---
64
- */
65
- private _getConnection;
60
+ }): Promise<{
61
+ 'deletedCount': number;
62
+ } | false>;
66
63
  }
67
64
  /**
68
65
  * --- 创建一个 Vector 对象 ---
package/lib/vector.js CHANGED
@@ -1,13 +1,6 @@
1
- /**
2
- * Project: Kebab, User: JianSuoQiYue
3
- * Date: 2025-10-28 15:18:41
4
- * Last: 2025-10-28 15:18:44
5
- */
6
- import * as milvus from '@zilliz/milvus2-sdk-node';
7
1
  import * as lCore from '#kebab/lib/core.js';
2
+ import * as lUndici from '#kebab/lib/undici.js';
8
3
  import * as sCtr from '#kebab/sys/ctr.js';
9
- /** --- milvus 的连接对象 --- */
10
- const links = [];
11
4
  export class Vector {
12
5
  /** --- 当前的 vector 连接信息 --- */
13
6
  _etc;
@@ -15,97 +8,79 @@ export class Vector {
15
8
  this._etc = etc;
16
9
  }
17
10
  /** --- 搜索 --- */
18
- // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
19
11
  async seach(data) {
20
- const link = await this._getConnection();
21
- if (!link) {
22
- return false;
12
+ const body = {
13
+ 'dbName': this._etc.name,
14
+ 'collectionName': data.collection,
15
+ 'data': [data.data],
16
+ 'limit': data.limit ?? 3,
17
+ 'searchParams': {
18
+ 'metricType': data.metric ?? 'L2',
19
+ },
20
+ };
21
+ if (data.filter) {
22
+ body['filter'] = data.filter;
23
+ }
24
+ if (data.fields) {
25
+ body['outputFields'] = data.fields;
23
26
  }
24
27
  try {
25
- const res = await link.search({
26
- 'collection_name': data.collection,
27
- 'data': data.data,
28
- 'filter': data.filter,
29
- 'limit': data.limit ?? 3,
30
- 'metric_type': data.metric ?? 'L2',
31
- 'output_fields': data.fields,
32
- });
33
- return res;
28
+ const res = await lUndici.postJsonResponseJson(`http://${this._etc.host}:${this._etc.port}/v2/vectordb/entities/search`, body, { 'headers': { 'Authorization': `Bearer ${this._etc.user}:${this._etc.pwd}` } });
29
+ if (res?.code !== 0) {
30
+ lCore.log({}, '[VECTOR][seach][error] ' + (res?.message ?? ''), '-error');
31
+ lCore.debug('[VECTOR][seach]', res);
32
+ return false;
33
+ }
34
+ return res.data;
34
35
  }
35
36
  catch (e) {
36
- lCore.log({}, '[VECTOR][seach][error] ' + (e.status?.reason ?? ''), '-error');
37
+ lCore.log({}, '[VECTOR][seach][error] ' + e.message, '-error');
37
38
  lCore.debug('[VECTOR][seach]', e);
38
39
  return false;
39
40
  }
40
41
  }
41
42
  /** --- 插入数据 --- */
42
43
  async insert(data) {
43
- const link = await this._getConnection();
44
- if (!link) {
45
- return false;
46
- }
47
44
  try {
48
- const res = await link.insert({
49
- 'collection_name': data.collection,
45
+ const res = await lUndici.postJsonResponseJson(`http://${this._etc.host}:${this._etc.port}/v2/vectordb/entities/insert`, {
46
+ 'dbName': this._etc.name,
47
+ 'collectionName': data.collection,
50
48
  'data': data.data,
51
- });
52
- return res;
49
+ }, { 'headers': { 'Authorization': `Bearer ${this._etc.user}:${this._etc.pwd}` } });
50
+ if (res?.code !== 0) {
51
+ lCore.log({}, '[VECTOR][insert][error] ' + (res?.message ?? ''), '-error');
52
+ lCore.debug('[VECTOR][insert]', res);
53
+ return false;
54
+ }
55
+ return res.data;
53
56
  }
54
57
  catch (e) {
55
- lCore.log({}, '[VECTOR][insert][error] ' + (e.status?.reason ?? ''), '-error');
58
+ lCore.log({}, '[VECTOR][insert][error] ' + e.message, '-error');
56
59
  lCore.debug('[VECTOR][insert]', e);
57
60
  return false;
58
61
  }
59
62
  }
60
63
  /** --- 删除数据 --- */
61
64
  async delete(data) {
62
- const link = await this._getConnection();
63
- if (!link) {
64
- return false;
65
- }
66
65
  try {
67
- const res = await link.delete({
68
- 'collection_name': data.collection,
66
+ const res = await lUndici.postJson(`http://${this._etc.host}:${this._etc.port}/v2/vectordb/entities/delete`, {
67
+ 'dbName': this._etc.name,
68
+ 'collectionName': data.collection,
69
69
  'filter': data.filter,
70
- });
71
- return res;
70
+ }, { 'headers': { 'Authorization': `Bearer ${this._etc.user}:${this._etc.pwd}` } });
71
+ const json = await res.getJson();
72
+ if (json?.code !== 0) {
73
+ lCore.log({}, '[VECTOR][delete][error] ' + (json?.message ?? ''), '-error');
74
+ return false;
75
+ }
76
+ return json.data;
72
77
  }
73
78
  catch (e) {
74
- lCore.log({}, '[VECTOR][delete][error] ' + (e.status?.reason ?? ''), '-error');
79
+ lCore.log({}, '[VECTOR][delete][error] ' + e.message, '-error');
75
80
  lCore.debug('[VECTOR][delete]', e);
76
81
  return false;
77
82
  }
78
83
  }
79
- /**
80
- * --- 从连接池中获取一个符合要求的连接 ---
81
- */
82
- async _getConnection() {
83
- const token = `${this._etc.host}-${this._etc.port}-${this._etc.name}-${this._etc.user}`;
84
- const item = links.find(item => item.token === token);
85
- if (item) {
86
- return item.link;
87
- }
88
- // --- 没有找到合适的连接,创建一个 ---
89
- try {
90
- const link = new milvus.MilvusClient({
91
- 'address': `${this._etc.host}:${this._etc.port}`,
92
- 'ssl': false,
93
- 'database': this._etc.name,
94
- 'username': this._etc.user,
95
- 'password': this._etc.pwd,
96
- });
97
- await link.connectPromise;
98
- links.push({
99
- 'token': token,
100
- link,
101
- });
102
- return link;
103
- }
104
- catch (e) {
105
- lCore.debug('[VECTOR][_getConnection]', e.code, e.message);
106
- return null;
107
- }
108
- }
109
84
  }
110
85
  /**
111
86
  * --- 创建一个 Vector 对象 ---
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maiyunnet/kebab",
3
- "version": "9.7.3",
3
+ "version": "9.9.0",
4
4
  "description": "Simple, easy-to-use, and fully-featured Node.js framework that is ready-to-use out of the box.",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -34,7 +34,6 @@
34
34
  "@radix-ui/react-switch": "^1.2.6",
35
35
  "@tailwindcss/cli": "^4.3.0",
36
36
  "@types/ssh2": "^1.15.5",
37
- "@zilliz/milvus2-sdk-node": "^3.0.0",
38
37
  "ajv": "^8.20.0",
39
38
  "ajv-formats": "^3.0.1",
40
39
  "class-variance-authority": "^0.7.1",
package/sys/master.js CHANGED
@@ -519,10 +519,52 @@ function createRpcListener() {
519
519
  }));
520
520
  return;
521
521
  }
522
+ // --- 用 wc -l 高效获取总行数 ---
523
+ let total = 0;
524
+ const wclRtn = await lCore.exec(`wc -l "${path}"`);
525
+ if (wclRtn !== false) {
526
+ const wclMatch = /^\s*(\d+)/.exec(wclRtn);
527
+ if (wclMatch) {
528
+ total = parseInt(wclMatch[1]);
529
+ if (format === 'csv') {
530
+ // --- csv 有表头,数据行数减 1 ---
531
+ total = Math.max(0, total - 1);
532
+ }
533
+ }
534
+ }
522
535
  /** --- 剩余 limit --- */
523
536
  let limit = msg.limit ?? 100;
524
- /** --- 剩余 offset --- */
525
- let offset = msg.offset ?? 0;
537
+ /** --- offset --- */
538
+ const offset = msg.offset ?? 0;
539
+ /**
540
+ * --- 用 grep -b '^' 获取目标行的字节偏移,直接传给 createReadStream start 跳过 offset ---
541
+ * --- jsonl 无表头:跳过 offset 行,从第 offset+1 行开始读 ---
542
+ * --- csv 有表头:跳过表头+offset 行,从第 offset+2 行开始读 ---
543
+ */
544
+ let startByte = 0;
545
+ /** --- offset 定位是否成功(offset=0 直接成功;offset>0 需 grep 定位)--- */
546
+ let offsetLocated = offset === 0;
547
+ if (offset > 0) {
548
+ const skipLines = format === 'jsonl' ? offset : offset + 1;
549
+ // --- sed -n '${N}{p;q}' 找到第 N 行后立即退出,使 grep 收到 SIGPIPE 提前终止 ---
550
+ const grepRtn = await lCore.exec(`grep -b '^' "${path}" | sed -n '${skipLines + 1}{p;q}'`);
551
+ if (grepRtn !== false) {
552
+ const grepMatch = /^(\d+):/.exec(grepRtn.trim());
553
+ if (grepMatch) {
554
+ startByte = parseInt(grepMatch[1]);
555
+ offsetLocated = true;
556
+ }
557
+ }
558
+ }
559
+ if (!offsetLocated) {
560
+ // --- offset 超出文件范围,返回空列表 ---
561
+ res.end(lText.stringifyJson({
562
+ 'result': 1,
563
+ 'data': [],
564
+ 'total': total,
565
+ }));
566
+ return;
567
+ }
526
568
  /**
527
569
  * --- csv 格式:string[][] 每行是字段数组,顺序与表头一致 ---
528
570
  * --- [['H:i:s', unix, url, cookie, session, userAgent, realIp, cfIp, xIp, osMem, procMem, message], ...] ---
@@ -531,14 +573,14 @@ function createRpcListener() {
531
573
  */
532
574
  const rtn = await new Promise(resolve => {
533
575
  const list = [];
534
- /** --- 当前行号(jsonl 无表头,csv 有表头,两者处理逻辑不同)--- */
576
+ /** --- 当前行号 --- */
535
577
  let line = 0;
536
578
  /** --- 当前行数据 --- */
537
579
  let packet = '';
538
580
  lFs.createReadStream(path, {
539
581
  'encoding': 'utf8',
540
- 'start': msg.start,
541
- }).on('data', (buf) => {
582
+ 'start': startByte,
583
+ }).on('data', buf => {
542
584
  if (typeof buf !== 'string') {
543
585
  return;
544
586
  }
@@ -557,50 +599,45 @@ function createRpcListener() {
557
599
  packet += buf.slice(0, index);
558
600
  buf = buf.slice(index + 1);
559
601
  ++line;
560
- // --- 先执行下本次完成的 ---
561
- // --- csv:line > 1 跳过表头行;jsonl:无表头,line >= 1 即可处理 ---
562
- if (format === 'jsonl' ? line >= 1 : line > 1) {
563
- if (offset === 0) {
564
- if (!msg.search || packet.includes(msg.search)) {
565
- if (format === 'jsonl') {
566
- const obj = lText.parseJson(packet);
567
- if (obj) {
568
- list.push(obj);
569
- --limit;
570
- }
602
+ // --- startByte > 0 时已跳过 offset(及 csv 表头),从第一行起均为数据行 ---
603
+ // --- startByte === 0 且 csv 时仍需跳过表头(line > 1)---
604
+ if (format === 'csv' && startByte === 0 ? line > 1 : line >= 1) {
605
+ if (!msg.search || packet.includes(msg.search)) {
606
+ if (format === 'jsonl') {
607
+ const obj = lText.parseJson(packet);
608
+ if (obj) {
609
+ list.push(obj);
610
+ --limit;
571
611
  }
572
- else {
573
- const result = [];
574
- let currentField = '';
575
- let inQuotes = false;
576
- for (let i = 0; i < packet.length; ++i) {
577
- const char = packet[i];
578
- if (char === '"') {
579
- if (inQuotes && packet[i + 1] === '"') {
580
- currentField += '"';
581
- ++i;
582
- }
583
- else {
584
- inQuotes = !inQuotes;
585
- }
586
- }
587
- else if (char === ',' && !inQuotes) {
588
- result.push(currentField);
589
- currentField = '';
612
+ }
613
+ else {
614
+ const result = [];
615
+ let currentField = '';
616
+ let inQuotes = false;
617
+ for (let i = 0; i < packet.length; ++i) {
618
+ const char = packet[i];
619
+ if (char === '"') {
620
+ if (inQuotes && packet[i + 1] === '"') {
621
+ currentField += '"';
622
+ ++i;
590
623
  }
591
624
  else {
592
- currentField += char;
625
+ inQuotes = !inQuotes;
593
626
  }
594
627
  }
595
- result.push(currentField);
596
- list.push(result);
597
- --limit;
628
+ else if (char === ',' && !inQuotes) {
629
+ result.push(currentField);
630
+ currentField = '';
631
+ }
632
+ else {
633
+ currentField += char;
634
+ }
598
635
  }
636
+ result.push(currentField);
637
+ list.push(result);
638
+ --limit;
599
639
  }
600
640
  }
601
- else {
602
- --offset;
603
- }
604
641
  }
605
642
  // --- 处理结束 ---
606
643
  packet = '';
@@ -619,7 +656,8 @@ function createRpcListener() {
619
656
  });
620
657
  res.end(lText.stringifyJson({
621
658
  'result': 1,
622
- 'data': rtn,
659
+ 'list': rtn,
660
+ 'total': total,
623
661
  }));
624
662
  return;
625
663
  }
@@ -1387,16 +1387,16 @@ for (let i = 0; i < 30000; ++i) {
1387
1387
  }
1388
1388
  async coreGetlog() {
1389
1389
  const path = lTime.format(null, 'Y/m/d/H');
1390
- const list = await lCore.getLog({
1390
+ const log = await lCore.getLog({
1391
1391
  'hostname': this._config.const.hostname,
1392
1392
  'path': path,
1393
1393
  'fend': '-visit',
1394
1394
  });
1395
1395
  const echo = [];
1396
- echo.push('<table style="width: 100%;">');
1397
- if (list) {
1396
+ echo.push(`total: ${log ? log.total : 0}<br><table style="width: 100%;">`);
1397
+ if (log) {
1398
1398
  echo.push('<tr><th>TIME</th><th>UNIX</th><th>URL</th><th>COOKIE</th><th>SESSION</th><th>USER_AGENT</th><th>REALIP</th><th>CFIP</th><th>XIP</th><th>OS</th><th>PROCESS</th><th>MESSAGE</th></tr>');
1399
- for (const row of list) {
1399
+ for (const row of log.list) {
1400
1400
  echo.push('<tr>');
1401
1401
  if (Array.isArray(row)) {
1402
1402
  // --- csv 格式:string[] ---
@@ -1418,7 +1418,7 @@ for (let i = 0; i < 30000; ++i) {
1418
1418
  }
1419
1419
  }
1420
1420
  else {
1421
- echo.push('<tr><th>' + JSON.stringify(list) + '</th></tr>');
1421
+ echo.push('<tr><th>' + JSON.stringify(log) + '</th></tr>');
1422
1422
  }
1423
1423
  echo.push('</table>');
1424
1424
  return echo.join('') + '<br>' + this._getEnd();
@@ -1729,7 +1729,7 @@ exec: ${JSON.stringify(exec)}<br><br>`);
1729
1729
  async vector() {
1730
1730
  const vector = lVector.get(this);
1731
1731
  const res = await vector.seach({
1732
- 'collection': 'oas_wiki',
1732
+ 'collection': 'ai_wiki_content',
1733
1733
  'metric': 'COSINE',
1734
1734
  'data': [0.4100031323819555, 0.7188991736586672, 0.32890290245747833, 0.9187961849628559, 0.023142186415922916, 0.45239563148580797, 0.23537591588175988, 0.6848990771759962, 0.9865744633216178, 0.8239142304110896, 0.997768380245414, 0.3012929412655765, 0.13731236076734943, 0.5126131685642945, 0.9806290097015617, 0.1870468071764284, 0.17178642706602143, 0.4016660911946244, 0.15484433366942607, 0.29719222215610386, 0.3103748731148619, 0.6892950176658315, 0.01785695346759608, 0.08539564964986557, 0.2655959514380064, 0.9964617086704073, 0.2838371937684081, 0.14987010598298633, 0.6228479079557896, 0.8080833516756243, 0.15438562173495285, 0.5078008662168574, 0.27262149922940804, 0.23104911473240675, 0.6266656488428926, 0.8553958245035254, 0.11699454830789868, 0.2300336351244865, 0.3042943975707315, 0.20182231286864427, 0.14334825938359863, 0.5272057735967806, 0.6568390179350452, 0.11388912236667226, 0.4916225414998463, 0.4913046496135085, 0.6301252401085475, 0.26051075673874036, 0.17023441587522825, 0.371755148312803, 0.5831318953846139, 0.9756820442368113, 0.6818893859710211, 0.5188330204766185, 0.7868335112863099, 0.7263293211859105, 0.15777067513918275, 0.25071428052177835, 0.9055952502390328, 0.39066574162485046, 0.6694768856781026, 0.904527206408617, 0.5359679189729842, 0.42923033393177423, 0.6959492373261136, 0.4721197667950616, 0.6861043448179791, 0.05188999799541438, 0.7346607591003518, 0.1574483630625012, 0.9141756884547747, 0.9116789303557802, 0.7609450526832306, 0.7763073356227885, 0.7334996162535046, 0.8036447394427264, 0.21291521237560262, 0.4628513517221038, 0.005054981316060525, 0.6289756103407573, 0.9376033918403373, 0.79713161153396, 0.1795021378890418, 0.32421299215073773, 0.5585715705291334, 0.1964507020528392, 0.9170965358836494, 0.44199069294404825, 0.46924875851341463, 0.005915168915280544, 0.4519648598811945, 0.7817208441823769, 0.39630447274483926, 0.874803477246406, 0.02593537985516514, 0.03494415508402371, 0.6948556600612117, 0.02531235612016558, 0.3252859275909026, 0.6124602304575255, 0.6662991517754546, 0.054786469959723805, 0.09541281916656552, 0.047971618444194286, 0.9888851535738363, 0.09923862294731634, 0.37389883211204245, 0.0510449762242422, 0.5140187522339308, 0.9165108670272317, 0.473682888066292, 0.7553395418192084, 0.48450479101753663, 0.22080081972551513, 0.8461012374988566, 0.32711442729081885, 0.46740436391036244, 0.9330234279632854, 0.7456194346850014, 0.8575560505025164, 0.2617623984893922, 0.6418053194775086, 0.607749877895083, 0.2176063100000032, 0.5366633111896186, 0.9689538808794083, 0.8226310778269623, 0.4813948057818185]
1735
1735
  });