The knowledge graph memory system provides advanced entity-relationship storage capabilities, enabling cipher to maintain and query complex interconnected knowledge structures. It manages nodes (entities) and edges (relationships) with support for multiple backends and sophisticated graph operations.
Knowledge graph is disabled by default. Set KNOWLEDGE_GRAPH_ENABLED=true to enable it.

Configuration

Environment Variables

Basic Configuration:
# Enable knowledge graph
KNOWLEDGE_GRAPH_ENABLED=true

# Backend type (neo4j or in-memory)
KNOWLEDGE_GRAPH_TYPE=neo4j

# Database name (for Neo4j)
KNOWLEDGE_GRAPH_DATABASE=cipher_knowledge
Neo4j Production Setup:
# Connection via host/port
KNOWLEDGE_GRAPH_HOST=localhost
KNOWLEDGE_GRAPH_PORT=7687
KNOWLEDGE_GRAPH_USERNAME=neo4j
KNOWLEDGE_GRAPH_PASSWORD=your_password

# Or connection via URI
KNOWLEDGE_GRAPH_URI=neo4j://localhost:7687
KNOWLEDGE_GRAPH_USERNAME=neo4j
KNOWLEDGE_GRAPH_PASSWORD=your_password
In-Memory Development Setup:
# Simple setup for development
KNOWLEDGE_GRAPH_ENABLED=true
KNOWLEDGE_GRAPH_TYPE=in-memory

# No additional configuration needed

cipher.yml Configuration

Neo4j Configuration:
memAgent:
  knowledgeGraph:
    type: neo4j
    host: localhost
    port: 7687
    username: neo4j
    password: your_password
    database: cipher_knowledge
    enableAutoIndexing: true
    enableMetrics: true
    enableQueryCache: true
    maxRetries: 3
    timeout: 30000
In-Memory Configuration:
memAgent:
  knowledgeGraph:
    type: in-memory
    maxNodes: 10000
    maxEdges: 50000
    enableIndexing: true
    enableGarbageCollection: false
    enableAutoIndexing: true
    defaultBatchSize: 1000

Knowledge Graph Architecture

The knowledge graph system manages complex entity-relationship structures through a sophisticated multi-layer architecture:

Tool Operation Flow

The knowledge graph tools follow a systematic approach to entity and relationship management:

Available Tools

The knowledge graph system provides 11 specialized tools for entity and relationship management:

Basic Operations

cipher_add_node

Creates new entities in the knowledge graph.

cipher_add_edge

Creates relationships between existing nodes.

cipher_update_node

Updates properties and labels of existing nodes.

cipher_delete_node

Removes nodes and their relationships from the graph.

Search and Query Operations

cipher_search_graph

Searches for nodes and edges with filtering capabilities.

cipher_get_neighbors

Gets neighboring nodes with relationship information.

cipher_query_graph

Executes custom queries against the knowledge graph.

Advanced Operations

cipher_extract_entities

Extracts entities from text and adds them to the knowledge graph.
Advanced search with semantic capabilities and fuzzy matching.

cipher_intelligent_processor

Intelligently processes natural language to manage entities and relationships.

cipher_relationship_manager

Manages complex relationship operations like entity replacement and merging.

Data Structures

GraphNode Structure

GraphEdge Structure

Common Labels and Edge Types

Examples

Best Practices

Tool Selection

  • Use cipher_enhanced_search for natural language queries, cipher_search_graph for structured searches
  • Use cipher_extract_entities for automatic entity extraction from text content
  • Use cipher_intelligent_processor for complex natural language operations

Entity Design

  • Meaningful IDs: Use descriptive identifiers (e.g., func_calculate_total, class_math_utils)
  • Multiple labels: Assign relevant labels for categorization (["Function", "Code", "TypeScript"])
  • Rich properties: Include metadata (file paths, timestamps, confidence scores)

Performance

  • Set limits: Always use appropriate limits (50-100 for searches, 10-25 for neighbors)
  • Neo4j for production: Use Neo4j backend for >1000 entities, in-memory for development
  • Enable debug logging: Set CIPHER_LOG_LEVEL=debug for detailed tool execution logs
Knowledge graph operations require both source and target nodes to exist before creating edges. Always verify node existence or use cipher_intelligent_processor for automatic entity creation.