import { EventEmitter } from 'events'; /** * Represents a node in the knowledge graph */ export interface KnowledgeNode { id: string; type: string; label: string; properties: Record; createdAt: Date; updatedAt: Date; } /** * Represents a relationship between two nodes in the knowledge graph */ export interface KnowledgeRelationship { id: string; type: string; sourceId: string; targetId: string; properties: Record; weight: number; createdAt: Date; updatedAt: Date; } /** * Configuration options for the KnowledgeGraph */ export interface KnowledgeGraphConfig { persistPath?: string; autoSaveInterval?: number; maxRelationshipWeight?: number; defaultRelationshipWeight?: number; } /** * Result of a knowledge graph query */ export interface KnowledgeGraphQueryResult { nodes: KnowledgeNode[]; relationships: KnowledgeRelationship[]; relevanceScore: number; } /** * A knowledge graph implementation that stores entities and their relationships */ export declare class KnowledgeGraph extends EventEmitter { private nodes; private relationships; private nodesByType; private nodesByLabel; private relationshipsByType; private relationshipsBySource; private relationshipsByTarget; private config; private dirty; private saveTimer; constructor(config?: KnowledgeGraphConfig); /** * Initialize indexes for efficient graph traversal */ private initializeIndexes; /** * Index a node for faster lookup */ private indexNode; /** * Index a relationship for faster lookup */ private indexRelationship; /** * Create a new node in the knowledge graph */ createNode(type: string, label: string, properties?: Record): KnowledgeNode; /** * Create a relationship between two nodes */ createRelationship(sourceId: string, targetId: string, type: string, properties?: Record, weight?: number): KnowledgeRelationship; /** * Get a node by its ID */ getNode(id: string): KnowledgeNode | undefined; /** * Get a relationship by its ID */ getRelationship(id: string): KnowledgeRelationship | undefined; /** * Find nodes by exact type and label match */ findNodes(type?: string, label?: string): KnowledgeNode[]; /** * Find relationships by type */ findRelationships(type?: string): KnowledgeRelationship[]; /** * Get all relationships where the specified node is the source */ getOutgoingRelationships(nodeId: string): KnowledgeRelationship[]; /** * Get all relationships where the specified node is the target */ getIncomingRelationships(nodeId: string): KnowledgeRelationship[]; /** * Get all nodes connected to a specific node */ getConnectedNodes(nodeId: string): KnowledgeNode[]; /** * Perform a breadth-first search starting from a node * @param startNodeId The ID of the starting node * @param maxDepth Maximum traversal depth * @param filter Optional filter function for relationships to traverse */ traverseGraph(startNodeId: string, maxDepth?: number, filter?: (relationship: KnowledgeRelationship) => boolean): KnowledgeGraphQueryResult; /** * Find path between two nodes (uses Dijkstra's algorithm) */ findPath(sourceId: string, targetId: string): KnowledgeRelationship[] | null; /** * Update an existing node */ updateNode(id: string, updates: Partial>): KnowledgeNode; /** * Update an existing relationship */ updateRelationship(id: string, updates: Partial>): KnowledgeRelationship; /** * Delete a node and all its relationships */ deleteNode(id: string): boolean; /** * Delete a relationship */ deleteRelationship(id: string): boolean; /** * Mark the graph as dirty and needing to be saved */ private markDirty; /** * Set up auto-save functionality */ private setupAutoSave; /** * Save the knowledge graph to disk */ save(): boolean; /** * Load the knowledge graph from disk */ load(): boolean; /** * Clear the entire knowledge graph */ clear(): void; /** * Get statistics about the knowledge graph */ getStats(): { nodeCount: number; relationshipCount: number; nodeTypes: string[]; relationshipTypes: string[]; }; }