Initialize all server components and configurations. This function orchestrates the creation and initialization of all components required by the MemOS server, including: - Database connections (graph DB, vector DB) - Language models and embedders - Memory systems (text)
()
| 106 | |
| 107 | |
| 108 | def init_server() -> dict[str, Any]: |
| 109 | """ |
| 110 | Initialize all server components and configurations. |
| 111 | |
| 112 | This function orchestrates the creation and initialization of all components |
| 113 | required by the MemOS server, including: |
| 114 | - Database connections (graph DB, vector DB) |
| 115 | - Language models and embedders |
| 116 | - Memory systems (text) |
| 117 | - Scheduler and related modules |
| 118 | |
| 119 | Returns: |
| 120 | A dictionary containing all initialized components with descriptive keys. |
| 121 | This approach allows easy addition of new components without breaking |
| 122 | existing code that uses the components. |
| 123 | """ |
| 124 | logger.info("Initializing MemOS server components...") |
| 125 | logger.info( |
| 126 | "[INIT_SERVER] env_MEMSCHEDULER_STREAM_KEY_PREFIX=%s, env_MEMSCHEDULER_REDIS_STREAM_KEY_PREFIX=%s, env_POLAR_DB_DB_NAME=%s", |
| 127 | os.getenv("MEMSCHEDULER_STREAM_KEY_PREFIX"), |
| 128 | os.getenv("MEMSCHEDULER_REDIS_STREAM_KEY_PREFIX"), |
| 129 | os.getenv("POLAR_DB_DB_NAME"), |
| 130 | ) |
| 131 | |
| 132 | # Initialize Redis client first as it is a core dependency for features like scheduler status tracking |
| 133 | if os.getenv("MEMSCHEDULER_USE_REDIS_QUEUE", "False").lower() == "true": |
| 134 | try: |
| 135 | from memos.mem_scheduler.orm_modules.api_redis_model import APIRedisDBManager |
| 136 | |
| 137 | redis_client = APIRedisDBManager.load_redis_engine_from_env() |
| 138 | if redis_client: |
| 139 | logger.info("Redis client initialized successfully.") |
| 140 | else: |
| 141 | logger.error( |
| 142 | "Failed to initialize Redis client. Check REDIS_HOST etc. in environment variables." |
| 143 | ) |
| 144 | except Exception as e: |
| 145 | logger.error(f"Failed to initialize Redis client: {e}", exc_info=True) |
| 146 | redis_client = None # Ensure redis_client exists even on failure |
| 147 | else: |
| 148 | redis_client = None |
| 149 | |
| 150 | # Get default cube configuration |
| 151 | default_cube_config = APIConfig.get_default_cube_config() |
| 152 | |
| 153 | # Get online bot setting |
| 154 | dingding_enabled = APIConfig.is_dingding_bot_enabled() |
| 155 | |
| 156 | # Build component configurations |
| 157 | graph_db_config = build_graph_db_config() |
| 158 | llm_config = build_llm_config() |
| 159 | chat_llm_config = build_chat_llm_config() |
| 160 | playground_chat_llm_config = build_chat_llm_config("PLAYGROUND_CHAT_MODEL_LIST") |
| 161 | embedder_config = build_embedder_config() |
| 162 | nli_client_config = build_nli_client_config() |
| 163 | mem_reader_config = build_mem_reader_config() |
| 164 | reranker_config = build_reranker_config() |
| 165 | feedback_reranker_config = build_feedback_reranker_config() |
no test coverage detected