Enterprise-Style Retrieval-Augmented Generation (RAG) Pipeline
Node.js + Gemini + Supabase (pgvector)
RAGOps-Lab is a modular and production-minded RAG system that supports provider-swappable embeddings, duplicate-safe ingestion, and measurable retrieval evaluation. It ingests local knowledge into Supabase vector storage, retrieves relevant chunks with pgvector search, and generates grounded answers.
- Added
reset-dbandreindexworkflows for one-command testing. - Added
eval:embeddingsto compare Gemini and custom embeddings with Recall@k and MRR. - Added duplicate-safe ingestion using deterministic chunk-level upsert logic.
- Added chunking strategy control (
lineorcharacter) for predictable ingestion behavior.
- Reusable pipeline class in
src/rag.js - Pluggable embedding provider architecture (
geminiorcustom) - Duplicate-safe ingestion via chunk-level upsert logic
- Configurable chunking strategies (
lineor overlappingcharacterwindows) - Supabase RPC retrieval (
match_documents) with configurable top-k - Strict environment validation and fail-fast startup checks
- CLI-ready entrypoints for ingestion and querying
- Configurable models and runtime tuning from
.env
flowchart LR
A[knowledge.txt or custom source] --> B[Chunking]
B --> C[Embedding Provider]
C --> D[Upsert into documents]
E[User Query] --> F[Query Embedding]
F --> G[match_documents RPC]
G --> H[Context Prompt]
H --> I[Gemini Generation]
I --> J[Grounded Answer]
src/rag.js: Pipeline core (RAGPipeline) with ingest/query/reset/count utilities.src/embeddings/createEmbeddingProvider.js: Provider factory.src/embeddings/geminiEmbeddingProvider.js: Gemini embedding implementation.src/embeddings/customEmbeddingProvider.js: Local custom embedding algorithm.src/resetDb.js: Clearsdocumentstable.src/reindex.js: Reset + ingest in one command.src/evaluateEmbeddings.js: Runs provider comparison with Recall@k and MRR.
Required environment variables:
GEMINI_API_KEYSUPABASE_URLSUPABASE_SERVICE_KEY
Optional tuning variables:
EMBEDDING_PROVIDER(default:gemini, values:gemini | custom)EMBEDDING_MODEL(default:models/gemini-embedding-001)CUSTOM_EMBEDDING_DIMENSION(default:768)GENERATION_MODEL(default:gemini-2.5-flash)MATCH_COUNT(default:3)CHUNKING_STRATEGY(default:line, values:line | character)CHUNK_SIZE(default:1000, used withcharacter)CHUNK_OVERLAP(default:200, used withcharacter)
- Install dependencies.
npm install- Configure environment.
copy .env.example .env- Edit
.envvalues.
GEMINI_API_KEY=your_gemini_key_here
SUPABASE_URL=your_supabase_url_here
SUPABASE_SERVICE_KEY=your_supabase_service_key_here
EMBEDDING_PROVIDER=gemini
EMBEDDING_MODEL=models/gemini-embedding-001
CUSTOM_EMBEDDING_DIMENSION=768
GENERATION_MODEL=gemini-2.5-flash
MATCH_COUNT=3
CHUNKING_STRATEGY=line
CHUNK_SIZE=1000
CHUNK_OVERLAP=200- Prepare Supabase assets.
documentstable with:id,content,embedding,metadatamatch_documents(query_embedding vector, match_count int)RPC function
npm run ingest
npm run query -- "how many goals has messi scored"npm run reset-db
npm run reindexnpm run eval:embeddingsThis evaluation command:
- Resets and reindexes for
gemini, evaluates metrics. - Resets and reindexes for
custom, evaluates metrics. - Prints summary table with Recall@k and MRR.
From current project run on knowledge.txt:
| Provider | Recall@k | MRR |
|---|---|---|
| gemini | 1.000 | 1.000 |
| custom | 1.000 | 0.900 |
- Repeated ingest does not create duplicate rows due to deterministic chunk IDs in metadata.
- If you change embedding provider or dimension, run
npm run reindexto rebuild vectors consistently. - Use
CHUNKING_STRATEGY=linefor fact-per-line corpora andcharacterfor long paragraphs.
This repo demonstrates production-oriented RAG practices:
- Modular provider abstraction.
- Operational scripts for reset/reindex/eval.
- Measurable retrieval quality reporting.
- Safe ingestion behavior under repeated runs.
ISC