Skip to main content
The v2 search API is powerful and flexible, allowing for more precise memory retrieval. It supports complex logical operations (AND, OR, NOT) and comparison operators for advanced filtering capabilities. The comparison operators include:
  • in: Matches any of the values specified
  • gte: Greater than or equal to
  • lte: Less than or equal to
  • gt: Greater than
  • lt: Less than
  • ne: Not equal to
  • icontains: Case-insensitive containment check
  • *: Wildcard character that matches everything
    related_memories = m.search(
        query="What are Alice's hobbies?",
        version="v2",
        filters={
            "OR": [
                {
                  "user_id": "alice"
                },
                {
                  "agent_id": {"in": ["travel-agent", "sports-agent"]}
                }
            ]
        },
    )
    
    # Using wildcard to match all run_ids for a specific user
    all_memories = m.search(
        query="What are Alice's hobbies?",
        version="v2",
        filters={
            "AND": [
                {
                    "user_id": "alice"
                },
                {
                    "run_id": "*"
                }
            ]
        },
    )
    
    # Example 1: Using 'contains' for partial matching
    finance_memories = m.search(
        query="What are my financial goals?",
        version="v2",
        filters={
            "AND": [
                { "user_id": "alice" },
                {
                    "categories": {
                        "contains": "finance"
                    }
                }
            ]
        },
    )
    
    # Example 2: Using 'in' for exact matching
    personal_memories = m.search(
        query="What personal information do you have?",
        version="v2",
        filters={
            "AND": [
                { "user_id": "alice" },
                {
                    "categories": {
                        "in": ["personal_information"]
                    }
                }
            ]
        },
    )