UNPKG

@dooor-ai/toolkit

Version:

Guards, Evals & Observability for AI applications - works seamlessly with LangChain/LangGraph

51 lines (50 loc) 2.03 kB
"use strict"; /** * RAGContext class for DOOOR AI Toolkit * Allows users to pass ephemeral documents, files, or embeddings for RAG */ Object.defineProperty(exports, "__esModule", { value: true }); exports.RAGContext = void 0; const types_1 = require("./types"); class RAGContext { constructor(config) { this.files = config.files || []; this.documents = config.documents || []; this.embeddings = config.embeddings || []; if (!config.embeddingProvider) { throw new Error("embeddingProvider is required. Please configure an embedding provider at /settings/embeddings " + "and pass its internal name (e.g., 'prod-gemini', 'myGemini')"); } this.embeddingProvider = config.embeddingProvider; this.strategy = config.strategy || types_1.RAGStrategy.SIMPLE; this.topK = config.topK || 5; this.chunkSize = config.chunkSize || 1000; this.chunkOverlap = config.chunkOverlap || 200; this.similarityThreshold = config.similarityThreshold || 0.7; // Validate at least one source is provided if (this.files.length === 0 && this.documents.length === 0 && this.embeddings.length === 0) { throw new Error("RAGContext requires at least one source: files, documents, or embeddings"); } } /** * Serialize RAGContext to JSON for API request */ toJSON() { return { files: this.files.map(f => ({ name: f.name, data: Buffer.isBuffer(f.data) ? f.data.toString('base64') : f.data, type: f.type, })), documents: this.documents, embeddings: this.embeddings, embedding_provider: this.embeddingProvider, strategy: this.strategy, top_k: this.topK, chunk_size: this.chunkSize, chunk_overlap: this.chunkOverlap, similarity_threshold: this.similarityThreshold, }; } } exports.RAGContext = RAGContext;