Embedder Initialization
Mis à jour le 2025-12-30Confiance : high
embedder-initializationimport-errorsdependency-managementrag-architectureopenai-embedderpostgres-retrieverruntime-crashesinitialization-failurescategory-5-bugsdependency-injectiondefault-constructors
Critical pattern in RAG systems where embedding model instances must be properly initialized before use. Failures in embedder initialization represent "Category 5" bugs that cause immediate runtime crashes, typically due to missing imports, incorrect dependency management, or failed dependency injection.
The Problem
Import/Initialization Mismatch
In the assistant-rh system, a critical bug exists where the PostgreSQL retriever attempts to instantiate an embedder with a commented-out import:
# Problematic code pattern
# from src.rag.embedder import OpenAIEmbedder # COMMENTED OUT!
class PostgresRetriever:
def __init__(self, embedder=None):
# BUG: Will crash if embedder is None due to missing import
self.embedder = embedder or OpenAIEmbedder() # NameError!
This creates an immediate NameError when the class is instantiated without an explicit embedder parameter.
Production Impact
Embedder initialization failures cause:
- Immediate crashes: NameError exceptions during object construction
- Silent failures: Systems that catch all exceptions may hide the root cause
- Deployment failures: Services fail to start due to initialization errors
- Testing gaps: Unit tests with mocked embedders may pass while production crashes
Common Failure Patterns
1. Missing Import Dependencies
# BAD: Import commented out or missing
# from embeddings import OpenAIEmbedder
class Retriever:
def __init__(self):