MCPcopy Create free account
hub / github.com/MemTensor/MemOS / init_server

Function init_server

src/memos/api/handlers/component_init.py:108–341  ·  view source on GitHub ↗

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)

()

Source from the content-addressed store, hash-verified

106
107
108def 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()

Callers 2

load_cube.pyFile · 0.90
dump_cube.pyFile · 0.90

Calls 15

build_graph_db_configFunction · 0.90
build_llm_configFunction · 0.90
build_chat_llm_configFunction · 0.90
build_embedder_configFunction · 0.90
build_nli_client_configFunction · 0.90
build_mem_reader_configFunction · 0.90
build_reranker_configFunction · 0.90
build_plugin_contextFunction · 0.90
MemoryManagerClass · 0.90
FastTokenizerClass · 0.90

Tested by

no test coverage detected