@juspay/neurolink
Version:
The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002
161 lines (160 loc) • 5.24 kB
TypeScript
/**
* RAG Pipeline Orchestrator
*
* Provides a complete end-to-end RAG pipeline that orchestrates:
* - Document loading and preprocessing
* - Chunking with configurable strategies
* - Embedding generation
* - Vector storage and retrieval
* - Context assembly for LLM queries
* - Response generation with citations
*
* @example
* ```typescript
* const pipeline = new RAGPipeline({
* vectorStore: myVectorStore,
* embeddingModel: { provider: 'openai', modelName: 'text-embedding-3-small' },
* generationModel: { provider: 'openai', modelName: 'gpt-4o-mini' }
* });
*
* // Ingest documents
* await pipeline.ingest(['/path/to/doc1.md', '/path/to/doc2.pdf']);
*
* // Query with RAG
* const response = await pipeline.query('What are the key features?');
* console.log(response.answer, response.sources);
* ```
*/
import type { RAGPipelineConfig, IngestOptions, QueryOptions, RAGResponse, PipelineStats, MultiModalRAGConfig, MultiModalQuery, MultiModalSearchResult, DecisionCallerFn } from "../../types/index.js";
import { MDocument } from "../document/MDocument.js";
export declare class RAGPipeline {
private id;
private config;
private vectorStore;
private bm25Index;
private graphRAG;
private embeddingProvider?;
private multiModalEmbeddingProvider?;
private generationProvider?;
/**
* Vision provider for image captioning, when `multiModal.captionProvider` /
* `captionModel` name one. Undefined means captioning uses
* {@link generationProvider} — captioning has always run on that provider,
* and these two fields were declared but read nowhere, so a caller who set
* them got the pipeline's generation model with no indication otherwise.
*/
private captionProvider?;
private hybridSearch?;
private documents;
private allChunks;
private multiModalConfig?;
private imageLoader;
constructor(config: RAGPipelineConfig);
/**
* Initialize the pipeline (lazy loading of providers)
*/
initialize(): Promise<void>;
/**
* Ingest documents into the pipeline
*
* @param sources - Array of file paths, URLs, or MDocument instances
* @param options - Ingestion options
*/
ingest(sources: Array<string | MDocument>, options?: IngestOptions): Promise<{
documentsProcessed: number;
chunksCreated: number;
}>;
/**
* Query the pipeline
*
* @param query - Search query
* @param options - Query options
* @returns RAG response with retrieved context and optional generated answer
*/
query(query: string, options?: QueryOptions): Promise<RAGResponse>;
/**
* Get pipeline statistics
*/
getStats(): PipelineStats;
/**
* Get pipeline ID
*/
getId(): string;
/**
* Clear all indexed data
*/
clear(): Promise<void>;
/**
* Ingest images into the pipeline for multi-modal RAG.
* Loads images, generates embeddings via the configured multi-modal provider,
* and stores them alongside text chunks in the vector store.
*
* @param sources - Array of image file paths, URLs, or Buffer objects
* @param options - Ingestion options
*/
ingestImages(sources: Array<string | Buffer>, options?: IngestOptions): Promise<{
imagesProcessed: number;
chunksCreated: number;
}>;
/**
* Query the pipeline with multi-modal input (text, image, or both).
*
* @param query - Text, image, or combined query
* @param options - Query options
* @returns Array of multi-modal search results
*/
queryMultiModal(query: MultiModalQuery, options?: QueryOptions): Promise<MultiModalSearchResult[]>;
/**
* Get multi-modal pipeline statistics
*/
getMultiModalStats(): {
totalImages: number;
totalTextChunks: number;
multiModalEnabled: boolean;
};
/**
* Generate a multi-modal embedding for text, image, or both.
* Uses the configured multi-modal embedding provider (e.g. Bedrock Titan Image).
*/
private generateMultiModalEmbedding;
/**
* Generate a caption for an image using the generation provider's vision model.
*/
private generateImageCaption;
/**
* Diversify multi-modal results to ensure a mix of text and image results.
*/
private diversifyMultiModalResults;
/**
* Ensure pipeline is initialized
*/
private ensureInitialized;
/**
* Generate embedding for text
*/
private generateEmbedding;
/**
* Assemble context from results
*/
private assembleContext;
/**
* Generate answer using LLM
*/
private generateAnswer;
}
/**
* Create a simple RAG pipeline with sensible defaults
*
* @param options - Basic configuration options
* @returns Configured RAGPipeline instance
*/
export declare function createRAGPipeline(options: {
provider?: string;
embeddingModel?: string;
generationModel?: string;
enableHybrid?: boolean;
enableGraph?: boolean;
multiModal?: MultiModalRAGConfig;
/** Fail-open decision caller for per-query retrieval planning. */
decide?: DecisionCallerFn;
}): RAGPipeline;