/** * Knowledge Graph Database Operations * * Manages the knowledge graph for tribal knowledge storage. * Entities, relations, observations, decisions, and learnings * capture WHY connections were made and decisions were reached. */ import type Database from 'better-sqlite3'; import type { KnowledgeEntity, KnowledgeRelation, KnowledgeObservation, KnowledgeDecision, KnowledgeLearning, KnowledgeQueryOptions } from '../types/knowledge.js'; /** * Initialize all knowledge graph tables. * Called on first access to ensure tables exist. */ export declare function createKnowledgeSchema(db: Database.Database): void; /** * Create a new knowledge entity */ export declare function createEntity(name: string, entityType: string, id?: string): KnowledgeEntity; /** * Get an entity by name or ID */ export declare function getEntity(nameOrId: string): KnowledgeEntity | null; /** * Delete an entity and all its relations and observations */ export declare function deleteEntity(nameOrId: string): { deleted: boolean; relations_removed: number; observations_removed: number; }; /** * List all entities, optionally filtered by type */ export declare function listEntities(entityType?: string, limit?: number): KnowledgeEntity[]; /** * Create a relation between two entities */ export declare function createRelation(fromEntity: string, toEntity: string, relationType: string, reasoning?: string, confidence?: number, id?: string): KnowledgeRelation; /** * Get relations for an entity (both incoming and outgoing) */ export declare function getRelationsForEntity(entityName: string): { outgoing: KnowledgeRelation[]; incoming: KnowledgeRelation[]; }; /** * Get all relations, optionally filtered by type */ export declare function listRelations(relationType?: string, limit?: number): KnowledgeRelation[]; /** * Add an observation to an entity */ export declare function addObservation(entityName: string, observation: string, source?: string, confidence?: number, id?: string): KnowledgeObservation; /** * Get observations for an entity */ export declare function getObservationsForEntity(entityName: string): KnowledgeObservation[]; /** * Delete an observation by ID */ export declare function deleteObservation(obsId: string): boolean; /** * Log a decision with full context and reasoning */ export declare function logDecision(decisionType: string, context: string, decision: string, reasoning: string, entitiesInvolved?: string[], outcome?: string, sessionId?: string, id?: string): KnowledgeDecision; /** * Get decisions relevant to a context (uses FTS) */ export declare function getRelevantDecisions(contextQuery: string, options?: KnowledgeQueryOptions): KnowledgeDecision[]; /** * List decisions by type */ export declare function listDecisions(decisionType?: string, limit?: number): KnowledgeDecision[]; /** * Add a learning (pattern/insight) */ export declare function addLearning(learningType: string, title: string, insight: string, evidence?: string, applications?: string, id?: string): KnowledgeLearning; /** * Get learnings relevant to a task (uses FTS) */ export declare function getRelevantLearnings(taskQuery: string, options?: KnowledgeQueryOptions): KnowledgeLearning[]; /** * Increment the times_applied counter for a learning */ export declare function applyLearning(learningId: string): boolean; /** * List learnings by type or get most-applied */ export declare function listLearnings(learningType?: string, limit?: number): KnowledgeLearning[]; /** * Get the entire knowledge graph or a filtered subgraph */ export declare function readGraph(options?: KnowledgeQueryOptions): { entities: KnowledgeEntity[]; relations: KnowledgeRelation[]; observations: KnowledgeObservation[]; stats: { entities: number; relations: number; observations: number; }; }; /** * Get complete information about a specific entity */ export declare function openEntity(nameOrId: string): { entity: KnowledgeEntity | null; relations: { outgoing: KnowledgeRelation[]; incoming: KnowledgeRelation[]; }; observations: KnowledgeObservation[]; } | null; export interface SearchResult { type: 'entity' | 'relation' | 'observation' | 'decision' | 'learning'; id: string; name?: string; content: string; score?: number; } /** * Search across all knowledge types */ export declare function searchKnowledge(query: string, limit?: number): SearchResult[]; /** * Get knowledge graph statistics */ export declare function getKnowledgeStats(): { entities: number; relations: number; observations: number; decisions: number; learnings: number; entity_types: Array<{ type: string; count: number; }>; relation_types: Array<{ type: string; count: number; }>; decision_types: Array<{ type: string; count: number; }>; learning_types: Array<{ type: string; count: number; }>; };