Language-first event graph system. Zero dependencies. <600 lines.
Extract relationships from text, find patterns, and navigate event chains - all in pure JavaScript.
npm install @terminals-tech/graphEvents are text. Text naturally forms graphs through language patterns (causal words, temporal markers, entity references). This package makes those implicit relationships explicit and queryable.
Instead of complex machine learning, we use simple text processing to extract tremendous value from your event data.
import { TextGraph, PatternMatcher, GraphProcessor } from '@terminals-tech/graph'
// Your events (from any source)
const events = [
{ id: '1', type: 'user-login', description: 'User logged in' },
{ id: '2', type: 'page-view', description: 'Dashboard opened after login' },
{ id: '3', type: 'error', description: 'Failed to load data due to timeout' },
{ id: '4', type: 'retry', description: 'System retried because of error' }
]
// Extract relationships from text
const textGraph = new TextGraph()
const graph = textGraph.buildGraph(events)
// Find what caused the error
const causes = textGraph.findCauses(graph, '3')
// Returns: events that led to the error
// Detect patterns
const matcher = new PatternMatcher()
const patterns = matcher.extractPatterns(events)
// Returns: common sequences like "login → dashboard → error"
// Scale to 100K+ events
const processor = new GraphProcessor()
events.forEach(e => processor.addEvent(e, []))
const important = processor.calculatePageRank()
// Returns: most important events by connectivityExtract causal chains, temporal sequences, and entity relationships from natural language:
const textGraph = new TextGraph()
// Automatically finds relationships like:
// "X caused Y" → causal edge
// "A then B" → temporal edge
// "C requires D" → dependency edge
const relations = textGraph.extractRelations(
"Settings failed to load due to network timeout"
)
// Returns: [{ type: 'causal', from: 'network timeout', to: 'failed to load' }]Find recurring patterns, detect anomalies, and predict likely next events:
const matcher = new PatternMatcher()
// Find patterns
const patterns = matcher.extractPatterns(events, 3) // 3-grams
// "login → browse → purchase" occurs 47 times
// Detect anomalies
const anomalies = matcher.detectAnomalies(events)
// "Direct purchase without browsing is unusual"
// Predict next
const predictions = matcher.predictNext(events)
// "85% chance user will click save"Handle 100K+ events with graph algorithms that run entirely in the browser:
const processor = new GraphProcessor()
// PageRank for importance
const important = processor.calculatePageRank()
// "Database connection lost" has highest impact
// Find clusters
const clusters = processor.findClusters()
// Discovers 12 independent workflows
// Navigate paths
const path = processor.findPath('login', 'purchase')
// Shows: login → browse → add-to-cart → checkout → purchase// What caused the crash?
const causes = textGraph.findCauses(graph, 'crash-event-id')
// What else was happening?
const context = processor.getSubgraph('crash-event-id', depth: 2)
// Is this pattern unusual?
const anomalies = matcher.detectAnomalies(eventsAroundCrash)// How do users get from A to B?
const paths = processor.findAllPaths('signup', 'first-purchase')
// What do successful users do differently?
const successPatterns = matcher.extractPatterns(successfulUsers)
const failurePatterns = matcher.extractPatterns(failedUsers)// Detect unusual patterns in real-time
eventStream.subscribe(event => {
const anomalies = matcher.detectAnomalies(recentEvents)
if (anomalies.length > 0) {
alert(`Unusual pattern: ${anomalies[0].reason}`)
}
})Works seamlessly with the Terminals event store:
import terminals from '@terminals-tech/core'
import { EventGraph } from '@terminals-tech/graph'
const term = terminals.init()
const graph = new EventGraph()
// Automatic graph building from event store
term.store.subscribe((event, state) => {
graph.processEvents(term.store.getEvents())
// Real-time insights
const predictions = graph.predictNext(term.store.getEvents())
console.log('Next likely:', predictions[0])
})- Phase 1: 0ms extraction (pure regex)
- Phase 2: 50ms for 10K events
- Phase 3: <1s for 100K events
- Memory: ~100 bytes per event
- Dependencies: Zero
extractRelations(text)- Find relationships in textbuildGraph(events)- Convert events to graphfindCauses(graph, eventId)- Find what caused an eventfindEffects(graph, eventId)- Find what an event caused
extractPatterns(events, n)- Find n-gram patternsdetectAnomalies(events)- Find unusual sequencespredictNext(events)- Predict likely next eventsfindCycles(events)- Find repeating patterns
addEvent(event, relations)- Add incrementallycalculatePageRank()- Find important nodesfindClusters()- Group related eventsfindPath(from, to)- Navigate between events
We believe that language is already the most sophisticated graph representation we have. Every sentence encodes nodes (entities), edges (relationships), and weights (emphasis).
By working with language directly instead of abstracting it into matrices, we get:
- Interpretability: Users can read the connections
- Editability: Users can modify relationships
- Composability: New events naturally integrate
- Zero-shot generalization: Works on any text
MIT © Intuition Labs
Built with ❤️ for developers who want insights from events without the complexity of machine learning.