@customize-agent/knowledge 4.0.3 → 4.0.5

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.
@@ -94,7 +94,10 @@ export declare class KnowledgeBaseManager {
94
94
  createdAt: number;
95
95
  }[];
96
96
  } | undefined;
97
- reindexFile(relativePath: string): Promise<DiffResult>;
97
+ reindexFile(relativePath: string, options?: {
98
+ onProgress?: (progress: KnowledgeIndexProgress) => void;
99
+ vectorMode?: 'sync' | 'defer';
100
+ }): Promise<DiffResult>;
98
101
  addFile(sourcePath: string, targetRelativePath?: string): Promise<DiffResult>;
99
102
  getUploadRelativePath(fileName: string, targetRelativePath?: string): string;
100
103
  uploadFile(fileName: string, content: Buffer, targetRelativePath?: string, onProgress?: (progress: KnowledgeIndexProgress) => void, options?: {
@@ -396,7 +396,7 @@ export class KnowledgeBaseManager {
396
396
  tags: this.store.listTags(normalized),
397
397
  };
398
398
  }
399
- async reindexFile(relativePath) {
399
+ async reindexFile(relativePath, options = {}) {
400
400
  const normalized = this.normalizeRelativePath(relativePath);
401
401
  const record = this.store.listRecords().find(item => item.relativePath === normalized);
402
402
  const targetPath = this.resolveKbRelativePath(normalized);
@@ -405,7 +405,7 @@ export class KnowledgeBaseManager {
405
405
  if (record)
406
406
  await this.deleteVectorFile(record.collectionName, normalized);
407
407
  this.store.deleteRecord(normalized);
408
- return this.incrementalIndex();
408
+ return this.incrementalIndex({ ...options, onlyRelativePaths: [normalized] });
409
409
  }
410
410
  async addFile(sourcePath, targetRelativePath) {
411
411
  this.initialize();
@@ -496,10 +496,14 @@ export class KnowledgeBaseManager {
496
496
  }
497
497
  this.reportProgress({ stage: 'vectorizing', percent: 85, message: `正在写入 HNSWLib 向量库,共 ${chunks.length} 个切片`, chunkCount: chunks.length });
498
498
  const indexer = new VectorIndexer(this.embeddingProvider, this.vectorStores);
499
+ let lastVectorPercent = -1;
499
500
  try {
500
501
  const results = await indexer.indexChunks(chunks, {
501
502
  onProgress: progress => {
502
503
  const percent = 85 + Math.round((progress.processedChunks / Math.max(1, progress.totalChunks)) * 14);
504
+ if (percent === lastVectorPercent && progress.processedChunks < progress.totalChunks)
505
+ return;
506
+ lastVectorPercent = percent;
503
507
  const message = `正在分批向量化并写入:${progress.processedChunks}/${progress.totalChunks} 个切片`;
504
508
  this.reportProgress({ stage: 'vectorizing', percent, message, chunkCount: progress.totalChunks });
505
509
  if (options.relativePath)
@@ -1,8 +1,8 @@
1
1
  function resolveVectorIndexBatchSize(configured) {
2
2
  const raw = configured ?? Number(process.env.CUSTOMIZE_VECTOR_INDEX_BATCH_SIZE ?? process.env.KB_VECTOR_INDEX_BATCH_SIZE);
3
3
  if (!Number.isFinite(raw) || raw <= 0)
4
- return 32;
5
- return Math.max(1, Math.min(256, Math.floor(raw)));
4
+ return 128;
5
+ return Math.max(1, Math.min(512, Math.floor(raw)));
6
6
  }
7
7
  /** 向量索引器,负责将文本切片生成 Embedding 并写入向量存储 */
8
8
  export class VectorIndexer {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@customize-agent/knowledge",
3
- "version": "4.0.3",
3
+ "version": "4.0.5",
4
4
  "description": "Local knowledge base infrastructure for customize-agent",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -12,14 +12,6 @@
12
12
  "default": "./dist/index.js"
13
13
  }
14
14
  },
15
- "scripts": {
16
- "prebuild": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
17
- "build": "tsc",
18
- "typecheck": "tsc --noEmit",
19
- "lint": "eslint src/",
20
- "postinstall": "node scripts/install-hnsw.cjs",
21
- "doctor:hnsw": "node scripts/install-hnsw.cjs"
22
- },
23
15
  "license": "MIT",
24
16
  "engines": {
25
17
  "node": ">=22.13.0"
@@ -64,5 +56,13 @@
64
56
  "devDependencies": {
65
57
  "@types/better-sqlite3": "^7.6.13",
66
58
  "@types/node": "^25.9.3"
59
+ },
60
+ "scripts": {
61
+ "prebuild": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
62
+ "build": "tsc",
63
+ "typecheck": "tsc --noEmit",
64
+ "lint": "eslint src/",
65
+ "postinstall": "node scripts/install-hnsw.cjs",
66
+ "doctor:hnsw": "node scripts/install-hnsw.cjs"
67
67
  }
68
- }
68
+ }