This repository is a scaffold for the bonus: a working RAG pipeline with re-ranking, retrieval-quality comparison, and basic latency/accuracy measurements.
It is designed to run on Replit / local machine. The code contains two modes:
- Provider mode: uses OpenAI for embeddings + LLM (requires
OPENAI_API_KEY). - Local mode: uses
sentence-transformers(for embeddings) andcross-encoderfor reranking. Local generation is left as a placeholder (you can plug a local LLM).
rag_demo.py— main script: ingest, index (FAISS), search, rerank, prompt assembly, evaluate (LLM-only vs RAG).vector_store.py— helper: build FAISS index and search.reranker.py— helper: cross-encoder re-ranking wrapper.data/session_doc.txt— placeholder: drop your Session_3 text here (I could not auto-extract DOCX in this scaffold).requirements.txt— suggested packages.run_demo.sh— example run script.
- Create a repl / VM with internet access.
- Upload your domain document to
data/session_doc.txt(or other txt files indata/). - Option A (OpenAI):
- Set
OPENAI_API_KEYin repl secrets / environment. pip install -r requirements.txtpython rag_demo.py --mode openai
- Set
- Option B (Local embeddings & reranker):
pip install -r requirements.txtpython rag_demo.py --mode local- (This downloads sentence-transformers / cross-encoder models on first run.)
- Ingests text file(s) and chunks them (200–300 token chunks with overlap).
- Builds FAISS index from embeddings.
- Runs sample queries, measuring:
- LLM-only (if configured) vs RAG answers (assembled prompt + LLM).
- Retrieval latency, re-rank latency, LLM latency.
- Simple retrieval quality metrics: provenance coverage (what percent of claimed lines include a substring from retrieved chunks).
- Outputs a comparison CSV in
outputs/.
- This scaffold focuses on reproducible evaluation: you can replace placeholder LLM calls with any provider (OpenAI, local Llama, etc.).
- For production, swap FAISS for Pinecone/Weaviate and Apollo/Hasura for GraphQL layer.