Skip to main content
Glama

memory_find_duplicates

Identify and analyze duplicate memory entries in Memora by scanning cross-references and using semantic comparison to maintain clean memory storage.

Instructions

Find potential duplicate memory pairs with optional LLM-powered comparison.

Scans cross-references to find memory pairs with similarity >= threshold, then optionally uses LLM to semantically compare them. Uses the same threshold (0.85) as the graph UI duplicate detection.

Args: min_similarity: Minimum similarity score to consider (default: 0.85) max_similarity: Maximum similarity score (default: 1.0, kept for backward compatibility) limit: Maximum pairs to analyze (default: 10) use_llm: Whether to use LLM for semantic comparison (default: True)

Returns: Dictionary with: - pairs: List of potential duplicate pairs with analysis - total_candidates: Total pairs found - analyzed: Number of pairs analyzed with LLM - llm_available: Whether LLM comparison was available

Rate limited: 120s cooldown.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
min_similarityNo
max_similarityNo
limitNo
use_llmNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The implementation of the logic for finding duplicate memory pairs, including optional LLM comparison.
    async def _find_duplicates_impl(
        min_similarity: float, max_similarity: float, limit: int, use_llm: bool
    ) -> Dict[str, Any]:
        from .storage import compare_memories_llm, connect, find_duplicate_candidates
    
        with connect() as conn:
            candidates = find_duplicate_candidates(conn, min_similarity, limit * 2)
    
        total_candidates = len(candidates)
        pairs = []
        llm_available = False
    
        for candidate in candidates[:limit]:
            mem_a = _get_memory(candidate["memory_a_id"])
            mem_b = _get_memory(candidate["memory_b_id"])
    
            if not mem_a or not mem_b:
                continue
    
            pair_result = {
                "memory_a": {
                    "id": mem_a["id"],
                    "preview": mem_a["content"][:150] + "..." if len(mem_a["content"]) > 150 else mem_a["content"],
                    "tags": mem_a.get("tags", []),
                },
                "memory_b": {
                    "id": mem_b["id"],
                    "preview": mem_b["content"][:150] + "..." if len(mem_b["content"]) > 150 else mem_b["content"],
                    "tags": mem_b.get("tags", []),
                },
                "similarity_score": round(candidate["similarity_score"], 3),
            }
    
            # Run LLM comparison if enabled
            if use_llm:
                llm_result = compare_memories_llm(
                    mem_a["content"],
                    mem_b["content"],
                    mem_a.get("metadata"),
                    mem_b.get("metadata"),
                )
                if llm_result:
                    llm_available = True
                    pair_result["llm_verdict"] = llm_result.get("verdict", "review")
                    pair_result["llm_confidence"] = llm_result.get("confidence", 0)
                    pair_result["llm_reasoning"] = llm_result.get("reasoning", "")
                    pair_result["suggested_action"] = llm_result.get("suggested_action", "review")
                    if llm_result.get("merge_suggestion"):
                        pair_result["merge_suggestion"] = llm_result["merge_suggestion"]
    
            pairs.append(pair_result)
    
        return {
            "pairs": pairs,
            "total_candidates": total_candidates,
            "analyzed": len(pairs),
            "llm_available": llm_available,
        }
  • The tool registration for 'memory_find_duplicates' which uses '_find_duplicates_impl' for its execution logic.
    async def memory_find_duplicates(
        min_similarity: float = 0.85,
        max_similarity: float = 1.0,
        limit: int = 10,
        use_llm: bool = True,
    ) -> Dict[str, Any]:
        """Find potential duplicate memory pairs with optional LLM-powered comparison.
    
        Scans cross-references to find memory pairs with similarity >= threshold,
        then optionally uses LLM to semantically compare them. Uses the same
        threshold (0.85) as the graph UI duplicate detection.
    
        Args:
            min_similarity: Minimum similarity score to consider (default: 0.85)
            max_similarity: Maximum similarity score (default: 1.0, kept for backward compatibility)
            limit: Maximum pairs to analyze (default: 10)
            use_llm: Whether to use LLM for semantic comparison (default: True)
    
        Returns:
            Dictionary with:
            - pairs: List of potential duplicate pairs with analysis
            - total_candidates: Total pairs found
            - analyzed: Number of pairs analyzed with LLM
            - llm_available: Whether LLM comparison was available
    
        Rate limited: 120s cooldown.
        """
        if msg := _check_tool_cooldown("memory_find_duplicates"):
            return {"error": "rate_limited", "message": msg}
        try:
            return await _find_duplicates_impl(min_similarity, max_similarity, limit, use_llm)
        finally:
            _finish_tool("memory_find_duplicates")
Behavior4/5

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

With no annotations provided, the description carries the full burden and successfully discloses the 120s rate limit cooldown, the two-phase processing approach (cross-reference scan followed by optional LLM analysis), and the complete return structure including `llm_available` flag. It does not clarify if the operation is read-only or has side effects.

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

Conciseness4/5

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

The description is well-structured with clear Args and Returns sections. Information is front-loaded with the core purpose in the first sentence. The rate limit warning appropriately appears at the end. It is slightly verbose but justifiably so given the need to document parameters and returns that the schema omits.

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 4 optional parameters and existing output schema, the description is nearly complete. It documents all inputs, explains the return dictionary structure (pairs, total_candidates, analyzed), and discloses rate limiting. It could be improved by noting whether results are cached or if the operation is idempotent.

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

Parameters5/5

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

Despite 0% schema description coverage (only titles like 'Min Similarity'), the description comprehensively documents all 4 parameters with semantic meaning, default values, and purpose (e.g., noting max_similarity is 'kept for backward compatibility'). This fully compensates for the schema's lack of descriptions.

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 finds duplicate memory pairs using LLM-powered comparison, with specific mechanism details (cross-references, threshold scanning). However, it does not explicitly distinguish this from sibling tools like `memory_merge` or `memory_semantic_search` beyond referencing the 'graph UI duplicate detection'.

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 outlines the workflow (scan cross-refs → semantic comparison) and mentions the 120s rate limit, implying it should not be used for real-time operations. However, it lacks explicit guidance on when to use this versus `memory_semantic_search` or prerequisites like 'use before memory_merge'.

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/agentic-box/memora'

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