@@ -42,41 +42,67 @@ def _get_required_env_var(key: str) -> str:
4242 raise ValueError (f"{ key } environment variable is required." )
4343 return value
4444
45+ @staticmethod
46+ def _parse_log_level (log_level_name : str ) -> int :
47+ log_levels = {
48+ "DEBUG" : logging .DEBUG ,
49+ "INFO" : logging .INFO ,
50+ "WARNING" : logging .WARNING ,
51+ "ERROR" : logging .ERROR ,
52+ "CRITICAL" : logging .CRITICAL ,
53+ }
54+ if log_level_name not in log_levels :
55+ raise ValueError (
56+ f"Invalid LOG_LEVEL: '{ log_level_name } '. Must be one of: { ', ' .join (log_levels .keys ())} "
57+ )
58+ return log_levels [log_level_name ]
59+
4560 @staticmethod
4661 def _init_db_provider (db_type : str ) -> DBProvider :
4762 """
4863 Initialize the correct DBProvider subclass based on DB_TYPE.
4964 """
65+ get = Config ._get_required_env_var
5066 db_type = db_type .upper ()
67+ embedding_model = get ("EMBEDDING_MODEL" )
5168
5269 if db_type == "REDIS" :
53- url = Config . _get_required_env_var ("REDIS_URL" )
70+ url = get ("REDIS_URL" )
5471 index = os .getenv ("REDIS_INDEX" , "docs" )
5572 schema = os .getenv ("REDIS_SCHEMA" , "redis_schema.yaml" )
56- return RedisProvider (url , index , schema )
73+ return RedisProvider (embedding_model , url , index , schema )
5774
5875 elif db_type == "ELASTIC" :
59- url = Config . _get_required_env_var ("ELASTIC_URL" )
60- password = Config . _get_required_env_var ("ELASTIC_PASSWORD" )
76+ url = get ("ELASTIC_URL" )
77+ password = get ("ELASTIC_PASSWORD" )
6178 index = os .getenv ("ELASTIC_INDEX" , "docs" )
6279 user = os .getenv ("ELASTIC_USER" , "elastic" )
63- return ElasticProvider (url , password , index , user )
80+ return ElasticProvider (embedding_model , url , password , index , user )
6481
6582 elif db_type == "PGVECTOR" :
66- url = Config . _get_required_env_var ("PGVECTOR_URL" )
67- collection = Config . _get_required_env_var ("PGVECTOR_COLLECTION_NAME" )
68- return PGVectorProvider (url , collection )
83+ url = get ("PGVECTOR_URL" )
84+ collection = get ("PGVECTOR_COLLECTION_NAME" )
85+ return PGVectorProvider (embedding_model , url , collection )
6986
7087 elif db_type == "SQLSERVER" :
71- return SQLServerProvider () # Handles its own env var loading
88+ host = get ("SQLSERVER_HOST" )
89+ port = get ("SQLSERVER_PORT" )
90+ user = get ("SQLSERVER_USER" )
91+ password = get ("SQLSERVER_PASSWORD" )
92+ database = get ("SQLSERVER_DB" )
93+ table = get ("SQLSERVER_TABLE" )
94+ driver = get ("SQLSERVER_DRIVER" )
95+ return SQLServerProvider (
96+ embedding_model , host , port , user , password , database , table , driver
97+ )
7298
7399 elif db_type == "QDRANT" :
74- url = Config . _get_required_env_var ("QDRANT_URL" )
75- collection = Config . _get_required_env_var ("QDRANT_COLLECTION" )
76- return QdrantProvider (url , collection )
100+ url = get ("QDRANT_URL" )
101+ collection = get ("QDRANT_COLLECTION" )
102+ return QdrantProvider (embedding_model , url , collection )
77103
78104 elif db_type == "DRYRUN" :
79- return DryRunProvider ()
105+ return DryRunProvider (embedding_model )
80106
81107 raise ValueError (f"Unsupported DB_TYPE '{ db_type } '" )
82108
@@ -99,44 +125,32 @@ def load() -> "Config":
99125 get = Config ._get_required_env_var
100126
101127 # Initialize logger
102- log_level_name = get ("LOG_LEVEL" ).lower ()
103- log_levels = {
104- "debug" : 10 ,
105- "info" : 20 ,
106- "warning" : 30 ,
107- "error" : 40 ,
108- "critical" : 50 ,
109- }
110- if log_level_name not in log_levels :
111- raise ValueError (
112- f"Invalid LOG_LEVEL: '{ log_level_name } '. Must be one of: { ', ' .join (log_levels )} "
113- )
114- log_level = log_levels [log_level_name ]
115- logging .basicConfig (level = log_level )
128+ log_level = get ("LOG_LEVEL" ).upper ()
129+ logging .basicConfig (level = Config ._parse_log_level (log_level ))
116130 logger = logging .getLogger (__name__ )
117- logger .debug ("Logging initialized at level: %s" , log_level_name . upper () )
131+ logger .debug ("Logging initialized at level: %s" , log_level )
118132
119133 # Initialize db
120134 db_type = get ("DB_TYPE" )
121135 db_provider = Config ._init_db_provider (db_type )
122136
123137 # Web URLs
124- web_sources_raw = get ("WEB_SOURCES" )
125138 try :
126- web_sources = json .loads (web_sources_raw )
139+ web_sources = json .loads (get ( "WEB_SOURCES" ) )
127140 except json .JSONDecodeError as e :
128141 raise ValueError (f"WEB_SOURCES must be a valid JSON list: { e } " )
129142
130143 # Repo sources
131- repo_sources_json = get ("REPO_SOURCES" )
132144 try :
133- repo_sources = json .loads (repo_sources_json )
145+ repo_sources = json .loads (get ( "REPO_SOURCES" ) )
134146 except json .JSONDecodeError as e :
135147 raise ValueError (f"Invalid REPO_SOURCES JSON: { e } " ) from e
136148
137- # Misc
149+ # Embedding settings
138150 chunk_size = int (get ("CHUNK_SIZE" ))
139151 chunk_overlap = int (get ("CHUNK_OVERLAP" ))
152+
153+ # Misc
140154 temp_dir = get ("TEMP_DIR" )
141155
142156 return Config (
0 commit comments