A lightweight RAG pipeline built with ChromaDB, HuggingFace Embeddings, and OpenAI GPT. Ask questions about your own documents and get accurate, context-grounded answers.
Your Document (.txt / .pdf)
↓
[Loader] → [Chunker] → [Embedder] → [ChromaDB Vectorstore]
↓
User Question → [Retriever]
↓
[Generator] → Answer
RAG/
├── data/ # ← Put YOUR documents here (.txt or .pdf)
├── src/
│ ├── api.py # FastAPI backend
│ ├── loader.py # Document loading (.txt, .pdf)
│ ├── chunker.py # Text splitting into chunks
│ ├── embedder.py # HuggingFace embeddings + ChromaDB
│ ├── retriever.py # Similarity search
│ ├── generator.py # OpenAI GPT answer generation
│ ├── ui.py # Streamlit frontend
│ └── main.py # CLI entry point (for testing)
├── tests/
├── .env # Your API keys (create this yourself)
├── .gitignore
└── requirements.txt
git clone https://github.com/your-username/RAG.git
cd RAGpython3 -m venv venv
source venv/bin/activate # macOS / Linux
venv\Scripts\activate # Windowspip install -r requirements.txtCreate a .env file in the project root:
OPENAI_API_KEY=sk-...your-key-here...
⚠️ Never commit your.envfile. It is already listed in.gitignore.
Place your .txt or .pdf files inside the data/ folder:
data/
└── your_document.txt
Then update the file path in src/api.py (line 9):
docs = load_documents("/absolute/path/to/your/RAG/data/your_document.txt")cd src
uvicorn api:app --reloadAPI will be available at: http://127.0.0.1:8000
Swagger UI (for testing): http://127.0.0.1:8000/docs
# From the project root
streamlit run src/ui.pyUI will be available at: http://localhost:8501
- Open the Streamlit UI at
http://localhost:8501 - Type your question in the chat input
- The system retrieves relevant chunks from your document and generates an answer
Or test directly via Swagger UI at http://127.0.0.1:8000/docs → POST /ask:
{
"question": "What is MoE?",
"history": ""
}| Component | Technology |
|---|---|
| Backend | FastAPI |
| Frontend | Streamlit |
| Embeddings | sentence-transformers/all-MiniLM-L6-v2 |
| Vector Store | ChromaDB (in-memory) |
| LLM | OpenAI GPT (via langchain-openai) |
| Doc Loading | LangChain TextLoader / PyPDFLoader |
See requirements.txt. Key dependencies:
fastapi
uvicorn
streamlit
langchain
langchain-community
langchain-openai
chromadb
sentence-transformers
python-dotenv
pypdf
- The vectorstore is in-memory — it rebuilds on every server restart.
- Only one document is loaded at a time. To use a different document, change the path in
api.pyand restart the server. - The
historyfield in the API request is optional — pass an empty string if not needed.
MIT License — feel free to use and modify.