docusaurus-openai-search
Version:
AI-powered search plugin for Docusaurus - extends Algolia search with intelligent keyword generation and RAG-based answers
196 lines (195 loc) • 5.7 kB
TypeScript
import { DocusaurusAISearchConfig } from '../types';
export interface SearchStep {
step: 'requesting-keywords' | 'keywords-received' | 'searching' | 'documents-found' | 'generating-answer' | 'multi-source-search' | 'aggregating-results' | 'complete';
message: string;
progress: number;
details?: {
keywords?: string[];
documentsFound?: number;
documentLinks?: string[];
sourcesFound?: {
[key: string]: number;
};
};
}
export interface DocumentContent {
url: string;
title: string;
content: string;
}
export interface MultiSourceResult {
source: 'documentation' | 'github' | 'blog' | 'changelog';
title: string;
url: string;
content: string;
metadata: {
weight: number;
timestamp?: string;
author?: string;
type?: string;
};
}
export interface AggregatedSearchResult {
answer: string;
sources: MultiSourceResult[];
aggregationMetrics: {
totalSources: number;
sourceBreakdown: Record<string, number>;
confidenceScore: number;
};
validation?: {
confidence?: string;
isNotFound?: boolean;
hasSources?: boolean;
score?: number;
qualityMetrics?: any;
warnings?: string[];
};
followUpQuestions?: string[];
sessionId?: string;
}
export interface ConversationTurn {
query: string;
answer: string;
timestamp: Date;
queryAnalysis?: any;
}
export interface SessionInfo {
sessionId: string;
createdAt: Date;
lastActiveAt: Date;
}
export declare class SearchOrchestrator {
private logger;
private config;
private onProgress?;
private recaptchaSiteKey?;
private abortController;
private pendingOperations;
private isDestroyed;
private currentSessionId;
constructor(config: DocusaurusAISearchConfig, onProgress?: (step: SearchStep) => void);
/**
* P3-002: Cancel all pending operations and cleanup resources
*/
cancelAllOperations(): void;
/**
* P3-002: Check if operations should be aborted due to race conditions
*/
private checkAborted;
/**
* P3-002: Track pending operation and handle completion
*/
private trackOperation;
/**
* Main orchestration method that performs AI-powered search
* Week 2 Enhancement: Returns validation data along with answer and documents
*/
performAISearch(query: string, algoliaClient: any, algoliaIndex: string): Promise<{
answer: string;
documents: DocumentContent[];
validation?: {
confidence?: string;
isNotFound?: boolean;
hasSources?: boolean;
score?: number;
qualityMetrics?: any;
warnings?: string[];
};
queryAnalysis?: {
type?: string;
intent?: string;
complexity?: string;
};
enhancement?: {
recursiveEnhanced?: boolean;
documentsAnalyzed?: number;
fineTunedModelUsed?: boolean;
};
}>;
/**
* P3-002: Enhanced get search keywords from backend with AbortController
*/
private getKeywordsFromBackend;
/**
* P3-002: Enhanced generate answer from backend using RAG with AbortController
* Week 2 Enhancement: Returns both answer and validation data
*/
private generateAnswerFromBackend;
/**
* Expand query with variations and synonyms for better search results
*/
private expandQuery;
/**
* P3-002: Enhanced perform a single search query with query expansion and abort checking
*/
private performSingleSearch;
/**
* Extract document content from search results with enhanced context
*/
private extractDocuments;
/**
* Update progress
*/
private updateProgress;
/**
* Stage 2: Enhanced AI search with multi-source capabilities
*/
performMultiSourceAISearch(query: string, searchClient: any, indexName: string, multiSourceConfig?: {
github?: {
repository: string;
};
blog?: {
url: string;
};
changelog?: {
url: string;
};
}): Promise<AggregatedSearchResult>;
/**
* Stage 2: Multi-source search backend integration
*/
private performMultiSourceSearch;
/**
* Week 6: Initialize a new conversation session
*/
private initializeSession;
/**
* Week 6: Get current session ID
*/
getSessionId(): string | null;
/**
* Week 6: Get conversation history for current session
*/
getConversationHistory(): Promise<ConversationTurn[]>;
/**
* Week 6: Enhanced AI search with conversational memory
*/
performConversationalAISearch(query: string, algoliaClient: any, algoliaIndex: string): Promise<{
answer: string;
documents: DocumentContent[];
validation?: {
confidence?: string;
isNotFound?: boolean;
hasSources?: boolean;
score?: number;
qualityMetrics?: any;
warnings?: string[];
};
queryAnalysis?: {
type?: string;
intent?: string;
complexity?: string;
};
followUpQuestions?: string[];
sessionId?: string;
}>;
/**
* Week 6: Generate answer with conversational memory
*/
private generateAnswerWithMemory;
/**
* Week 6: Generate follow-up questions for a given query and answer
*/
generateFollowUpQuestions(query: string, answer: string, queryAnalysis?: any): Promise<string[]>;
}