MemoryStackMemoryStack/Documentation
    Back to Documentation

    Knowledge Graph

    Memories aren't isolated - they're connected. The Knowledge Graph reveals relationships between memories, enabling your AI to make connections and discover insights.

    Watch Knowledge Graph Form in Real-Time

    User:"Hi, my name is Alex"
    Alex
    Alex
    First memory created - identity node

    See how each conversation builds your knowledge network progressively

    Connections are automatically discovered as memories are created

    What is a Knowledge Graph?

    A knowledge graph is a network of connected memories. Instead of storing memories in isolation, Memory OS automatically discovers and maintains relationships between them - just like how your brain connects related concepts.

    This enables powerful features like discovering related information, finding patterns, and understanding context.

    Isolated Memories

    Memory A: "User likes Python"
    Memory B: "Working on API project"
    Memory C: "Prefers FastAPI framework"

    No connections - each memory stands alone.

    Connected Knowledge Graph

    Memory A: "User likes Python"
    ↓ related_to
    Memory B: "Working on API project"
    ↓ uses
    Memory C: "Prefers FastAPI framework"

    Connected - the AI understands relationships and context.

    Types of Relationships

    Memory OS automatically detects and maintains different types of relationships between memories:

    Semantic Similarity

    Memories about similar topics are automatically connected based on meaning.

    "Python programming" ←→ "FastAPI framework" ←→ "API development"

    Temporal Connections

    Memories created around the same time or in sequence are linked.

    "Started project" → "First milestone" → "Project completed"

    Causal Relationships

    Cause-and-effect connections between memories and events.

    "User reported bug" → "Fixed authentication" → "Bug resolved"

    Entity Relationships

    Connections through shared entities (people, places, projects).

    All memories mentioning "Project Alpha" are connected

    Using the Knowledge Graph

    Exploring Connections

    from memory_os import MemoryOSClient
    
    memory = MemoryOSClient(
        api_key="your_api_key",
        user_id="user_123"
    )
    
    # Get a memory and its connections
    mem = memory.get_memory(memory_id="mem_123")
    
    # Explore related memories
    related = memory.get_related_memories(
        memory_id="mem_123",
        relationship_types=["similar", "temporal"],
        limit=10
    )
    
    # Process connections
    for rel in related['relationships']:
        print(f"Relationship: {rel['type']}")
        print(f"Connected to: {rel['target_memory']['content']}")
        print(f"Strength: {rel['strength']}")
        print("---")

    Graph Traversal

    # Find path between two memories
    path = memory.find_path(
        from_memory="mem_123",
        to_memory="mem_456",
        max_depth=3
    )
    
    # Discover clusters of related memories
    clusters = memory.find_clusters(
        min_cluster_size=5,
        similarity_threshold=0.7
    )
    
    # Get memory neighborhood
    neighborhood = memory.get_neighborhood(
        memory_id="mem_123",
        depth=2  # 2 hops away
    )
    
    # Visualize the graph
    graph_data = memory.export_graph(
        memory_ids=["mem_123", "mem_456", "mem_789"],
        include_connections=True
    )

    Pattern Discovery

    # Find patterns in the graph
    patterns = memory.discover_patterns(
        pattern_type="frequent_connections",
        min_support=3
    )
    
    # Identify central/important memories
    central_memories = memory.get_central_memories(
        metric="betweenness",  # or "degree", "pagerank"
        limit=10
    )
    
    # Find emerging topics
    topics = memory.detect_topics(
        time_window_days=30,
        min_memories=5
    )
    
    for topic in topics:
        print(f"Topic: {topic['name']}")
        print(f"Memories: {topic['memory_count']}")
        print(f"Keywords: {', '.join(topic['keywords'])}")

    Powerful Use Cases

    🔍Discovery & Recommendations

    "You asked about Python APIs. Based on your previous work with FastAPI and interest in authentication, you might want to explore OAuth2 implementation."

    How it works:
    The graph connects "Python" → "FastAPI" → "Authentication" → "OAuth2" to make intelligent suggestions.

    🧩Context Building

    When answering a question, the AI can pull in connected memories to provide richer, more contextual responses.

    Example:
    Question about "the project" automatically includes memories about Project Alpha, its timeline, team members, and current status.

    📊Pattern Recognition

    Identify recurring themes, common issues, or emerging trends across your memories.

    Insight:
    "You've asked about authentication 5 times this month, always related to API projects. Consider creating a reusable auth module."

    🎯Smart Navigation

    Navigate through your knowledge by following connections, discovering related information naturally.

    Flow:
    "Python" → "Web Frameworks" → "FastAPI" → "Documentation" → "OpenAPI Spec" - each step reveals related knowledge.

    Visualizing Your Knowledge

    Memory OS provides interactive graph visualizations in your dashboard. See your knowledge network, explore connections, and discover insights visually.

    Graph Features

    🎨 Visual Clustering
    Related memories are grouped by color and proximity
    🔍 Interactive Exploration
    Click nodes to explore connections and view details
    📊 Importance Sizing
    Node size reflects memory importance
    🎯 Filtered Views
    Filter by type, date, or custom criteria

    Best Practices

    ✅ Do

    • • Let the system auto-discover connections
    • • Use rich, descriptive memory content
    • • Explore related memories when searching
    • • Leverage graph insights for recommendations
    • • Visualize your knowledge periodically

    ❌ Don't

    • • Manually create all connections
    • • Ignore relationship suggestions
    • • Store isolated, context-free memories
    • • Overlook graph-based insights
    • • Forget to explore memory neighborhoods

    Next Steps