Skip to main content

Relationships

Connect memories with typed relationships to build knowledge graphs.

What are Relationships?

Relationships connect memories to each other, creating a knowledge graph. Each relationship has a type (like "supports", "contradicts", or "references") and a weight that indicates its strength.

import { Trix } from '@trixdb/client';

const trix = new Trix({ apiKey: process.env.TRIX_API_KEY });

// Create a relationship between two memories
const relationship = await trix.relationships.create(
  sourceMemoryId,
  targetMemoryId,
  {
    relationshipType: 'supports',
    weight: 0.9,
    metadata: { context: 'research findings' }
  }
);

console.log(relationship.id); // rel_abc123...

Relationship Types

Trix supports several built-in relationship types:

  • related_to - Generic relationship
  • parent_of / child_of - Hierarchical relationships
  • supersedes - Source replaces or updates target
  • references - Source mentions or cites target
  • derived_from - Source was created based on target
  • contradicts - Source conflicts with target
  • supports - Source provides evidence for target
  • similar_to - Semantic similarity
  • depends_on - Source requires target
  • caused_by / leads_to - Causal relationships

Querying Relationships

Get incoming and outgoing relationships for a memory:

import { Trix } from '@trixdb/client';

const trix = new Trix({ apiKey: process.env.TRIX_API_KEY });

// Get all relationships for a memory
const outgoing = await trix.relationships.getOutgoing(memoryId);
const incoming = await trix.relationships.getIncoming(memoryId);

// Filter by type and minimum weight
const supports = outgoing.filter(r =>
  r.relationshipType === 'supports' && r.weight > 0.7
);

console.log(`Found ${supports.length} strong support relationships`);

Reinforcing Relationships

When memories are used together successfully, reinforce their relationships to increase weight:

import { Trix } from '@trixdb/client';

const trix = new Trix({ apiKey: process.env.TRIX_API_KEY });

// Reinforce a relationship (increases weight)
await trix.relationships.reinforce(relationshipId, {
  amount: 0.1
});

// Relationships that are frequently reinforced become stronger
// and surface more prominently in graph traversals

Relationship weights decay over time if not reinforced, mimicking how human memory connections weaken without use.

Graph Traversal

Traverse the knowledge graph to discover connected memories:

import { Trix } from '@trixdb/client';

const trix = new Trix({ apiKey: process.env.TRIX_API_KEY });

// Traverse from a starting memory
const result = await trix.graph.traverse({
  startNodeId: memoryId,
  maxDepth: 2,
  relationshipTypes: ['supports', 'references'],
  direction: 'both'
});

console.log(result.nodes);  // Connected memories
console.log(result.edges);  // Relationships between them

// Find shortest path between two memories
const path = await trix.graph.shortestPath(
  sourceId,
  targetId,
  { maxDepth: 5 }
);

Use Cases

  • Knowledge graphs - Connect related concepts and facts
  • Citation tracking - Link sources to derived content
  • Contradiction detection - Mark conflicting information
  • Dependency mapping - Track what information depends on what
  • Learning paths - Build prerequisite chains