import { EventEmitter } from 'events'; import { EmbeddingService } from './embedding-service'; import { KnowledgeGraph, KnowledgeNode } from './knowledge-graph'; /** * Structure of an FAQ entry */ export interface FAQEntry { id: string; question: string; answer: string; category?: string; tags?: string[]; createdAt: Date; updatedAt: Date; } /** * Structure of a document entry in the knowledge base */ export interface DocumentEntry { id: string; title: string; content: string; url?: string; source?: string; category?: string; tags?: string[]; createdAt: Date; updatedAt: Date; chunks?: DocumentChunk[]; } /** * Structure of a document chunk for long document handling */ export interface DocumentChunk { id: string; documentId: string; content: string; index: number; embedding?: number[]; } /** * Result of a knowledge base query */ export interface KnowledgeBaseQueryResult { entries: Array; relevanceScores: Map; sourceNodes?: KnowledgeNode[]; } /** * Configuration options for the KnowledgeBase */ export interface KnowledgeBaseConfig { persistPath?: string; graphPersistPath?: string; embeddingService?: EmbeddingService; autoSaveInterval?: number; maxResults?: number; relevanceThreshold?: number; enableChunking?: boolean; chunkSize?: number; chunkOverlap?: number; maxDocumentLength?: number; } /** * KnowledgeBase implementation that integrates with KnowledgeGraph for * storing and retrieving company-specific information */ export declare class KnowledgeBase extends EventEmitter { private faqs; private documents; private graph; private embeddingService; private faqEmbeddings; private documentEmbeddings; private documentChunkEmbeddings; private config; private dirty; private saveTimer; private initialized; constructor(config?: KnowledgeBaseConfig); /** * Initialize the knowledge base */ initialize(): Promise; /** * Process document content into chunks and generate embeddings */ private processDocumentChunks; /** * Split text into chunks for better embedding and retrieval */ private chunkText; /** * Add a new FAQ entry to the knowledge base */ addFAQ(question: string, answer: string, category?: string, tags?: string[]): Promise; /** * Add a new document to the knowledge base */ addDocument(title: string, content: string, url?: string, source?: string, category?: string, tags?: string[]): Promise; /** * Update an existing FAQ entry */ updateFAQ(id: string, updates: Partial>): Promise; /** * Update an existing document */ updateDocument(id: string, updates: Partial>): Promise; /** * Delete an FAQ entry */ deleteFAQ(id: string): boolean; /** * Delete a document */ deleteDocument(id: string): boolean; /** * Query the knowledge base for relevant information */ query(query: string, options?: { maxResults?: number; types?: Array<'faq' | 'document' | 'chunk'>; categories?: string[]; tags?: string[]; relevanceThreshold?: number; preferChunks?: boolean; }): Promise; /** * Find FAQs by category */ getFAQsByCategory(category: string): FAQEntry[]; /** * Find documents by category */ getDocumentsByCategory(category: string): DocumentEntry[]; /** * Find FAQs by tag */ getFAQsByTag(tag: string): FAQEntry[]; /** * Find documents by tag */ getDocumentsByTag(tag: string): DocumentEntry[]; /** * Ingest a bulk set of FAQs from a JSON array */ ingestFAQs(faqs: Array<{ question: string; answer: string; category?: string; tags?: string[]; }>): Promise; /** * Ingest a bulk set of documents from a JSON array */ ingestDocuments(documents: Array<{ title: string; content: string; url?: string; source?: string; category?: string; tags?: string[]; }>): Promise; /** * Generate context for agents by retrieving relevant information * from the knowledge base */ generateContext(query: string, options?: { maxResults?: number; types?: Array<'faq' | 'document' | 'chunk'>; categories?: string[]; tags?: string[]; relevanceThreshold?: number; format?: 'markdown' | 'text'; preferChunks?: boolean; }): Promise; /** * Mark the knowledge base as dirty and needing to be saved */ private markDirty; /** * Set up auto-save functionality */ private setupAutoSave; /** * Save the knowledge base to disk */ save(): boolean; /** * Load the knowledge base from disk */ load(): boolean; /** * Clear the entire knowledge base */ clear(): void; /** * Get statistics about the knowledge base */ getStats(): { faqCount: number; documentCount: number; chunkCount: number; averageChunksPerDocument: number; averageChunkSize: number; totalContentSize: number; graphStats: { nodeCount: number; relationshipCount: number; nodeTypes: string[]; relationshipTypes: string[]; }; categories: (string | undefined)[]; tags: string[]; }; /** * Get access to the underlying knowledge graph */ getGraph(): KnowledgeGraph; }