Skip to content

Commit feb2f5e

Browse files
Restore summaries. Output limit 4096 so limit the number of chunks. (#692)
Experimentally, 40 chunks per batch appears to work.
1 parent 5f84b74 commit feb2f5e

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

ts/packages/agents/spelunker/src/searchCode.ts

+21-23
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ async function selectChunks(
254254
const limiter = createLimiter(maxConcurrency);
255255
const batches = makeBatches(allChunks, 250000); // TODO: Tune this more
256256
console_log(
257-
` [maxConcurrency = ${maxConcurrency}, ${batches.length} batches]`,
257+
` [${batches.length} batches, maxConcurrency ${maxConcurrency}]`,
258258
);
259259
for (const batch of batches) {
260260
const p = limiter(() =>
@@ -280,13 +280,13 @@ async function selectChunks(
280280
// console_log(` [${allChunks.map((c) => (c.relevance)).join(", ")}]`);
281281
const chunks = keepBestChunks(allChunkDescs, allChunks, 250000); // TODO: Tune this more
282282
console_log(` [Keeping ${chunks.length} chunks]`);
283-
for (let i = 0; i < chunks.length; i++) {
284-
const chunk = chunks[i];
285-
const chunkDesc = allChunkDescs[i];
286-
console_log(
287-
` [${chunkDesc.relevance} ${path.basename(chunk.fileName)}:${chunk.codeName} ${chunk.chunkId}]`,
288-
);
289-
}
283+
// for (let i = 0; i < chunks.length; i++) {
284+
// const chunk = chunks[i];
285+
// const chunkDesc = allChunkDescs[i];
286+
// console_log(
287+
// ` [${chunkDesc.relevance} ${path.basename(chunk.fileName)}:${chunk.codeName} ${chunk.chunkId}]`,
288+
// );
289+
// }
290290
return chunks;
291291
}
292292

@@ -611,14 +611,10 @@ async function loadDatabase(
611611
` [Chunked ${allChunkedFiles.length} files into ${allChunks.length} chunks]`,
612612
);
613613

614-
// Let's see how things go without summaries.
615-
// They are slow and don't fit in the oracle's buffer.
616-
// TODO: Restore this feature.
617-
618-
// // 1c. Use a fast model to summarize all chunks.
619-
// if (allChunks.length) {
620-
// await summarizeChunks(context, allChunks);
621-
// }
614+
// 1c. Use a fast model to summarize all chunks.
615+
if (allChunks.length) {
616+
await summarizeChunks(context, allChunks);
617+
}
622618

623619
return db;
624620
}
@@ -697,12 +693,15 @@ export async function summarizeChunks(
697693
console_log(
698694
`[Step 1c: Summarizing ${chunks.length} chunks (may take a while)]`,
699695
);
696+
// NOTE: We cannot stuff the buffer, because the completion size
697+
// is limited to 4096 tokens, and we expect a certain number of
698+
// tokens per chunk. Experimentally, 40 chunks per job works great.
700699
const maxConcurrency =
701-
parseInt(process.env.AZURE_OPENAI_MAX_CONCURRENCY ?? "0") ?? 40;
702-
let chunksPerJob = 30;
700+
parseInt(process.env.AZURE_OPENAI_MAX_CONCURRENCY ?? "0") ?? 5;
701+
let chunksPerJob = 40;
703702
let numJobs = Math.ceil(chunks.length / chunksPerJob);
704703
console_log(
705-
` [maxConcurrency = ${maxConcurrency}, chunksPerJob = ${chunksPerJob}, numJobs = ${numJobs}]`,
704+
` [${chunksPerJob} chunks/job, ${numJobs} jobs, maxConcurrency ${maxConcurrency}]`,
706705
);
707706
const limiter = createLimiter(maxConcurrency);
708707
const promises: Promise<void>[] = [];
@@ -732,10 +731,9 @@ async function summarizeChunkSlice(
732731
summarizer.translate(prompt),
733732
);
734733
if (!result) {
735-
const chunkSummary = chunks
736-
.map((c) => `${path.basename(c.fileName)}:${c.codeName}`)
737-
.join(", ");
738-
console_log(` [Failed to summarize chunks for ${chunkSummary}]`);
734+
console_log(
735+
` [Failed to summarize chunks for ${chunks.length} chunks]`,
736+
);
739737
return;
740738
}
741739

0 commit comments

Comments
 (0)