Skip to main content
Glama

search_memories

Search stored conversation memories using natural language queries and filters to find relevant information across users and agents.

Instructions

Run a semantic search over existing memories.

    Use filters to narrow results. Common filter patterns:
    - Single user: {"AND": [{"user_id": "john"}]}
    - Agent memories: {"AND": [{"agent_id": "agent_name"}]}
    - Recent memories: {"AND": [{"user_id": "john"}, {"created_at": {"gte": "2024-01-01"}}]}
    - Multiple users: {"AND": [{"user_id": {"in": ["john", "jane"]}}]}
    - Cross-entity: {"OR": [{"user_id": "john"}, {"agent_id": "agent_name"}]}

    user_id is automatically added to filters if not provided.
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesNatural language description of what to find.
filtersNoAdditional filter clauses (user_id injected automatically).
limitNoMaximum number of results to return.
enable_graphNoSet true only when the user explicitly wants graph-derived memories.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function for the 'search_memories' MCP tool. It is registered via the @server.tool decorator, validates input using SearchMemoriesArgs, injects default user_id into filters, and invokes the Mem0 MemoryClient.search method to perform semantic search on memories.
    @server.tool(
        description="""Run a semantic search over existing memories.
    
        Use filters to narrow results. Common filter patterns:
        - Single user: {"AND": [{"user_id": "john"}]}
        - Agent memories: {"AND": [{"agent_id": "agent_name"}]}
        - Recent memories: {"AND": [{"user_id": "john"}, {"created_at": {"gte": "2024-01-01"}}]}
        - Multiple users: {"AND": [{"user_id": {"in": ["john", "jane"]}}]}
        - Cross-entity: {"OR": [{"user_id": "john"}, {"agent_id": "agent_name"}]}
    
        user_id is automatically added to filters if not provided.
        """
    )
    def search_memories(
        query: Annotated[str, Field(description="Natural language description of what to find.")],
        filters: Annotated[
            Optional[Dict[str, Any]],
            Field(default=None, description="Additional filter clauses (user_id injected automatically)."),
        ] = None,
        limit: Annotated[
            Optional[int], Field(default=None, description="Maximum number of results to return.")
        ] = None,
        enable_graph: Annotated[
            Optional[bool],
            Field(
                default=None,
                description="Set true only when the user explicitly wants graph-derived memories.",
            ),
        ] = None,
        ctx: Context | None = None,
    ) -> str:
        """Semantic search against existing memories."""
    
        api_key, default_user, graph_default = _resolve_settings(ctx)
        args = SearchMemoriesArgs(
            query=query,
            filters=filters,
            limit=limit,
            enable_graph=_default_enable_graph(enable_graph, graph_default),
        )
        payload = args.model_dump(exclude_none=True)
        payload["filters"] = _with_default_filters(default_user, payload.get("filters"))
        payload.setdefault("enable_graph", graph_default)
        client = _mem0_client(api_key)
        return _mem0_call(client.search, **payload)
  • Pydantic model defining the input schema (arguments) for the search_memories tool, used for validation in the handler.
    class SearchMemoriesArgs(BaseModel):
        query: str = Field(..., description="Describe what you want to find.")
        filters: Optional[Dict[str, Any]] = Field(
            None, description="Additional filter clauses; user_id is injected automatically."
        )
        limit: Optional[int] = Field(None, description="Optional maximum number of matches.")
        enable_graph: Optional[bool] = Field(
            None, description="Set True only when the user asks for graph knowledge."
        )
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden and adds valuable behavioral context. It discloses that 'user_id is automatically added to filters if not provided' - an important implementation detail not evident from the schema. It also provides practical filter patterns showing how the tool behaves with different query structures. However, it doesn't mention rate limits, authentication requirements, or pagination behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately front-loaded with the core purpose, but the extensive filter examples (5 patterns) make it somewhat lengthy. While the examples are helpful, they could potentially be streamlined. Every sentence earns its place by providing practical guidance, but the structure could be more concise.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (semantic search with filtering), no annotations, but with complete schema coverage and an output schema, the description provides good contextual coverage. It explains the core search behavior, provides practical filter examples, and discloses the automatic user_id injection. The presence of an output schema means the description doesn't need to explain return values. However, for a search tool with no annotations, it could benefit from mentioning performance characteristics or result ordering.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 100% schema description coverage, the baseline is 3. The description adds meaningful value by explaining filter usage patterns with concrete examples, showing how the 'filters' parameter works in practice. It also clarifies the automatic user_id injection behavior, which enhances understanding beyond the schema's technical description. However, it doesn't provide similar context for 'enable_graph' or 'limit' parameters.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Run a semantic search over existing memories.' This specifies the verb ('search') and resource ('memories'), and the semantic aspect distinguishes it from simple filtering. However, it doesn't explicitly differentiate from sibling tools like 'get_memories' or 'list_entities'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides implied usage context through filter examples and the note about automatic user_id injection, suggesting this is for retrieving memories with semantic matching. However, it lacks explicit guidance on when to use this tool versus alternatives like 'get_memories' (which appears to be a simpler retrieval) or 'list_entities'.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/parthshr370/mem0_mcp_private'

If you have feedback or need assistance with the MCP directory API, please join our Discord server