Skip to main content

Working with Connections

Connections in EngramDB allow you to create graph-like relationships between memory nodes. This document explains how to work with connections effectively.

What are Connections?

A connection represents a relationship between two memory nodes. Each connection has:
  • A target memory node ID (the node being connected to)
  • A relationship type (e.g., Association, Causation, Sequence)
  • A strength value (between 0.0 and 1.0)
  • A creation timestamp
Connections enable EngramDB to model complex relationships between memories, forming a knowledge graph that can be traversed and queried.

Relationship Types

EngramDB provides several built-in relationship types:
  • Association: A general relationship between related concepts
  • Causation: A cause-effect relationship
  • Sequence: A temporal sequence or ordering
  • Hierarchy: A parent-child or category-subcategory relationship
  • Similarity: Indicates that two memories are similar
  • Opposition: Indicates that two memories are opposites or contradictory
  • Custom: User-defined relationship types

Creating Connections

You can create connections between memory nodes in two ways:
  1. Directly on a memory node
  2. Through the database API

Using the Memory Node API

Rust Example

Python Example

Using the Database API

Rust Example

Python Example

Retrieving Connections

You can retrieve the connections of a memory node in two ways:
  1. Directly from a memory node
  2. Through the database API

Using the Memory Node API

Rust Example

Python Example

Using the Database API

Rust Example

Python Example

Removing Connections

You can remove connections in two ways:
  1. Directly from a memory node
  2. Through the database API

Using the Memory Node API

Rust Example

Python Example

Using the Database API

Rust Example

Python Example

Use Cases for Connections

Knowledge Graphs

Connections can be used to build knowledge graphs that represent relationships between concepts.

Causal Chains

Connections can represent cause-effect relationships, forming causal chains.

Temporal Sequences

Connections can represent sequences of events or steps.

Graph Traversal

You can traverse the graph by following connections from one memory to another.

Rust Example

Python Example

Best Practices

When to Use Connections

Use connections when:
  1. You need to represent explicit relationships between memories
  2. You want to build a knowledge graph
  3. You need to model causal chains or sequences
  4. You want to represent hierarchical relationships

Connection Strength

The strength value (0.0 to 1.0) can be used to represent:
  1. The confidence in the relationship
  2. The importance of the relationship
  3. The strength of association between concepts
Use consistent semantics for strength values across your application.

Bidirectional Relationships

If you need bidirectional relationships, you must create two connections:

Custom Relationship Types

You can extend the built-in relationship types with custom ones:

Conclusion

Connections are a powerful feature of EngramDB that enable modeling complex relationships between memories. By effectively using connections, you can build rich knowledge graphs, causal chains, and temporal sequences that enhance the capabilities of your agent systems.