This document describes the Neo4j database schema used by MemoryGraph.
The core node type representing a stored memory.
Labels: Memory
Properties:
id(string, unique) - Unique identifier for the memorytype(string) - Type of memory (see MemoryType enum)title(string) - Short descriptive titlecontent(string) - Detailed memory contentsummary(string, optional) - Brief summarytags(array of strings) - Categorization tagsimportance(float, 0.0-1.0) - Importance scoreconfidence(float, 0.0-1.0) - Confidence in the memoryeffectiveness(float, 0.0-1.0, optional) - How effective this memory has beenusage_count(integer) - Number of times this memory has been accessedcreated_at(ISO datetime string) - When the memory was createdupdated_at(ISO datetime string) - When the memory was last updatedlast_accessed(ISO datetime string, optional) - When the memory was last accessed
Context Properties: (prefixed with context_)
context_project_path(string, optional) - Project directory pathcontext_files_involved(string, optional) - JSON array of involved filescontext_languages(string, optional) - JSON array of programming languagescontext_frameworks(string, optional) - JSON array of frameworks usedcontext_technologies(string, optional) - JSON array of technologiescontext_git_commit(string, optional) - Git commit hashcontext_git_branch(string, optional) - Git branch namecontext_working_directory(string, optional) - Working directorycontext_timestamp(ISO datetime string, optional) - Context timestampcontext_session_id(string, optional) - Session identifiercontext_user_id(string, optional) - User identifier
The system supports the following memory types:
task- Development tasks and their executioncode_pattern- Reusable code patterns and solutionsproblem- Issues and problems encounteredsolution- Solutions to problemsproject- Project-specific context and knowledgetechnology- Technology, framework, and tool knowledgeerror- Error messages and their contextfix- Fixes applied to resolve errorscommand- CLI commands and their usagefile_context- File-specific context and knowledgeworkflow- Development workflow patternsgeneral- General development knowledge
Represent cause-and-effect relationships:
CAUSES- One thing causes anotherTRIGGERS- One thing triggers anotherLEADS_TO- One thing leads to anotherPREVENTS- One thing prevents anotherBREAKS- One thing breaks another
Represent problem-solving relationships:
SOLVES- A solution solves a problemADDRESSES- A solution partially addresses a problemALTERNATIVE_TO- Different approaches to the same problemIMPROVES- An enhancement to an existing solutionREPLACES- A new solution that replaces an old one
Represent contextual connections:
OCCURS_IN- Something occurs in a specific contextAPPLIES_TO- Something applies to a specific situationWORKS_WITH- Things that work well togetherREQUIRES- Dependencies between conceptsUSED_IN- Usage relationships
Represent knowledge building:
BUILDS_ON- Knowledge that builds on previous knowledgeCONTRADICTS- Conflicting informationCONFIRMS- Confirming evidenceGENERALIZES- Specific cases that generalize to patternsSPECIALIZES- General patterns specialized for specific cases
Represent similarity and analogy:
SIMILAR_TO- Similar concepts or solutionsVARIANT_OF- Variations of the same conceptRELATED_TO- General relatednessANALOGY_TO- Analogous situationsOPPOSITE_OF- Contrasting approaches
Represent process and workflow connections:
FOLLOWS- Sequential order in workflowsDEPENDS_ON- Dependencies in task executionENABLES- One thing enables anotherBLOCKS- One thing blocks anotherPARALLEL_TO- Things that can be done in parallel
Represent effectiveness and preference:
EFFECTIVE_FOR- Effectiveness in specific contextsINEFFECTIVE_FOR- Known ineffectivenessPREFERRED_OVER- Preference relationshipsDEPRECATED_BY- Replacement relationshipsVALIDATED_BY- Validation relationships
All relationships can have the following properties:
id(string, unique) - Unique identifier for the relationshipstrength(float, 0.0-1.0) - Strength of the relationshipconfidence(float, 0.0-1.0) - Confidence in the relationshipcontext(string, optional) - Context descriptionevidence_count(integer) - Number of supporting observationssuccess_rate(float, 0.0-1.0, optional) - Success rate for effectiveness relationshipscreated_at(ISO datetime string) - When the relationship was createdlast_validated(ISO datetime string) - When the relationship was last validatedvalidation_count(integer) - Number of times the relationship was validatedcounter_evidence_count(integer) - Number of counter-examples
CREATE CONSTRAINT memory_id_unique IF NOT EXISTS FOR (m:Memory) REQUIRE m.id IS UNIQUE;
CREATE CONSTRAINT relationship_id_unique IF NOT EXISTS FOR (r:RELATIONSHIP) REQUIRE r.id IS UNIQUE;-- Type-based filtering
CREATE INDEX memory_type_index IF NOT EXISTS FOR (m:Memory) ON (m.type);
-- Temporal queries
CREATE INDEX memory_created_at_index IF NOT EXISTS FOR (m:Memory) ON (m.created_at);
-- Tag-based search
CREATE INDEX memory_tags_index IF NOT EXISTS FOR (m:Memory) ON (m.tags);
-- Full-text search
CREATE FULLTEXT INDEX memory_content_index IF NOT EXISTS FOR (m:Memory) ON EACH [m.title, m.content, m.summary];
-- Quality-based filtering
CREATE INDEX memory_importance_index IF NOT EXISTS FOR (m:Memory) ON (m.importance);
CREATE INDEX memory_confidence_index IF NOT EXISTS FOR (m:Memory) ON (m.confidence);
-- Context-based queries
CREATE INDEX memory_project_path_index IF NOT EXISTS FOR (m:Memory) ON (m.context_project_path);MERGE (m:Memory {id: $id})
SET m += $properties
RETURN m.id as idMATCH (m:Memory)
WHERE m.title CONTAINS $query OR m.content CONTAINS $query
AND m.type IN $memory_types
AND m.importance >= $min_importance
RETURN m
ORDER BY m.importance DESC, m.created_at DESC
LIMIT $limitMATCH (from:Memory {id: $from_id})
MATCH (to:Memory {id: $to_id})
CREATE (from)-[r:SOLVES $properties]->(to)
RETURN r.id as idMATCH (start:Memory {id: $memory_id})
MATCH (start)-[r*1..2]-(related:Memory)
WHERE related.id <> start.id
RETURN DISTINCT related, r[0] as relationship
ORDER BY r[0].strength DESC, related.importance DESC
LIMIT 20- Indexing Strategy: All frequently queried properties are indexed
- Full-text Search: Enabled for content-based queries
- Relationship Traversal: Limited depth to prevent expensive queries
- Query Optimization: Use parameterized queries and appropriate LIMIT clauses
- Connection Pooling: Configured for optimal performance under load
The schema is designed to be extensible:
- New Memory Types: Can be added by extending the MemoryType enum
- New Relationship Types: Can be added by extending the RelationshipType enum
- Additional Properties: Can be added to nodes and relationships as needed
- New Indexes: Can be created for new query patterns
All data is validated at the application layer using Pydantic models before being stored in Neo4j. This ensures:
- Type Safety: All properties have correct types
- Constraints: Required fields are present and within valid ranges
- Consistency: Relationships reference valid memory IDs
- Normalization: Text fields are properly formatted and normalized