This repo provides a plug-and-play RAG pipeline in Python. Use it to index your documents and query them with an LLM (OpenAI, Gemini, HuggingFace, etc.).
rag_template.py→ The main RAG script.sample_docs.txt→ Example text file for testing.
git clone https://github.com/yourusername/rag-template.git
cd rag-templatepython -m venv venv
source venv/bin/activate # On Mac/Linux
venv\Scripts\activate # On Windowspip install -r requirements.txtMinimal requirements (requirements.txt):
langchain
langchain-community
langchain-openai
faiss-cpuExport your API key for security:
export OPENAI_API_KEY="your_api_key_here" # Mac/Linux
setx OPENAI_API_KEY "your_api_key_here" # WindowsOr edit the script to place your key directly.
python rag_template.py- Load Documents → from
.txtfiles (can swap for PDFs, CSVs, or DBs). - Split Text → into manageable chunks.
- Embed Chunks → using OpenAI embeddings.
- Store Vectors → inside FAISS (local vector database).
- Ask Questions → queries are matched against your docs.
- LLM Response → retrieved chunks are passed to the LLM for context.
- Change
TextLoadertoPyPDFLoader,CSVLoader, etc. - Swap embeddings:
OpenAIEmbeddings→HuggingFaceEmbeddings. - Replace FAISS with other vector DBs (Pinecone, Chroma, Weaviate).
- Use another LLM:
ChatOpenAI→ Gemini / HuggingFace / LLaMA.
YOU: What is this document about?
RAG: This document explains how to set up a Retrieval-Augmented Generation pipeline.
Feel free to fork, modify, and use this template for your own projects.
MIT License. Free to use and modify.