@customize-agent/knowledge 4.1.4 → 4.1.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.
@@ -140,6 +140,11 @@ export declare class IndexStateStore {
140
140
  collectionName?: string;
141
141
  relativePath?: string;
142
142
  }): number;
143
+ listChunksSampled(options?: {
144
+ collectionName?: string;
145
+ relativePath?: string;
146
+ sampleSize?: number;
147
+ }): StoredChunk[];
143
148
  listChunksByContentBudget(options?: {
144
149
  collectionName?: string;
145
150
  relativePath?: string;
@@ -216,6 +216,23 @@ export class IndexStateStore {
216
216
  const row = this.db.prepare(`SELECT COUNT(*) AS count FROM kb_chunks ${where}`).get(...params);
217
217
  return Number(row?.count || 0);
218
218
  }
219
+ // 均匀步长取样:对超长文件按 chunk_index 取模抽样并强制含最后一块,
220
+ // 避免 listChunks 前缀取样导致的文件中部/尾部关键信息(工期、质量标准等)覆盖缺失
221
+ listChunksSampled(options = {}) {
222
+ const sampleSize = Number(options.sampleSize) || 32;
223
+ const total = this.countChunks(options);
224
+ if (total <= sampleSize)
225
+ return this.listChunks(options);
226
+ const step = Math.ceil(total / sampleSize);
227
+ const { where, params } = this.chunkQueryParts(options);
228
+ const whereClause = where ? `${where} AND` : 'WHERE';
229
+ const rows = this.db.prepare(`
230
+ SELECT rowid, * FROM kb_chunks
231
+ ${whereClause} (chunk_index % ? = 0 OR chunk_index = ?)
232
+ ORDER BY relative_path, chunk_index
233
+ `).all(...params, step, total - 1);
234
+ return rows.map(row => this.rowToChunk(row, 0));
235
+ }
219
236
  listChunksByContentBudget(options = {}) {
220
237
  const maxContentChars = Number(options.maxContentChars);
221
238
  if (!Number.isFinite(maxContentChars) || maxContentChars <= 0)
@@ -92,6 +92,10 @@ export declare class KnowledgeBaseManager {
92
92
  relativePath?: string;
93
93
  limit?: number;
94
94
  }): StoredChunk[];
95
+ listChunksSampled(options?: {
96
+ relativePath?: string;
97
+ sampleSize?: number;
98
+ }): StoredChunk[];
95
99
  getFileDetail(relativePath: string, options?: {
96
100
  maxChunkContentChars?: number;
97
101
  }): {
@@ -519,6 +519,9 @@ export class KnowledgeBaseManager {
519
519
  listChunks(options = {}) {
520
520
  return this.store.listChunks(options);
521
521
  }
522
+ listChunksSampled(options = {}) {
523
+ return this.store.listChunksSampled(options);
524
+ }
522
525
  getFileDetail(relativePath, options = {}) {
523
526
  const normalized = this.normalizeRelativePath(relativePath);
524
527
  const file = this.store.listRecords().find(record => record.relativePath === normalized);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@customize-agent/knowledge",
3
- "version": "4.1.4",
3
+ "version": "4.1.5",
4
4
  "description": "Local knowledge base infrastructure for customize-agent",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",