@codai/memorai-core
Version:
Simplified advanced memory engine - no tiers, just powerful semantic search with persistence
133 lines • 3.85 kB
TypeScript
/**
* Knowledge Graph Engine for Memorai
* Provides entity relationship management and graph-based memory operations
*/
export interface GraphEntity {
id: string;
name: string;
type: string;
properties: Record<string, unknown>;
createdAt: Date;
updatedAt: Date;
tenant_id: string;
agent_id?: string;
}
export interface GraphRelation {
id: string;
fromId: string;
toId: string;
type: string;
properties: Record<string, unknown>;
weight: number;
confidence: number;
createdAt: Date;
updatedAt: Date;
tenant_id: string;
agent_id?: string;
}
export interface GraphQuery {
entityTypes?: string[];
relationTypes?: string[];
properties?: Record<string, unknown>;
maxDepth?: number;
limit?: number;
tenant_id: string;
agent_id?: string;
}
export interface GraphPath {
entities: GraphEntity[];
relations: GraphRelation[];
totalWeight: number;
confidence: number;
}
export interface GraphAnalytics {
entityCount: number;
relationCount: number;
avgRelationsPerEntity: number;
strongestConnections: Array<{
from: string;
to: string;
weight: number;
}>;
entityTypeDistribution: Record<string, number>;
relationTypeDistribution: Record<string, number>;
clustersDetected: number;
centralEntities: Array<{
entity: GraphEntity;
centrality: number;
}>;
}
/**
* Advanced Knowledge Graph for entity-relationship memory storage
*/
export declare class KnowledgeGraph {
private entities;
private relations;
private entityRelations;
private relationIndex;
/**
* Add or update an entity in the knowledge graph
*/ addEntity(name: string, type: string, properties: Record<string, unknown>, tenant_id: string, agent_id?: string): Promise<string>;
/**
* Add a relation between two entities
*/ addRelation(fromId: string, toId: string, relationType: string, properties: Record<string, unknown> | undefined, weight: number | undefined, confidence: number | undefined, tenant_id: string, agent_id?: string): Promise<string>;
/**
* Find entities by criteria
*/
findEntities(query: GraphQuery): GraphEntity[];
/**
* Get a specific entity by ID
*/
getEntity(id: string): GraphEntity | null;
/**
* Get a specific relation by ID
*/
getRelation(id: string): GraphRelation | null;
/**
* Find relations based on query criteria
*/
findRelations(query: GraphQuery): GraphRelation[];
/**
* Find all paths between two entities
*/
findPaths(fromId: string, toId: string, maxDepth?: number): GraphPath[];
/**
* Find shortest path between two entities
*/
findShortestPath(fromId: string, toId: string, maxDepth?: number): GraphPath | null;
/**
* Get all connected entities within specified depth
*/
getConnectedEntities(entityId: string, maxDepth?: number): GraphEntity[];
/**
* Get graph analytics and insights
*/
getAnalytics(tenant_id: string, agent_id?: string): GraphAnalytics;
/**
* Remove an entity and all its relations
*/
removeEntity(entityId: string): Promise<boolean>;
/**
* Remove a specific relation
*/
removeRelation(relationId: string): Promise<boolean>;
/**
* Export graph data
*/
exportGraph(tenant_id: string, agent_id?: string): {
entities: GraphEntity[];
relations: GraphRelation[];
};
/**
* Import graph data
*/
importGraph(data: {
entities: GraphEntity[];
relations: GraphRelation[];
}): Promise<void>;
private findEntityByNameAndType;
private findExistingRelation;
private detectClusters;
private dfsCluster;
}
//# sourceMappingURL=KnowledgeGraph.d.ts.map