Enterprise-grade multi-tenant RAG (Retrieval-Augmented Generation) platform for transforming company documentation into an AI-powered knowledge assistant. Features intelligent document ingestion, semantic search with pgvector, contextual Q&A, automatic SOP generation, and enterprise security with multi-tenant isolation.
Visit Live Site View on GitHub
AI Knowledge Hub is a production-ready SaaS platform that transforms company documentation into an intelligent knowledge assistant using advanced RAG (Retrieval-Augmented Generation) technology. Built with Next.js 15, TypeScript, Supabase, LangChain, and OpenAI GPT-4, it features a complete document ingestion pipeline with semantic chunking and vector embeddings, context-aware Q&A with source attribution, automatic SOP generation, and enterprise-grade security with Row-Level Security (RLS), role-based access control (RBAC), and Stripe-powered subscription management.
The platform implements a sophisticated document ingestion pipeline that transforms unstructured PDFs into searchable vector embeddings. Documents are uploaded via drag-and-drop, stored in Supabase Storage, and processed through a multi-step pipeline: text extraction, intelligent semantic chunking using LangChain's RecursiveCharacterTextSplitter (900 character chunks with 150 character overlap to maintain context continuity), embedding generation with OpenAI's text-embedding-3-small model (1536 dimensions), and storage in PostgreSQL with the pgvector extension. The vector database uses IVFFlat indexing for O(log n) approximate nearest neighbor search, with cosine similarity scoring to find the most relevant document chunks for each query.
The RAG (Retrieval-Augmented Generation) chat enables users to ask natural language questions and receive contextual answers based on their organization's documentation. The system embeds each query using the same embedding model as ingestion (ensuring consistency), performs a vector similarity search to retrieve the top 6 most relevant document chunks (with a configurable similarity threshold of 0.75), constructs a context from retrieved chunks, and uses GPT-4.1-mini to generate answers with specialized prompt engineering. Responses are streamed token-by-token using NDJSON format for immediate user feedback. Each answer includes source attribution, showing which specific documents and chunks informed the response. Conversation history is maintained within sessions, allowing for contextual follow-up questions.
The platform can automatically generate Standard Operating Procedures (SOPs) from company documentation using specialized AI prompting. Users specify a title, scope, and context, and the system leverages the same RAG infrastructure to retrieve relevant chunks, then uses GPT-4.1 (full model for complex reasoning) with a specialized template to generate structured SOPs. The output includes: purpose and scope section, prerequisites checklist, numbered step-by-step instructions, safety warnings and notes, and post-completion checklist. Generated SOPs can be edited, regenerated, or exported to Markdown or PDF formats with custom formatting using pdf-lib.
Built with enterprise-grade security and true multi-tenancy using Supabase Row-Level Security (RLS). Every database table has RLS policies that enforce organization-level data isolation at the database layer, ensuring users can only access data belonging to their organization. The platform implements a 4-tier Role-Based Access Control (RBAC) system: Viewer (read-only access), Contributor (can upload docs and generate SOPs), Company Admin (full team management, billing, and user invitations), and Super Admin (platform oversight with access to all organizations, system-wide statistics, and monitoring). Permissions are enforced at three levels: UI (hide features based on role), API (server-side validation in route handlers), and Database (RLS policies with role column checks).
Company Admins can manage their team through a comprehensive admin interface. The invitation system allows sending email invitations with pre-assigned roles, tracking invitation status (pending, accepted, expired, revoked), and automatically creating user accounts when invitations are accepted. Admins can change user roles, suspend or enable users, view detailed user activity, and perform bulk operations like deleting all pending invitations. The system tracks invitation expiration (7 days) and provides clear feedback on invitation status.
The Super Admin dashboard provides comprehensive platform oversight with real-time statistics and analytics. Features include: total users, organizations, documents, conversations, and procedures; plan distribution showing users across Trial, SMB, and Enterprise tiers; user growth visualization over the last 30 days; top 10 organizations ranked by activity (members, documents, chats, SOPs); engagement metrics (active users per day/week/month, avg conversations per user, avg documents per organization); document ingestion status tracking; and time-series charts for documents uploaded and chat activity over time. All data is filtered by organization using RLS, and Super Admins have visibility across all tenants for monitoring and support purposes.
Integrated Stripe subscription system with three plans: Trial (14 days free, 5 documents, 50 chats/month, 2 SOPs, 2 contributors, 1 viewer), SMB (€19.90/month or €199/year, 50 docs, 500 chats/month, 20 SOPs, 10 contributors, 5 viewers), and Enterprise (€49.90/month or €499/year, unlimited resources). The platform includes automatic account disabling for expired subscriptions, email notifications for trial expirations and deactivations, webhook handling for subscription lifecycle events (created, updated, deleted), and a complete billing portal for subscription management. Subscription status is verified at login and through automated cron jobs, ensuring users with expired subscriptions are immediately disabled. Company Admins can upgrade, downgrade, or cancel subscriptions directly from their profile.
Full internationalization (i18n) support with English and Italian languages using next-intl. All UI elements, messages, errors, and emails are fully translated. The platform features a responsive design that adapts to mobile, tablet, and desktop viewports. Navigation is context-aware: desktop users (≥1024px) see a traditional TopNav with all menu items, while mobile users (<1024px) access features through a Command Palette (Ctrl+K / Cmd+K). The Command Palette provides fast keyboard-driven navigation, filtered by user role, with search functionality for quick access to any feature. Language switching is seamless and persists across sessions.
Comprehensive Help Center with FAQ sections covering common questions about the platform, documents, chat, procedures, team management, and troubleshooting. The help system includes quick info cards for each major feature, detailed user manuals in both English and Italian (accessible as PDFs), and a contact form for user support allowing users to submit questions, report bugs, or request new features. All help content is internationalized and accessible from any page via the main navigation or Command Palette.
The platform's AI architecture is optimized for cost and performance. Document embeddings use text-embedding-3-small ($0.02/1M tokens) for cost-effectiveness. RAG chat uses GPT-4.1-mini, which is 10x cheaper than GPT-4 and sufficient for factual Q&A. SOP generation uses full GPT-4.1 for complex reasoning and structured output generation. The vector search SQL function uses PostgreSQL's pgvector extension with the cosine distance operator (<=>), indexed with IVFFlat for O(log n) search performance. Typical latencies: query embedding 50-100ms, vector search 100-200ms, LLM first token 500-800ms, full answer 2-4s. Rate limiting prevents abuse (20 chat queries/min per user), and streaming responses provide immediate user feedback with progressive rendering.
Built with enterprise-grade security features including:
The codebase follows SOLID principles and clean architecture patterns. Built with TypeScript in strict mode (no implicit `any` allowed), functional programming patterns throughout (no classes), and React Server Components (RSC) first architecture with minimal client-side JavaScript (60% CSR / 40% SSR ratio optimized after thorough analysis). The project uses modular folder structure with clear separation of concerns: server-only utilities in `lib/server/`, UI components in `components/`, internationalized routes in `app/[locale]/`, and database migrations in `supabase/migrations/`. All environment variables are validated with Zod schemas at startup, ensuring fast-fail behavior for misconfigurations. The codebase includes comprehensive JSDoc comments for complex functions and maintains consistent naming conventions throughout.