DAG-FS Examples

Practical examples and use cases for DAG-FS filesystem

Basic Pattern Operations

Example 1: Creating a Memory Pattern

// Store a memory with contextual tags
const char *memory_data = "First day of school, smelled chalk, felt happy";
const char *tags = "first day of school";

pattern_id_t memory = dagfs_create_pattern(
    tags,
    memory_data,
    strlen(memory_data)
);

// Add more tags for better recall
dagfs_add_tag(memory, "chalk");
dagfs_add_tag(memory, "happy");
dagfs_add_tag(memory, "childhood");
dagfs_add_tag(memory, "school");

Example 2: Recalling a Memory

// Query by any tag
pattern_id_t memory = dagfs_query_by_tag("first day of school");

if (memory != 0) {
    // Read pattern (reconstructs from weights, strengthens memory!)
    void *data = dagfs_read_pattern(memory);
    
    // Pattern is now stronger due to reconsolidation
    // Just like accessing a memory in the brain!
}

Example 3: Pattern Completion

// Complete pattern from partial cue
char partial[] = "first day";
char output[1024];

int bytes = dagfs_complete_pattern(
    memory,              // Pattern ID
    partial,             // Partial input
    strlen(partial),     // Input length
    output,              // Output buffer
    sizeof(output)       // Buffer size
);

// Output now contains: "First day of school, smelled chalk, felt happy"
// Pattern was strengthened during completion (reconsolidation)

Advanced Patterns

Example 4: Associating Related Memories

// Create multiple related patterns
pattern_id_t school_memory = dagfs_create_pattern("school", school_data, len1);
pattern_id_t teacher_memory = dagfs_create_pattern("teacher", teacher_data, len2);
pattern_id_t friend_memory = dagfs_create_pattern("friend", friend_data, len3);

// Link them together (strengthens all)
dagfs_associate_patterns(school_memory, teacher_memory);
dagfs_associate_patterns(school_memory, friend_memory);
dagfs_associate_patterns(teacher_memory, friend_memory);

// Now accessing one can trigger recall of associated memories

Example 5: Updating a Memory

// Update memory with new information (Hebbian learning)
const char *updated_data = "First day of school, smelled chalk, felt happy, met teacher";

dagfs_write_pattern(memory, updated_data, strlen(updated_data));

// Weights are updated, pattern strength increases
// Memory is now "stronger" and includes new information

Example 6: Forgetting a Memory

// Delete pattern (forgetting - weakens weights)
dagfs_delete_pattern(memory);

// Weights are weakened by ~10% (Long-Term Depression)
// Pattern fades away over time
// Can be "forgotten" completely if deleted multiple times

Real-World Use Cases

Use Case 1: Command History

// Store command with context
pattern_id_t cmd = dagfs_create_pattern(
    "command history",
    command_string,
    strlen(command_string)
);

dagfs_add_tag(cmd, "shell");
dagfs_add_tag(cmd, "user input");

// Later, recall by context
pattern_id_t found = dagfs_query_by_tag("command history");
void *cmd_data = dagfs_read_pattern(found);
// Command is recalled and strengthened

Use Case 2: Learned Behaviors

// Store learned behavior pattern
pattern_id_t behavior = dagfs_create_pattern(
    "learned behavior",
    behavior_data,
    behavior_len
);

dagfs_add_tag(behavior, "automated");
dagfs_add_tag(behavior, "response");

// Access strengthens the behavior (more likely to repeat)

Use Case 3: Contextual Knowledge

// Store knowledge with multiple tags
pattern_id_t knowledge = dagfs_create_pattern(
    "knowledge base",
    knowledge_data,
    knowledge_len
);

// Rich tagging for flexible recall
dagfs_add_tag(knowledge, "science");
dagfs_add_tag(knowledge, "biology");
dagfs_add_tag(knowledge, "neural networks");
dagfs_add_tag(knowledge, "memory");

// Can be recalled by any tag
pattern_id_t found = dagfs_query_by_tag("neural networks");

Pattern Lifecycle

Complete Lifecycle Example

// 1. CREATE: Store new pattern
pattern_id_t pattern = dagfs_create_pattern("new memory", data, len);
dagfs_add_tag(pattern, "important");
dagfs_add_tag(pattern, "recent");

// 2. READ: Access pattern (strengthens it)
void *data = dagfs_read_pattern(pattern);
// Pattern strength increased, access count incremented

// 3. UPDATE: Modify pattern (Hebbian learning)
dagfs_write_pattern(pattern, new_data, new_len);
// Weights updated, pattern strengthened further

// 4. ASSOCIATE: Link with other patterns
dagfs_associate_patterns(pattern, related_pattern);
// Both patterns strengthened

// 5. COMPLETE: Recall from partial input
dagfs_complete_pattern(pattern, partial, partial_len, output, output_size);
// Full pattern reconstructed, strengthened again

// 6. DELETE: Forget pattern (LTD)
dagfs_delete_pattern(pattern);
// Weights weakened, pattern fades away

Best Practices

Tagging Strategy

  • Use descriptive tags: "first day of school" is better than "memory1"
  • Multiple tags: Add several tags for flexible recall
  • Hierarchical tags: Use tags like "science.biology.neural" for organization
  • Context tags: Include emotional/contextual tags ("happy", "important")

Pattern Management

  • Regular access: Frequently accessed patterns stay strong
  • Association: Link related patterns for better recall
  • Cleanup: Delete unused patterns to free resources
  • Completion: Use pattern completion for partial recall

Performance Tips

  • Batch operations: Create multiple patterns before querying
  • Tag indexing: Use specific tags for faster lookup
  • Pattern reuse: Access existing patterns rather than recreating
  • Memory management: Monitor pattern count (max 1024)

Common Patterns

Pattern: Store and Recall

// Store
pattern_id_t p = dagfs_create_pattern(tags, data, len);

// Recall
void *recalled = dagfs_read_pattern(p);

Pattern: Query and Complete

// Query
pattern_id_t p = dagfs_query_by_tag("context");

// Complete from partial
dagfs_complete_pattern(p, partial, partial_len, output, output_size);

Pattern: Update and Strengthen

// Update
dagfs_write_pattern(p, new_data, new_len);

// Strengthen by reading
dagfs_read_pattern(p);

See Also