LLM Wiki is a cross-platform desktop application that turns your documents into an organized, interlinked knowledge base — automatically. Instead of traditional RAG (retrieve-and-answer from scratch every time), the LLM incrementally builds and maintains a persistent wiki from your sources。
TypeScript
fix: batch large duplicate scans
nash_su714b33d26183
diff --git a/src/lib/dedup-runner.test.ts b/src/lib/dedup-runner.test.tsindex 29d2b9e1..286f0c63 100644--- a/src/lib/dedup-runner.test.ts+++ b/src/lib/dedup-runner.test.ts@@ -300,6 +300,26 @@ describe("runDuplicateDetection embedding prefilter", () => {expect(mockStreamChat).not.toHaveBeenCalled()})+ it("bounds every LLM request when a large wiki has no embedding prefilter", async () => {+ setupLargeProject(170)+ mockLoadNotDuplicates.mockResolvedValue([])+ setupEmbeddingConfig(false)+ mockStreamChat.mockImplementation(async (_c, _m, cb) => {+ cb.onToken('{"groups": []}')+ cb.onDone()+ })++ await runDuplicateDetection("/project", cfg)++ expect(mockStreamChat.mock.calls.length).toBeGreaterThan(1)+ for (const call of mockStreamChat.mock.calls) {+ const prompt = call[1][1].content as string+ const count = Number(prompt.match(/Wiki pages to scan \((\d+) entries\)/)?.[1])+ expect(count).toBeGreaterThanOrEqual(2)+ expect(count).toBeLessThanOrEqual(80)+ }+ })+it("keeps the not-duplicates whitelist active on the prefiltered path", async () => {setupThreePageProject()mockLoadNotDuplicates.mockResolvedValue([["foo", "bar"]])diff --git a/src/lib/dedup-runner.ts b/src/lib/dedup-runner.tsindex 06cc8228..18cae472 100644--- a/src/lib/dedup-runner.ts+++ b/src/lib/dedup-runner.ts@@ -37,6 +37,7 @@ const DEDUP_PREFILTER_TOP_K = 8const DEDUP_PREFILTER_THRESHOLD = 0.68const DEDUP_PREFILTER_MAX_PAGES = 5_000const DEDUP_DETECTOR_BATCH_SUMMARIES = 80+const DEDUP_FALLBACK_BATCH_OVERLAP = 8const DEDUP_EMPTY_PREFILTER_FULL_SCAN_LIMIT = 250/**@@ -220,12 +221,37 @@ export async function runDuplicateDetection(}}- return detectDuplicateGroups(summaries, llm, {+ return detectDuplicateGroupsInBoundedBatches(summaries, llm, {signal: options.signal,notDuplicates: notDup,})}+async function detectDuplicateGroupsInBoundedBatches(+ summaries: EntitySummary[],+ llm: DedupLlmCall,+ options: { signal?: AbortSignal; notDuplicates?: string[][] },+): Promise<DuplicateGroup[]> {+ if (summaries.length <= DEDUP_DETECTOR_BATCH_SUMMARIES) {+ return detectDuplicateGroups(summaries, llm, options)+ }++ // Keep likely aliases adjacent while bounding every LLM request. A small+ // overlap prevents a duplicate pair at a batch boundary from being split.+ const ordered = [...summaries].sort((left, right) =>+ `${left.title}\u0000${left.slug}`.localeCompare(`${right.title}\u0000${right.slug}`),+ )+ const stride = DEDUP_DETECTOR_BATCH_SUMMARIES - DEDUP_FALLBACK_BATCH_OVERLAP+ const groups: DuplicateGroup[] = []+ for (let start = 0; start < ordered.length; start += stride) {+ if (options.signal?.aborted) throw new Error("Duplicate scan cancelled")+ const batch = ordered.slice(start, start + DEDUP_DETECTOR_BATCH_SUMMARIES)+ if (batch.length < 2) break+ groups.push(...await detectDuplicateGroups(batch, llm, options))+ }+ return uniqueDuplicateGroups(groups)+}+async function detectDuplicateGroupsWithEmbeddingPrefilter(summaries: EntitySummary[],embeddingConfig: EmbeddingConfig,@@ -245,7 +271,7 @@ async function detectDuplicateGroupsWithEmbeddingPrefilter(// is meant to find. For large wikis, the old full scan is what caused// #359 hangs, so no candidates means no detector call.return summaries.length <= DEDUP_EMPTY_PREFILTER_FULL_SCAN_LIMIT- ? detectDuplicateGroups(summaries, llm, options)+ ? detectDuplicateGroupsInBoundedBatches(summaries, llm, options): []}