Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/services/code-index/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const MAX_PENDING_BATCHES = 20 // Maximum number of batches to accumulate

/**OpenAI Embedder */
export const MAX_BATCH_TOKENS = 100000
export const MAX_BATCH_ITEMS = 32 // Maximum number of items per embedding API call (provider limit, fixes #335)
export const MAX_ITEM_TOKENS = 8191
export const BATCH_PROCESSING_CONCURRENCY = 10

Expand Down
3 changes: 2 additions & 1 deletion src/services/code-index/embedders/bedrock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { fromIni, fromNodeProviderChain } from "@aws-sdk/credential-providers"
import { IEmbedder, EmbeddingResponse, EmbedderInfo } from "../interfaces"
import {
MAX_BATCH_TOKENS,
MAX_BATCH_ITEMS,
MAX_ITEM_TOKENS,
MAX_BATCH_RETRIES as MAX_RETRIES,
INITIAL_RETRY_DELAY_MS as INITIAL_DELAY_MS,
Expand Down Expand Up @@ -83,7 +84,7 @@ export class BedrockEmbedder implements IEmbedder {
continue
}

if (currentBatchTokens + itemTokens <= MAX_BATCH_TOKENS) {
if (currentBatchTokens + itemTokens <= MAX_BATCH_TOKENS && currentBatch.length < MAX_BATCH_ITEMS) {
currentBatch.push(text)
currentBatchTokens += itemTokens
processedIndices.push(i)
Expand Down
3 changes: 2 additions & 1 deletion src/services/code-index/embedders/openai-compatible.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { OpenAI } from "openai"
import { IEmbedder, EmbeddingResponse, EmbedderInfo } from "../interfaces/embedder"
import {
MAX_BATCH_TOKENS,
MAX_BATCH_ITEMS,
MAX_ITEM_TOKENS,
MAX_BATCH_RETRIES as MAX_RETRIES,
INITIAL_RETRY_DELAY_MS as INITIAL_DELAY_MS,
Expand Down Expand Up @@ -144,7 +145,7 @@ export class OpenAICompatibleEmbedder implements IEmbedder {
continue
}

if (currentBatchTokens + itemTokens <= MAX_BATCH_TOKENS) {
if (currentBatchTokens + itemTokens <= MAX_BATCH_TOKENS && currentBatch.length < MAX_BATCH_ITEMS) {
currentBatch.push(text)
currentBatchTokens += itemTokens
processedIndices.push(i)
Expand Down
3 changes: 2 additions & 1 deletion src/services/code-index/embedders/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ApiHandlerOptions } from "../../../shared/api"
import { IEmbedder, EmbeddingResponse, EmbedderInfo } from "../interfaces"
import {
MAX_BATCH_TOKENS,
MAX_BATCH_ITEMS,
MAX_ITEM_TOKENS,
MAX_BATCH_RETRIES as MAX_RETRIES,
INITIAL_RETRY_DELAY_MS as INITIAL_DELAY_MS,
Expand Down Expand Up @@ -100,7 +101,7 @@ export class OpenAiEmbedder extends OpenAiNativeHandler implements IEmbedder {
continue
}

if (currentBatchTokens + itemTokens <= MAX_BATCH_TOKENS) {
if (currentBatchTokens + itemTokens <= MAX_BATCH_TOKENS && currentBatch.length < MAX_BATCH_ITEMS) {
currentBatch.push(text)
currentBatchTokens += itemTokens
processedIndices.push(i)
Expand Down
3 changes: 2 additions & 1 deletion src/services/code-index/embedders/openrouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { OpenAI } from "openai"
import { IEmbedder, EmbeddingResponse, EmbedderInfo } from "../interfaces/embedder"
import {
MAX_BATCH_TOKENS,
MAX_BATCH_ITEMS,
MAX_ITEM_TOKENS,
MAX_BATCH_RETRIES as MAX_RETRIES,
INITIAL_RETRY_DELAY_MS as INITIAL_DELAY_MS,
Expand Down Expand Up @@ -148,7 +149,7 @@ export class OpenRouterEmbedder implements IEmbedder {
continue
}

if (currentBatchTokens + itemTokens <= MAX_BATCH_TOKENS) {
if (currentBatchTokens + itemTokens <= MAX_BATCH_TOKENS && currentBatch.length < MAX_BATCH_ITEMS) {
currentBatch.push(text)
currentBatchTokens += itemTokens
processedIndices.push(i)
Expand Down
Loading