@chiway/contextweaver 1.1.0 → 1.4.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/dist/{SearchService-MYPOCM3B.js → SearchService-OS7CYHNJ.js} +58 -12
- package/dist/{chunk-6QMYML5V.js → chunk-AB24E3Z7.js} +399 -277
- package/dist/{chunk-7G5V7YT5.js → chunk-EMSMLPMK.js} +6 -7
- package/dist/{chunk-AMQQK4P7.js → chunk-JVKVSTQ3.js} +1 -2
- package/dist/{chunk-6Z4JEEVJ.js → chunk-RGJSXUFS.js} +243 -58
- package/dist/{chunk-RJURH22T.js → chunk-SKBAE26T.js} +0 -1
- package/dist/{chunk-NQR4CGQ6.js → chunk-X7PAYQMT.js} +40 -10
- package/dist/chunk-ZOMGPIU6.js +377 -0
- package/dist/codebaseRetrieval-3Z4CRA7X.js +11 -0
- package/dist/{config-BWZ6CU3W.js → config-LCOJHTCF.js} +1 -2
- package/dist/db-PMVM7557.js +54 -0
- package/dist/index.js +37 -9
- package/dist/{lock-DVY3KJSK.js → lock-FL54LIQL.js} +2 -3
- package/dist/scanner-2XGJWYHR.js +11 -0
- package/dist/{server-27HI7WZO.js → server-XK6EINRV.js} +4 -5
- package/dist/vectorStore-HPQZOVWF.js +12 -0
- package/package.json +1 -1
- package/dist/codebaseRetrieval-NLAMGOA2.js +0 -12
- package/dist/scanner-RFG4YWYI.js +0 -11
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
+
ChunkContentLoader,
|
|
3
|
+
bootstrap,
|
|
2
4
|
getGraphExpander,
|
|
3
5
|
getIndexer,
|
|
4
|
-
getVectorStore,
|
|
5
6
|
scoreChunkTokenOverlap
|
|
6
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-AB24E3Z7.js";
|
|
8
|
+
import {
|
|
9
|
+
getVectorStore
|
|
10
|
+
} from "./chunk-ZOMGPIU6.js";
|
|
7
11
|
import {
|
|
8
12
|
initDb,
|
|
9
13
|
isChunksFtsInitialized,
|
|
@@ -11,15 +15,15 @@ import {
|
|
|
11
15
|
searchChunksFts,
|
|
12
16
|
searchFilesFts,
|
|
13
17
|
segmentQuery
|
|
14
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-RGJSXUFS.js";
|
|
15
19
|
import {
|
|
16
20
|
isDebugEnabled,
|
|
17
21
|
logger
|
|
18
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-JVKVSTQ3.js";
|
|
19
23
|
import {
|
|
20
24
|
getEmbeddingConfig,
|
|
21
25
|
getRerankerConfig
|
|
22
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-SKBAE26T.js";
|
|
23
27
|
|
|
24
28
|
// src/api/reranker.ts
|
|
25
29
|
var RerankerClient = class {
|
|
@@ -350,6 +354,12 @@ var SearchService = class {
|
|
|
350
354
|
this.indexer = await getIndexer(this.projectId, embeddingConfig.dimensions);
|
|
351
355
|
this.vectorStore = await getVectorStore(this.projectId, embeddingConfig.dimensions);
|
|
352
356
|
this.db = initDb(this.projectId);
|
|
357
|
+
try {
|
|
358
|
+
await bootstrap(this.db, this.vectorStore);
|
|
359
|
+
} catch (err) {
|
|
360
|
+
const error = err;
|
|
361
|
+
logger.warn({ error: error.message }, "bootstrap \u5931\u8D25\uFF0C\u7EE7\u7EED\u542F\u52A8");
|
|
362
|
+
}
|
|
353
363
|
}
|
|
354
364
|
// 公开接口
|
|
355
365
|
/**
|
|
@@ -517,6 +527,20 @@ var SearchService = class {
|
|
|
517
527
|
const allFilePaths = fileResults.map((r) => r.path);
|
|
518
528
|
const chunksMap = await this.vectorStore?.getFilesChunks(allFilePaths);
|
|
519
529
|
if (!chunksMap) return [];
|
|
530
|
+
const allChunkSlices = [];
|
|
531
|
+
for (const filePath of allFilePaths) {
|
|
532
|
+
const chunks = chunksMap.get(filePath);
|
|
533
|
+
if (!chunks) continue;
|
|
534
|
+
for (const c of chunks) {
|
|
535
|
+
allChunkSlices.push({
|
|
536
|
+
filePath: c.file_path,
|
|
537
|
+
start_index: c.start_index,
|
|
538
|
+
end_index: c.end_index
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
const contentLoader = new ChunkContentLoader(this.db);
|
|
543
|
+
const codeMap = contentLoader.loadMany(allChunkSlices);
|
|
520
544
|
const allChunks = [];
|
|
521
545
|
let totalChunks = 0;
|
|
522
546
|
let skippedFiles = 0;
|
|
@@ -524,10 +548,19 @@ var SearchService = class {
|
|
|
524
548
|
if (totalChunks >= this.config.lexTotalChunks) break;
|
|
525
549
|
const chunks = chunksMap.get(filePath);
|
|
526
550
|
if (!chunks || chunks.length === 0) continue;
|
|
527
|
-
const scoredChunks = chunks.map((chunk) =>
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
551
|
+
const scoredChunks = chunks.map((chunk) => {
|
|
552
|
+
const code = codeMap.get(
|
|
553
|
+
ChunkContentLoader.key({
|
|
554
|
+
filePath: chunk.file_path,
|
|
555
|
+
start_index: chunk.start_index,
|
|
556
|
+
end_index: chunk.end_index
|
|
557
|
+
})
|
|
558
|
+
) ?? "";
|
|
559
|
+
return {
|
|
560
|
+
chunk,
|
|
561
|
+
overlapScore: scoreChunkTokenOverlap(chunk, code, queryTokens)
|
|
562
|
+
};
|
|
563
|
+
});
|
|
531
564
|
const maxOverlap = Math.max(...scoredChunks.map((c) => c.overlapScore));
|
|
532
565
|
if (maxOverlap === 0) {
|
|
533
566
|
skippedFiles++;
|
|
@@ -647,12 +680,26 @@ var SearchService = class {
|
|
|
647
680
|
return candidates;
|
|
648
681
|
}
|
|
649
682
|
const queryTokens = this.extractQueryTokens(query);
|
|
683
|
+
const loader = new ChunkContentLoader(this.db);
|
|
684
|
+
const codeMap = loader.loadMany(
|
|
685
|
+
candidates.map((c) => ({
|
|
686
|
+
filePath: c.filePath,
|
|
687
|
+
start_index: c.record.start_index,
|
|
688
|
+
end_index: c.record.end_index
|
|
689
|
+
}))
|
|
690
|
+
);
|
|
650
691
|
const textExtractor = (chunk) => {
|
|
651
692
|
const bc = this.truncateMiddle(chunk.record.breadcrumb, this.config.maxBreadcrumbChars);
|
|
693
|
+
const key = ChunkContentLoader.key({
|
|
694
|
+
filePath: chunk.filePath,
|
|
695
|
+
start_index: chunk.record.start_index,
|
|
696
|
+
end_index: chunk.record.end_index
|
|
697
|
+
});
|
|
698
|
+
const code = codeMap.get(key) ?? "";
|
|
652
699
|
const budget = Math.max(0, this.config.maxRerankChars - bc.length - 1);
|
|
653
|
-
const
|
|
700
|
+
const trimmed = this.extractAroundHit(code, queryTokens, budget);
|
|
654
701
|
return `${bc}
|
|
655
|
-
${
|
|
702
|
+
${trimmed}`;
|
|
656
703
|
};
|
|
657
704
|
try {
|
|
658
705
|
const reranked = await reranker.rerankWithData(query, candidates, textExtractor, {
|
|
@@ -883,4 +930,3 @@ ${code}`;
|
|
|
883
930
|
export {
|
|
884
931
|
SearchService
|
|
885
932
|
};
|
|
886
|
-
//# sourceMappingURL=SearchService-MYPOCM3B.js.map
|