Skip to content

Commit 8d48e72

Browse files
committed
feat: Implement rate limit configuration for Gemini embedder and add control in settings
1 parent 43562bb commit 8d48e72

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/services/code-index/embedders/gemini.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ export class CodeIndexGeminiEmbedder extends GeminiHandler implements IEmbedder
112112

113113
// Process the current batch if not empty
114114
if (currentBatch.length > 0) {
115-
// Add proactive delay for rate limiting, except for the very first batch.
116-
if (!isFirstBatch) {
117-
console.log(`Adding proactive delay of ${GEMINI_RATE_LIMIT_DELAY_MS}ms before Gemini batch`)
118-
await new Promise((resolve) => setTimeout(resolve, GEMINI_RATE_LIMIT_DELAY_MS))
119-
}
120-
isFirstBatch = false // Set to false after the first potential delay or first run
115+
const delayMs =
116+
this.options.rateLimitSeconds !== undefined
117+
? this.options.rateLimitSeconds * 1000
118+
: GEMINI_RATE_LIMIT_DELAY_MS
119+
console.log(`Adding proactive delay of ${delayMs}ms before Gemini batch`)
120+
await new Promise((resolve) => setTimeout(resolve, delayMs))
121121

122122
try {
123123
const batchResult = await this._embedBatchWithRetries(currentBatch, model, taskType)

webview-ui/src/components/settings/CodeIndexSettings.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
} from "@src/components/ui"
3131

3232
import { SetCachedStateField } from "./types"
33+
import { RateLimitSecondsControl } from "./RateLimitSecondsControl"
3334

3435
interface CodeIndexSettingsProps {
3536
codebaseIndexModels: CodebaseIndexModels | undefined
@@ -401,6 +402,12 @@ export const CodeIndexSettings: React.FC<CodeIndexSettingsProps> = ({
401402
</div>
402403
</div>
403404
</div>
405+
<div className="flex flex-col gap-3">
406+
<RateLimitSecondsControl
407+
value={apiConfiguration.rateLimitSeconds || 0}
408+
onChange={(value) => setApiConfigurationField("rateLimitSeconds", value)}
409+
/>
410+
</div>
404411
</>
405412
)}
406413

0 commit comments

Comments
 (0)