/** * RAG Pipeline - Retrieval-Augmented Generation * * Full RAG implementation with document ingestion, retrieval, and context building. * * @example * ```typescript * import { RAGPipeline, Agent } from 'praisonai'; * * const rag = new RAGPipeline({ * embedder: async (text) => openai.embed(text), * vectorStore: pinecone * }); * * await rag.ingest('docs/', { recursive: true }); * * const agent = new Agent({ * augment: async (query) => rag.retrieve(query) * }); * ``` */ /** * RAG Document */ export interface RAGDocument { id: string; content: string; metadata: Record; embedding?: number[]; } /** * RAG Chunk */ export interface RAGChunk { id: string; docId: string; content: string; metadata: Record; embedding?: number[]; } /** * RAG Retrieval Result */ export interface RAGResult { id: string; content: string; score: number; source?: string; metadata?: Record; } /** * RAG Context */ export interface RAGContext { query: string; results: RAGResult[]; contextString: string; tokenCount?: number; } /** * Embedder function */ export type RAGEmbedder = (text: string) => Promise; /** * Vector store interface */ export interface RAGVectorStore { insert(id: string, vector: number[], metadata?: Record): Promise; search(vector: number[], topK?: number, filter?: any): Promise>; delete?(id: string): Promise; clear?(): Promise; } /** * Chunker function */ export type RAGChunker = (text: string, options?: { size?: number; overlap?: number; }) => string[]; /** * Reranker function */ export type RAGReranker = (query: string, results: RAGResult[]) => Promise; /** * RAG Pipeline Configuration */ export interface RAGPipelineConfig { /** Embedding function */ embedder?: RAGEmbedder; /** Vector store */ vectorStore?: RAGVectorStore; /** Chunking function */ chunker?: RAGChunker; /** Reranking function */ reranker?: RAGReranker; /** Chunk size */ chunkSize?: number; /** Chunk overlap */ chunkOverlap?: number; /** Default top K results */ topK?: number; /** Minimum score threshold */ minScore?: number; /** Maximum context tokens */ maxContextTokens?: number; } /** * In-memory vector store (for testing/simple use) */ export declare class MemoryVectorStore implements RAGVectorStore { private store; insert(id: string, vector: number[], metadata?: Record): Promise; search(vector: number[], topK?: number): Promise>; delete(id: string): Promise; clear(): Promise; private cosineSimilarity; } /** * RAGPipeline - Full RAG implementation */ export declare class RAGPipeline { readonly id: string; private config; private documents; private chunks; private inMemoryStore; constructor(config?: RAGPipelineConfig); /** * Ingest a document */ ingest(content: string, metadata?: Record): Promise; /** * Ingest multiple documents */ ingestMany(documents: Array<{ content: string; metadata?: Record; }>): Promise; /** * Retrieve relevant chunks */ retrieve(query: string, options?: { topK?: number; minScore?: number; filter?: any; }): Promise; /** * Build context from query */ buildContext(query: string, options?: { topK?: number; format?: 'plain' | 'numbered' | 'json'; }): Promise; /** * Query and augment - helper for agents */ augment(query: string, options?: { topK?: number; }): Promise; /** * Delete a document and its chunks */ deleteDocument(docId: string): Promise; /** * Clear all documents */ clear(): Promise; /** * Get stats */ getStats(): { documentCount: number; chunkCount: number; }; } /** * Create a RAG pipeline */ export declare function createRAGPipeline(config?: RAGPipelineConfig): RAGPipeline; /** * Create a simple RAG pipeline without embeddings (keyword only) */ export declare function createSimpleRAGPipeline(): RAGPipeline; export default RAGPipeline;