FEATURE REQUEST:Fix EmbeddingService blocking the event loop

Aperta
#261 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@dolliecoder ci sta già lavorando.

Dal 2/2/2026.

  • #262 di @dolliecoder — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
48/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
python

Direzione di ricerca

Inizia in backend/app/services/embedding_service/service.py, concentrandoti su get_embedding e get_embeddings e sulle relative chiamate sincrone a model.encode. Esamina i consumer in app/services/github/user/profiling.py, app/services/github/issue_processor.py e app/agents/devrel/github/tools/contributor_recommendation.py; il lavoro è completo quando l’API async pubblica rimane invariata e un’altra richiesta async resta reattiva durante la generazione degli embedding.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Is your feature request related to a problem?
  • Yes, it is related to a problem
Describe the feature you'd like

🌟Feature Description

Offload blocking embedding work from the async event loop so that EmbeddingService does not block other concurrent requests. The service should run CPU/GPU-bound model.encode() calls in a thread pool (e.g. via asyncio.to_thread()) while keeping the public API async.

🔍 Problem Statement

EmbeddingService exposes async methods (get_embedding, get_embeddings, summarize_user_profile, search_similar_profiles) but internally calls synchronous SentenceTransformer code:

  • self.model.encode(...) in get_embedding and get_embeddings is blocking. It runs on CPU/GPU and does not yield to the event loop.
  • While one request is generating embeddings, the entire process is blocked: other HTTP requests, agent tools, and background tasks stall until the encode finishes.
  • The LLM call in summarize_user_profile correctly uses await self.llm.ainvoke(...) and is non-blocking; only the embedding step blocks.

This hurts latency and concurrency wherever the service is used (e.g. issue_processor.py, contributor_recommendation.py, user profiling).

🎯 Expected Outcome

  • Event loop stays responsive during embedding generation: other async work (API handlers, other embeddings, LLM calls) can run while model.encode() runs in a worker thread.
  • No change to the public API: callers keep using await embedding_service.get_embedding(...) and await embedding_service.get_embeddings(...).
  • Implementation approach: add a synchronous helper that performs model.encode() and tensor-to-list conversion; call it from get_embedding and get_embeddings via asyncio.to_thread() (or loop.run_in_executor() with a ThreadPoolExecutor).
  • Optional: run model lazy-load in a thread at first use to avoid blocking on first request.

📷 Screenshots and Design Ideas

Before: One long embedding request blocks the event loop → other requests wait.

After: Embedding runs in a thread pool → event loop continues handling other requests; embedding call still awaited by the original request.

No UI changes; this is a backend concurrency fix.

📋 Additional Context

  • File to change: backend/app/services/embedding_service/service.py
  • Consumers: app/services/github/user/profiling.py, app/services/github/issue_processor.py, app/agents/devrel/github/tools/contributor_recommendation.py
  • Suggested steps:
    1. Add import asyncio.
    2. Add a sync helper method (e.g. _encode(texts)) that calls self.model.encode(...) and returns list(s) of floats.
    3. In get_embedding: replace direct model.encode with await asyncio.to_thread(self._encode, [text]), then return the single embedding list.
    4. In get_embeddings: replace direct model.encode with await asyncio.to_thread(self._encode, texts) and return the list of lists.
  • Verification: While one request is generating embeddings, trigger another (e.g. health check or simple async endpoint); the second should respond without waiting for the first.
Record
  • I agree to follow this project's Code of Conduct
  • I want to work on implementing this feature
Lingua principale
Python
Stelle
103
Fork
143
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di AOSSIE-Org/Devr.AI

Tutte le issue di AOSSIE-Org/Devr.AI

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.