@@ -741,6 +741,54 @@ def search_user_memory(self, user_id: str, query: str, limit: int = 5, rerank: b
741741 filtered .append (h )
742742 return filtered [:limit ]
743743
744+ def search (self , query : str , user_id : Optional [str ] = None , agent_id : Optional [str ] = None ,
745+ run_id : Optional [str ] = None , limit : int = 5 , rerank : bool = False , ** kwargs ) -> List [Dict [str , Any ]]:
746+ """
747+ Generic search method that delegates to appropriate specific search methods.
748+ Provides compatibility with mem0.Memory interface.
749+
750+ Args:
751+ query: The search query string
752+ user_id: Optional user ID for user-specific search
753+ agent_id: Optional agent ID for agent-specific search
754+ run_id: Optional run ID for run-specific search
755+ limit: Maximum number of results to return
756+ rerank: Whether to use advanced reranking
757+ **kwargs: Additional search parameters
758+
759+ Returns:
760+ List of search results
761+ """
762+ # If using mem0, pass all parameters directly
763+ if self .use_mem0 and hasattr (self , "mem0_client" ):
764+ search_params = {
765+ "query" : query ,
766+ "limit" : limit ,
767+ "rerank" : rerank
768+ }
769+
770+ # Add optional parameters if provided
771+ if user_id is not None :
772+ search_params ["user_id" ] = user_id
773+ if agent_id is not None :
774+ search_params ["agent_id" ] = agent_id
775+ if run_id is not None :
776+ search_params ["run_id" ] = run_id
777+
778+ # Include any additional kwargs
779+ search_params .update (kwargs )
780+
781+ return self .mem0_client .search (** search_params )
782+
783+ # For local memory, use specific search methods
784+ if user_id :
785+ # Use user-specific search
786+ return self .search_user_memory (user_id , query , limit = limit , rerank = rerank , ** kwargs )
787+ else :
788+ # Default to long-term memory search
789+ # Note: agent_id and run_id filtering could be added to metadata filtering in the future
790+ return self .search_long_term (query , limit = limit , rerank = rerank , ** kwargs )
791+
744792 def reset_user_memory (self ):
745793 """
746794 Clear all user-based info. For simplicity, we do a full LTM reset.
0 commit comments