Process and add text memories (including preference memories). Extracts memories from messages and adds them to the text memory system. Handles both sync and async modes. Args: add_req: Add memory request user_context: User context with IDs
(
self,
add_req: APIADDRequest,
user_context: UserContext,
sync_mode: str,
)
| 661 | |
| 662 | @timed |
| 663 | def _process_text_mem( |
| 664 | self, |
| 665 | add_req: APIADDRequest, |
| 666 | user_context: UserContext, |
| 667 | sync_mode: str, |
| 668 | ) -> list[dict[str, Any]]: |
| 669 | """ |
| 670 | Process and add text memories (including preference memories). |
| 671 | |
| 672 | Extracts memories from messages and adds them to the text memory system. |
| 673 | Handles both sync and async modes. |
| 674 | |
| 675 | Args: |
| 676 | add_req: Add memory request |
| 677 | user_context: User context with IDs |
| 678 | |
| 679 | Returns: |
| 680 | List of formatted memory responses |
| 681 | """ |
| 682 | target_session_id = add_req.session_id or "default_session" |
| 683 | |
| 684 | # Decide extraction mode: |
| 685 | # - async: always fast (ignore add_req.mode) |
| 686 | # - sync: use add_req.mode == "fast" to switch to fast pipeline, otherwise fine |
| 687 | if sync_mode == "async": |
| 688 | extract_mode = "fast" |
| 689 | else: # sync |
| 690 | extract_mode = "fast" if add_req.mode == "fast" else "fine" |
| 691 | |
| 692 | self.logger.info( |
| 693 | "[SingleCubeView] cube=%s Processing text memory " |
| 694 | "with sync_mode=%s, extract_mode=%s, add_mode=%s", |
| 695 | user_context.mem_cube_id, |
| 696 | sync_mode, |
| 697 | extract_mode, |
| 698 | add_req.mode, |
| 699 | ) |
| 700 | process_start = time.perf_counter() |
| 701 | |
| 702 | # Stage 1+2: parse + embedding (logged inside get_memory via timed_stage) |
| 703 | with timed_stage("add", "get_memory", cube_id=self.cube_id) as ts_gm: |
| 704 | memories_local = self.mem_reader.get_memory( |
| 705 | [add_req.messages], |
| 706 | type="chat", |
| 707 | info={ |
| 708 | **(add_req.info or {}), |
| 709 | "custom_tags": add_req.custom_tags, |
| 710 | "user_id": add_req.user_id, |
| 711 | "session_id": target_session_id, |
| 712 | }, |
| 713 | mode=extract_mode, |
| 714 | user_name=user_context.mem_cube_id, |
| 715 | chat_history=add_req.chat_history, |
| 716 | user_context=user_context, |
| 717 | is_upload_skill=getattr(add_req, "is_upload_skill", False), |
| 718 | ) |
| 719 | get_memory_ms = ts_gm.duration_ms |
| 720 | flattened_local = [mm for m in memories_local for mm in m] |
no test coverage detected