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 relationshipparent_of/child_of- Hierarchical relationshipssupersedes- Source replaces or updates targetreferences- Source mentions or cites targetderived_from- Source was created based on targetcontradicts- Source conflicts with targetsupports- Source provides evidence for targetsimilar_to- Semantic similaritydepends_on- Source requires targetcaused_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 traversalsRelationship 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