Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions backend/indexing/embedder.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ def model(self):
logger.info("Embedding model loaded.")
return self._model

def load(self) -> None:
"""
Force the model to load/download immediately (eager loading).

Intended to be called during application startup so that the
(potentially slow) model download/initialization happens before
the server begins accepting HTTP requests, rather than blocking
the first incoming request.
"""
_ = self.model

@property
def dimension(self) -> int:
"""Embedding vector dimension."""
Expand Down
8 changes: 8 additions & 0 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ async def lifespan(app: FastAPI):
app.state.orchestrator = Orchestrator()
app.state.database = Database()

# Eagerly load the embedding model now so the (slow) download/init
# happens during startup instead of blocking the first HTTP request.
# Without this, the embedder's lazy `@property` defers loading until
# first use, causing 502s while the model downloads on first request.
logger.info("Eagerly loading embedding model before accepting requests...")
app.state.orchestrator.embedder.load()
logger.info("Embedding model ready.")

logger.info(
f"Research Agent API ready. "
f"Vector store: {app.state.orchestrator.vector_store.count()} passages"
Expand Down