Skip to content

Repository files navigation

Advanced RAG Demo 🚀

CILicense: MITNode.js VersionTypeScript

A production-ready Retrieval-Augmented Generation (RAG) system demonstrating cutting-edge techniques for semantic search, document retrieval, and AI-powered question answering.

✨ What's New

  • Enhanced UI: Proper markdown rendering with syntax highlighting and formatted citations
  • Flexible Document Ingestion: Support for PDF, Markdown, JSON, CSV, and HTML files
  • Improved Relevance: Hybrid search combining vector and keyword matching
  • Real Document Support: Ingest your own documents or use high-quality samples
  • Production Ready: Docker Compose setup, health checks, and monitoring tools

🎯 Live Features

Core RAG Capabilities

  • Hybrid Search: Combines vector similarity and keyword matching (configurable alpha)
  • Query Expansion: Automatically expands queries for comprehensive coverage
  • Cross-Encoder Reranking: Cohere's reranking for 40-50% better precision
  • Adaptive Chunking: Smart document splitting with configurable size and overlap
  • Streaming Responses: Real-time streaming with live markdown rendering

Advanced Features

  • Multiple Data Sources: Ingest from local files, URLs, or use sample data
  • Performance Metrics: Detailed timing for retrieval, reranking, and generation
  • Configuration Comparison: Side-by-side testing of different RAG configurations
  • Citation Tracking: Automatic source attribution with relevance scores
  • Qdrant Dashboard: Visual exploration of vector embeddings at http://localhost:6333/dashboard

🛠 Tech Stack

ComponentTechnologyPurpose
LLMOpenAI GPT-4 TurboAnswer generation
EmbeddingsOpenAI text-embedding-3Semantic search
Vector DatabaseQdrantVector storage & retrieval
RerankingCohere Rerank v3Result refinement
FrameworkLangChainRAG pipeline orchestration
BackendNode.js + TypeScriptServer implementation
FrontendVanilla JS + Marked.jsInteractive UI

🚀 Quick Start

Option 1: Full Setup with Real Data (Recommended)

# Clone repository
git clone https://github.com/hew/advanced-rag-demo.git
cd advanced-rag-demo
# Install dependencies
npm install
# Start Qdrant with Docker
npm run qdrant:setup
# Or manually: docker-compose up -d qdrant# Configure API keys
cp .env.example .env
# Edit .env with your OpenAI and Cohere API keys# Ingest documents
npm run ingest:files # Your documents from ./documents/# Or use samples: npm run ingest:sample# Start the server
npm run dev
# Open browser
open http://localhost:3000

Option 2: Mock Mode (No API Keys Required)

# Quick test without setup
MOCK_MODE=true npm run dev

📁 Document Ingestion

Supported Formats

  • Text: .txt, .md, .markdown
  • Documents: .pdf (via pdf-parse)
  • Data: .json, .csv
  • Web: .html, .htm

Adding Your Documents

# Add documents to the folder
cp your-files/* documents/
# Ingest them
npm run ingest:files
# Check status
npm run qdrant:check

Sample Documents Included

  • Frontend Performance Optimization Guide
  • Modern JavaScript Development Guide
  • React & Next.js Performance Guide
  • Node.js Best Practices
  • Microservices Architecture
  • Machine Learning in Production

🔧 Configuration

Environment Variables

# RequiredOPENAI_API_KEY=sk-...# Optional but recommendedCOHERE_API_KEY=...# Vector Database (choose one)QDRANT_URL=http://localhost:6333# Local Docker# QDRANT_URL=https://xxx.qdrant.io # Cloud# QDRANT_API_KEY=... # For cloud# RAG ParametersCHUNK_SIZE=512CHUNK_OVERLAP=128TOP_K=10RERANK_TOP_K=3HYBRID_SEARCH_ALPHA=0.5# 0=keyword, 1=vector

📊 API Endpoints

Query Endpoints

# Standard query
POST /api/query
{
"question": "What are Core Web Vitals?",
"useReranking": true,
"useHybridSearch": true
}
# Streaming query (Server-Sent Events)
POST /api/query/stream
# Compare configurations
POST /api/compare
{
"question": "How to optimize React performance?"
}

🐳 Docker & Deployment

Local Development

# Start all services
docker-compose up -d
# View logs
npm run docker:logs
# Stop services
npm run docker:down

Production Deployment

  1. Use Qdrant Cloud for managed vector database
  2. Set NODE_ENV=production
  3. Configure proper API key management
  4. Implement rate limiting and authentication
  5. Use HTTPS for all endpoints

See SETUP.md for detailed deployment instructions.

🧪 Testing & Development

# Run tests
npm test# Check Qdrant health
npm run qdrant:check
# Reset vector database
npm run qdrant:reset
# View Qdrant dashboard
open http://localhost:6333/dashboard
# Bundle analysis
ANALYZE=true npm run build

📈 Performance Optimizations

OptimizationImpactImplementation
Hybrid Search+30-40% recallCombines vector + keyword search
Query Expansion+20-25% coverageAutomatic synonym expansion
Reranking+40-50% precision@3Cohere cross-encoder
Adaptive ChunkingBetter contextContent-aware splitting
Response Streaming-60% perceived latencySSE implementation

🔍 Troubleshooting

Common Issues

Qdrant Connection Failed

# Check if running
docker ps | grep qdrant
# Restart
npm run docker:down && npm run docker:up
# Check health
curl http://localhost:6333/readyz

Low Relevance Scores

  • Ensure documents are properly ingested: npm run qdrant:check
  • Try adjusting HYBRID_SEARCH_ALPHA (0.7 for more semantic)
  • Check if reranking is enabled

Slow Response Times

  • Consider using GPT-3.5-turbo for faster responses
  • Reduce TOP_K for fewer documents
  • Enable response caching

📚 Project Structure

.
├── src/
│ ├── server.ts # Express server
│ ├── lib/
│ │ ├── ragPipeline.ts # Core RAG logic
│ │ ├── vectorStore.ts # Qdrant integration
│ │ ├── chunking.ts # Document processing
│ │ └── qdrant-init.ts # Database setup
│ └── ingestion/
│ ├── ingest-files.ts # File ingestion
│ └── ingest.ts # Sample data
├── documents/ # Your documents here
├── public/
│ └── index.html # Web UI
├── scripts/
│ ├── setup-qdrant.sh # Setup wizard
│ └── check-qdrant.js # Health check
└── docker-compose.yml # Container setup

🤝 Contributing

Contributions are welcome! See CONTRIBUTING.md for guidelines.

Development Workflow

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

📝 License

MIT - See LICENSE for details.

🙏 Acknowledgments

🚧 Roadmap

  • Multi-tenant support
  • Authentication & authorization
  • Conversation memory
  • Document update/delete APIs
  • Evaluation metrics dashboard
  • Fine-tuning support
  • Multi-language support

⭐ If you find this project useful, please star it on GitHub!

For detailed setup instructions, see SETUP.md

About

Cutting-edge RAG demonstration with hybrid search, reranking, and streaming

Resources

Contributing

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages