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

Method map

src/memos/context/context.py:279–313  ·  view source on GitHub ↗

Returns an iterator equivalent to map(fn, iter). Automatically propagates the current thread's context to worker threads.

(
        self,
        fn: Callable[..., T],
        *iterables: Any,
        timeout: float | None = None,
        chunksize: int = 1,
    )

Source from the content-addressed store, hash-verified

277 return super().submit(wrapper, *args, **kwargs)
278
279 def map(
280 self,
281 fn: Callable[..., T],
282 *iterables: Any,
283 timeout: float | None = None,
284 chunksize: int = 1,
285 ) -> Any:
286 """
287 Returns an iterator equivalent to map(fn, iter).
288 Automatically propagates the current thread's context to worker threads.
289 """
290 main_trace_id = get_current_trace_id()
291 main_api_path = get_current_api_path()
292 main_env = get_current_env()
293 main_user_type = get_current_user_type()
294 main_user_name = get_current_user_name()
295 main_context = get_current_context()
296
297 @functools.wraps(fn)
298 def wrapper(*args: Any, **kwargs: Any) -> Any:
299 if main_context:
300 # Create and set new context in worker thread
301 child_context = RequestContext(
302 trace_id=main_trace_id,
303 api_path=main_api_path,
304 env=main_env,
305 user_type=main_user_type,
306 user_name=main_user_name,
307 )
308 child_context._data = main_context._data.copy()
309 set_request_context(child_context)
310
311 return fn(*args, **kwargs)
312
313 return super().map(wrapper, *iterables, timeout=timeout, chunksize=chunksize)
314
315
316# Type for trace_id getter function

Callers 15

deepResolveEnvFunction · 0.80
embedMethod · 0.80
loadTelemetryCredentialsFunction · 0.80
createMemoryTimelineToolFunction · 0.80
buildTopicJudgeStateMethod · 0.80
shouldSkipSummaryMethod · 0.80
generateTitleMethod · 0.80
fallbackSummaryMethod · 0.80
storeChunkMethod · 0.80
filterRelevantOpenAIFunction · 0.80

Calls 6

get_current_trace_idFunction · 0.85
get_current_api_pathFunction · 0.85
get_current_envFunction · 0.85
get_current_user_typeFunction · 0.85
get_current_user_nameFunction · 0.85
get_current_contextFunction · 0.85

Tested by 15

embedFunction · 0.64
embedManyFunction · 0.64
buildLlmFunction · 0.64
traceFunction · 0.64
embedManyFunction · 0.64
embedManyFunction · 0.64
embedManyFunction · 0.64
embedMethod · 0.64
embedMethod · 0.64
embedFunction · 0.64
fakeEmbedderFunction · 0.64
searchByVectorFunction · 0.64