Repository navigation
Eagerly load embedding model on FastAPI startup - #1
Open
railway-app[bot] wants to merge 1 commit into
Open
railway-app[bot] wants to merge 1 commit into
railway-app[bot] wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The Embedder in backend/indexing/embedder.py lazily loads the all-MiniLM-L6-v2 model via a @Property, deferring the download/initialization until the first request. Since this can take 5-15 minutes, the first requests after deploy hit the backend while it's mid-download, resulting in 502 Bad Gateway errors even though the Dockerfile pre-seeds data via
python -m backend.cli ingest sample_docs/.Solution
Added an explicit
load()method to Embedder that forces the lazymodelproperty to resolve. In backend/main.py's lifespan startup handler, we now callapp.state.orchestrator.embedder.load()right after constructing the Orchestrator, so the model is fully downloaded and initialized before the FastAPI app finishes startup and begins accepting HTTP requests.Changes
backend/indexing/embedder.pybackend/main.pyGenerated by Railway