EmbeddingService: use flutter_gemma batch API (generateEmbeddings) for sync-burst throughput
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
Problem
EmbeddingService.embed (lib/features/shiv/rag/embedding/embedding_service.dart) calls EmbeddingModel.generateEmbedding(text) once per note. Every call
pays the full LiteRT per-invocation overhead (input/output tensor marshalling, GPU dispatch setup/teardown). The actual model math on Gecko-110M is
tiny — overhead dominates.
This is invisible when a user adds one note at a time, but becomes visible during sync bursts:
- First app open after install / restore (relay backfills 100s of notes)
- Returning online after a few days
- Joining / catching up on a busy channel or long thread
In those windows the embedder lane saturates EmbeddingQueue(Semaphore(2)) for ~tens of seconds, RAG context lags behind the visible feed (Shiv answers
are "incomplete" until the index catches up), and the phone stays warm.
Proposal
Wire flutter_gemma's batch entry point through the service:
Future<List<List>> embedBatch(
List texts, {
bool isDocument = false,
});
Internally calls _model!.generateEmbeddings(texts, taskType: ...) — one native dispatch for the whole list — then L2-normalises each vector. Keep the
existing single-text embed() as a thin wrapper around embedBatch([text]).first so call sites that genuinely embed one string at a time don't change.
Call sites to migrate
- The note-ingest path that embeds inbound Kind 1 events as the Gateway writes them to Isar. Currently iterates and calls embed(...) per note; should
accumulate a small list (e.g. up to N=16 or whatever flushes a Gateway batch) and call embedBatch. - Saved-note / reference-note backfill jobs.
Out of scope — explicitly NOT changing
- The embedding model itself (stay on bundled Gecko-1024 — offline-first, ~25 MB).
- The 1-hop GraphRAG expansion. Edges come from e/t tags, not from the embedder.
- The EmbeddingQueue(Semaphore(2)) parallelism cap — that stays as a backpressure guard.
- Shiv chat query embedding — already single-string, no batching opportunity.
Expected user-visible improvements
No change to single-add latency or retrieval quality.
Acceptance
- New embedBatch(List) lands on EmbeddingService with GPU→CPU fallback preserved.
- Inbound note handler in the Gateway batches embed calls.
- Device test (one app install, integration_test/) ingests N≈100 notes and asserts wall-clock time drops by ≥5× vs. current per-note path on the same
device. - No regression on chat first-token latency or single-note add.
References
- Current implementation: lib/features/shiv/rag/embedding/embedding_service.dart
- flutter_gemma docs: https://pub.dev/documentation/flutter_gemma/latest/ (see generateEmbeddings)
- Lingua principale
- Dart
- Stelle
- 2
- Fork
- 2
- Merge medio
- 1g 7h
- PR unite (30g)
- 35
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di basictech01/uniun
-
bug good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
basictech01/uniun#300 ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement good first issue P2-Medium
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
basictech01/uniun#296 ·
I maintainer di solito rispondono entro 1 giorno
-
bug good first issue P2-Medium
Difficoltà 4/5 1-2 giorni Idoneità per principianti 22/100
basictech01/uniun#293 ·
I maintainer di solito rispondono entro 1 giorno
-
bug P1-High
Difficoltà 4/5 3-5 giorni Idoneità per principianti 18/100
basictech01/uniun#286 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
P3-Low
Difficoltà 4/5 1-2 giorni Idoneità per principianti 30/100
basictech01/uniun#282 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di basictech01/uniun
Issue simili
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 65/100
chriskelly/wish-together#36 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
AppFlowy-IO/AppFlowy#9075 ·
-
Paste asks for iOS paste permission because the default context menu ignores SystemContextMenuForse già presa @dorklein l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
maheshj01/searchfield#267 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
hajisensai/Fushi#2340 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno