/** * Query Engine - Semantic and hybrid search for knowledge retrieval * * Provides unified search interface for RAG applications. * * @example * ```typescript * import { QueryEngine, Agent } from 'praisonai'; * * const engine = new QueryEngine({ * embedder: async (text) => embeddings.embed(text), * vectorStore: vectorStore * }); * * const results = await engine.query('What is PraisonAI?', { topK: 5 }); * ``` */ /** * Query result item */ export interface QueryResult { /** Document ID */ id: string; /** Document content */ content: string; /** Relevance score (0-1) */ score: number; /** Document metadata */ metadata?: Record; /** Source information */ source?: string; } /** * Query options */ export interface QueryOptions { /** Number of results to return */ topK?: number; /** Minimum score threshold */ minScore?: number; /** Filter by metadata */ filter?: Record; /** Search mode */ mode?: 'semantic' | 'keyword' | 'hybrid'; /** Rerank results */ rerank?: boolean; /** Include document content */ includeContent?: boolean; } /** * Embedder function type */ export type EmbedderFn = (text: string) => Promise; /** * Vector store interface (minimal) */ export interface VectorStoreInterface { query(vector: number[], options?: { topK?: number; filter?: any; }): Promise; content?: string; }>>; search?(query: string, options?: { topK?: number; }): Promise; } /** * Query engine configuration */ export interface QueryEngineConfig { /** Embedding function */ embedder?: EmbedderFn; /** Vector store for semantic search */ vectorStore?: VectorStoreInterface; /** Keyword search function */ keywordSearch?: (query: string, options?: QueryOptions) => Promise; /** Reranker function */ reranker?: (query: string, results: QueryResult[]) => Promise; /** Default options */ defaultOptions?: QueryOptions; } /** * QueryEngine - Unified search for knowledge retrieval */ export declare class QueryEngine { readonly id: string; private config; private cache; private cacheMaxAge; constructor(config?: QueryEngineConfig); /** * Semantic search using embeddings */ semanticSearch(query: string, options?: QueryOptions): Promise; /** * Keyword search */ keywordSearch(query: string, options?: QueryOptions): Promise; /** * Hybrid search combining semantic and keyword */ hybridSearch(query: string, options?: QueryOptions): Promise; /** * Main query method - routes to appropriate search type */ query(query: string, options?: QueryOptions): Promise; /** * Query and return formatted context string */ queryForContext(query: string, options?: QueryOptions): Promise; /** * Clear the query cache */ clearCache(): void; /** * Set cache max age */ setCacheMaxAge(ms: number): void; } /** * Create a query engine */ export declare function createQueryEngine(config?: QueryEngineConfig): QueryEngine; /** * Create a simple in-memory query engine for testing */ export declare function createSimpleQueryEngine(documents: Array<{ id: string; content: string; metadata?: any; }>): QueryEngine; export default QueryEngine;