improvement(kb): add configurable concurrency to chunks processing, speedup up to 22x for large docs#2681
Conversation
…ped up 22x for large docs
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Greptile SummaryReplaced serial batch processing with concurrent worker pool pattern in embedding generation, achieving up to 22x speedup for large documents. Key Changes:
How It Works: Performance Impact: Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant generateEmbeddings
participant processWithConcurrency
participant Worker1
participant Worker2
participant WorkerN
participant callEmbeddingAPI
participant OpenAI/Azure
Client->>generateEmbeddings: texts[], model, workspaceId
generateEmbeddings->>generateEmbeddings: batchByTokenLimit(texts, 8000 tokens)
Note over generateEmbeddings: Split into batches by token limit
generateEmbeddings->>processWithConcurrency: batches[], concurrency=50
Note over processWithConcurrency: Create worker pool (min of 50 or batch count)
par Concurrent Workers
processWithConcurrency->>Worker1: Process batch[0]
processWithConcurrency->>Worker2: Process batch[1]
processWithConcurrency->>WorkerN: Process batch[n]
end
par Parallel API Calls
Worker1->>callEmbeddingAPI: batch texts
Worker2->>callEmbeddingAPI: batch texts
WorkerN->>callEmbeddingAPI: batch texts
end
par API Requests with Retry
callEmbeddingAPI->>OpenAI/Azure: POST /embeddings
OpenAI/Azure-->>callEmbeddingAPI: embeddings data
Note over callEmbeddingAPI: Retry on 429/5xx with exponential backoff
end
Worker1-->>processWithConcurrency: batch embeddings
Worker2-->>processWithConcurrency: batch embeddings
WorkerN-->>processWithConcurrency: batch embeddings
processWithConcurrency->>processWithConcurrency: Collect all results
processWithConcurrency-->>generateEmbeddings: all batch results
generateEmbeddings->>generateEmbeddings: batchResults.flat()
generateEmbeddings-->>Client: embeddings[][]
|
…ped up 22x for large docs (#2681)
Summary
Type of Change
Testing
Tested manually
Checklist