Supabase RAG Engine
This document describes the Supabase RAG Engine, a production-ready system for generating intelligent insights from document collections.
Overview
The Supabase RAG Engine is a sophisticated RAG intelligence layer with hybrid search, production-ready resilience patterns, comprehensive observability and performance monitoring, and advanced quality metrics.
Key Functionalities:
- Hybrid Search: Combines vector similarity search with keyword-based full-text search using Reciprocal Rank Fusion (RRF) for optimal result quality and performance.
- Resilience: Implements a fallback search strategy to ensure users always get relevant results, even when precision-focused searches fail.
- Quality Metrics: Calculates relevance density to distinguish between documents that are about a topic versus just mention it.
- Insight Generation: Uses a multi-stage process to generate document summaries, direct answers, and related questions.
Technology Stack:
- Supabase: The core platform, providing the PostgreSQL database, Edge Functions, and other backend services.
- PostgreSQL: The database, with the
pgvectorandpg_trgmextensions. - Deno: The runtime for the Edge Functions.
- OpenAI: The LLM provider for insight generation.
Edge Functions
query-knowledge-base
Performs a hybrid search (semantic + keyword) with a fallback strategy.
generate-rag-insights
Generates insights from the search results using a multi-stage process.
Database Schema
The database schema is defined in the supabase/bootstrap.sql file. It includes tables for documents, document chunks, insight cache, and search history.