Skip to content

Quick RAG v1.1.0 - Query Explainability & Dynamic Prompts 🎉

Choose a tag to compare

@devemree devemree released this 05 Nov 12:06
· 52 commits to main since this release

Two industry-first features that make Quick RAG the most advanced RAG library for JavaScript!


🆕 What's New

🔍 Query Explainability

Understand WHY documents were retrieved - A capability not found in any other RAG library!

Now you can see detailed explanations for every retrieved document:

const results = await retriever.getRelevant('What is Ollama?', 3, {
  explain: true  // Enable explanations
});

// Each result includes:
{
  text: "Ollama is a local AI platform...",
  score: 0.856,
  explanation: {
    queryTerms: ["ollama", "local", "ai"],        // Extracted from query
    matchedTerms: ["ollama", "local"],            // Found in document  
    matchCount: 2,                                // Number of matches
    matchRatio: 0.67,                             // 67% coverage
    cosineSimilarity: 0.856,                      // Semantic similarity
    relevanceFactors: {
      termMatches: 2,
      semanticSimilarity: 0.856,
      coverage: "67%"
    }
  }
}

Use Cases:

  • 🐛 Debug unexpected search results
  • 📊 Understand semantic vs keyword matching
  • ✅ Validate retrieval accuracy
  • 📈 Optimize query quality
  • 💡 Explain results to end users

Example: example/08-explain-scores.js - Full demo with Ollama & LM Studio


🎨 Dynamic Prompt Management

10 built-in templates + full customization for perfect responses every time!

Built-in Templates

Choose from 10 professionally-crafted templates:

  • default - Standard RAG format
  • conversational - Chat-style responses
  • technical - Technical documentation format
  • academic - Research/scholarly style
  • code - Code-focused responses with examples
  • concise - Brief, to-the-point answers
  • detailed - Comprehensive, thorough responses
  • qa - Clean question-answer format
  • instructional - Step-by-step guides
  • creative - Creative writing style

Quick Usage

// 1. Simple template selection
await generateWithRAG(client, model, query, docs, {
  template: 'conversational'
});

// 2. Add system prompts
await generateWithRAG(client, model, query, docs, {
  systemPrompt: 'You are a helpful programming tutor',
  template: 'instructional'
});

// 3. Context formatting options
await generateWithRAG(client, model, query, docs, {
  context: {
    includeScores: true,      // Show similarity scores
    includeMetadata: true,    // Show document metadata
    maxLength: 500           // Limit context length
  }
});

Advanced: PromptManager

For reusable configurations:

import { createPromptManager } from 'quick-rag';

const promptMgr = createPromptManager({
  systemPrompt: 'You are an expert software engineer with 10 years experience',
  template: 'technical',
  variables: { company: 'TechCorp' }
});

// Add custom formatters
promptMgr.addContextFormatter('numbered', (context, docs) => {
  return docs.map((doc, i) => `${i + 1}. ${doc.text}`).join('\n');
});

// Use it
await generateWithRAG(client, model, query, docs, {
  promptManager: promptMgr
});

// Clone and modify
const tutorMode = promptMgr.clone({ 
  template: 'conversational',
  systemPrompt: 'You are a friendly tutor' 
});

Custom Templates

Full control with function-based templates:

const customTemplate = (query, context) => `
╔══════════════════════════════════════╗
║        KNOWLEDGE BASE QUERY          ║
╚══════════════════════════════════════╝

📚 Available Information:
${context}

❓ User Question:
${query}

💡 Expert Analysis:
`;

await generateWithRAG(client, model, query, docs, {
  template: customTemplate
});

Use Cases:

  • 🎭 Different response styles per feature
  • 👤 Role-based assistants (tutor, expert, analyst)
  • 🏢 Multi-tenant applications
  • 🧪 A/B test prompt effectiveness
  • 🎯 Domain-specific formatting

Example: example/09-prompt-management.js - Complete guide with all features


🔧 Improvements

  • Enhanced API: retriever.getRelevant() now accepts explain option
  • Enhanced API: generateWithRAG() now accepts full options parameter
  • Better Context: Automatic formatting of scores and metadata
  • Optional React: React imports no longer required for Node.js usage
  • Better Errors: More helpful error messages

📦 Installation

npm install quick-rag@1.1.0

Or update existing installation:

npm update quick-rag

🔄 Migration from v1.0.0

Zero breaking changes! All v1.0.0 code works unchanged. New features are opt-in:

// v1.0.0 - still works perfectly
const results = await retriever.getRelevant(query, 3);
await generateWithRAG(client, model, query, docs);

// v1.1.0 - enhanced with new options
const results = await retriever.getRelevant(query, 3, { explain: true });
await generateWithRAG(client, model, query, docs, { 
  template: 'conversational',
  systemPrompt: 'You are a helpful assistant'
});

✅ Testing

All features thoroughly tested:

  • ✅ Query Explainability with Ollama
  • ✅ Query Explainability with LM Studio
  • ✅ All 10 prompt templates
  • ✅ System prompts
  • ✅ Context formatting options
  • ✅ PromptManager functionality
  • ✅ Custom templates
  • ✅ Backward compatibility

Run tests yourself:

npm test

📚 Documentation


🎯 Why Quick RAG v1.1.0?

Unique Features

  • ✅ Query Explainability - Not found in LangChain, LlamaIndex, or any competitor
  • ✅ 10 Prompt Templates - Most flexible prompt system in any RAG library
  • ✅ PromptManager - Enterprise-grade prompt configuration
  • ✅ Full Customization - Function-based templates for unlimited flexibility

Production Ready

  • ✅ Official Ollama & LM Studio SDKs
  • ✅ Comprehensive testing
  • ✅ TypeScript support
  • ✅ Backward compatible
  • ✅ Clean, documented code

Developer Experience

  • ✅ Clear, helpful error messages
  • ✅ Complete examples for every feature
  • ✅ Well-documented API
  • ✅ Active development

🙏 Thank You

To all contributors and users who made this release possible! Your feedback drives innovation.

What's Next?

Vote on upcoming features:

  • Hybrid Search (BM25 + semantic)
  • Persistent Vector Store
  • Query Analytics & Insights
  • Multi-modal RAG (images, audio)
  • Streaming Explainability

Join the discussion on GitHub Issues!


📦 Full Changelog

See CHANGELOG.md for complete details.


Made with ❤️ for the JavaScript & AI community

Support: GitHub Issues
Docs: README.md
NPM: quick-rag

Full Changelog: v1.0.0...v1.1.0