You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: share ML model instances to reduce startup time (#412)
* fix: share ML model instances to reduce startup time
The backend startup was slow because RetrieverTools.initialize() creates
6 retriever chains, and each one independently loaded its own copy of
the embedding model (thenlper/gte-large) and reranker model
(BAAI/bge-reranker-base). That meant 12 heavy model loads when only
2 are actually needed, since all chains use the same model config.
This fix creates both models once at the top of initialize() and passes
the shared instances down through HybridRetrieverChain,
SimilarityRetrieverChain, and FAISSVectorDatabase. Both models are
stateless (they only run encode/score inference) so sharing a single
instance across all chains is safe. Each chain still builds its own
independent FAISS index with its own documents.
Startup model loading goes from ~34s to ~7s on a local machine (4.9x).
Resolves#88
Signed-off-by: Harsh Kumar <harshkumar3446@gmail.com>
* refactor(backend): build every embedding model in one factory
RetrieverTools had its own copy of the embedding setup. That copy built
plain Gemini embeddings without the retry on temporary 503 errors, and
it passed the old model_name argument to VertexAIEmbeddings. The shared
and per-database models now come from create_embedding_model, so the
two paths cannot drift.
Signed-off-by: Vitor Bandeira <vvbandeira@precisioninno.com>
* fix(backend): share the HuggingFace reranker only when it is used
With RERANKER_TYPE=VERTEX_AI, the chains build a Vertex AI reranker.
Building the shared CrossEncoder anyway downloaded and loaded a model
that no chain used.
Signed-off-by: Vitor Bandeira <vvbandeira@precisioninno.com>
---------
Signed-off-by: Harsh Kumar <harshkumar3446@gmail.com>
Signed-off-by: Vitor Bandeira <vvbandeira@precisioninno.com>
Co-authored-by: Harsh Kumar <harshkumar3446@gmail.com>
0 commit comments