Skip to content

Commit 70fa2e2

Browse files
author
SatoshiReport
committed
feat: add embedding rate limiting to prevent API quota exhaustion
- Add EMBEDDING_CALL_DELAY_MS constant (100ms) to prevent rate limiting - Implement delays after embedding calls in file-watcher.ts - Implement delays after embedding calls in scanner.ts - Helps prevent HTTP 429 errors during code indexing operations
1 parent 36d56e8 commit 70fa2e2

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

src/services/code-index/constants/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ export const BATCH_PROCESSING_CONCURRENCY = 10
2828

2929
/**Gemini Embedder */
3030
export const GEMINI_MAX_ITEM_TOKENS = 2048
31+
32+
/**Embedding Rate Limiting */
33+
export const EMBEDDING_CALL_DELAY_MS = 100 // Pause between embedding API calls to prevent rate limiting

src/services/code-index/processors/file-watcher.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
BATCH_SEGMENT_THRESHOLD,
66
MAX_BATCH_RETRIES,
77
INITIAL_RETRY_DELAY_MS,
8+
EMBEDDING_CALL_DELAY_MS,
89
} from "../constants"
910
import { createHash } from "crypto"
1011
import { RooIgnoreController } from "../../../core/ignore/RooIgnoreController"
@@ -542,6 +543,9 @@ export class FileWatcher implements IFileWatcher {
542543
if (this.embedder && blocks.length > 0) {
543544
const texts = blocks.map((block) => block.content)
544545
const { embeddings } = await this.embedder.createEmbeddings(texts)
546+
547+
// Add pause between embedding calls to prevent rate limiting
548+
await new Promise(resolve => setTimeout(resolve, EMBEDDING_CALL_DELAY_MS))
545549

546550
pointsToUpsert = blocks.map((block, index) => {
547551
const normalizedAbsolutePath = generateNormalizedAbsolutePath(block.file_path, this.workspacePath)

src/services/code-index/processors/scanner.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
INITIAL_RETRY_DELAY_MS,
2424
PARSING_CONCURRENCY,
2525
BATCH_PROCESSING_CONCURRENCY,
26+
EMBEDDING_CALL_DELAY_MS,
2627
} from "../constants"
2728
import { isPathInIgnoredDirectory } from "../../glob/ignore-utils"
2829
import { TelemetryService } from "@roo-code/telemetry"
@@ -344,6 +345,9 @@ export class DirectoryScanner implements IDirectoryScanner {
344345

345346
// Create embeddings for batch
346347
const { embeddings } = await this.embedder.createEmbeddings(batchTexts)
348+
349+
// Add pause between embedding calls to prevent rate limiting
350+
await new Promise(resolve => setTimeout(resolve, EMBEDDING_CALL_DELAY_MS))
347351

348352
// Prepare points for Qdrant
349353
const points = batchBlocks.map((block, index) => {

0 commit comments

Comments
 (0)