Upload
.txtor
Live Demo → basic-rag-mstghx3dbkhezdategemlv.streamlit.app
Evaluated on a QA dataset over the included articles (python evaluate.py):
| Metric | Score | What it means |
|---|---|---|
| Faithfulness | 0.92 | Answers grounded in retrieved context |
| Answer Relevancy | 0.88 | Answers address the question asked |
| Context Precision | 0.85 | Retrieved chunks are on-topic |
| Context Recall | 0.81 | Necessary chunks were retrieved |
Run
python evaluate.pyto reproduce with your own documents.
User Question
│
▼
┌─────────────────────────────────────────┐
│ Streamlit UI / CLI (main.py) │
└──────────────────┬──────────────────────┘
│
┌────────────┴────────────┐
▼ ▼
┌──────────────┐ ┌──────────────────────┐
│ data_loader │ │ vector_store │
│ │ │ │
│ .txt + .pdf ├─────▶│ OpenAI Embeddings │
│ LangChain │chunks│ ChromaDB (persisted) │
│ TextSplitter │ │ Similarity search │
└──────────────┘ └──────────┬───────────┘
│ top-k chunks
▼
┌──────────────────────┐
│ rag.py │
│ │
│ LangChain LCEL chain │
│ GPT-4o-mini │
│ Source citations │
└──────────┬───────────┘
│
▼
┌──────────────────────┐
│ RAGResponse │
│ answer: str │
│ sources: list[str] │
│ num_chunks_used: int │
└──────────────────────┘
git clone https://github.com/Babarali2k21/basic-rag.git
cd basic-rag
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txtcp .env.example .env
# Edit .env and set OPENAI_API_KEY=sk-your-key-hereDrop .txt or .pdf files into the ./articles/ folder. A sample article is included to get you started.
streamlit run app.pyOpen http://localhost:8501, enter your API key in the sidebar, upload documents or use the articles folder, then start asking questions.
# Index documents
python main.py --index
# Interactive Q&A session
python main.py
# Single question
python main.py --query "What is retrieval-augmented generation?"python evaluate.pybasic-rag/
├── app.py # Streamlit web UI with document upload
├── main.py # CLI (--index / --query / interactive)
├── config.py # Settings via Pydantic BaseSettings
├── data_loader.py # Load .txt/.pdf + LangChain text splitting
├── vector_store.py # ChromaDB indexing, loading, retriever factory
├── rag.py # LangChain LCEL chain + RAGResponse dataclass
├── evaluate.py # RAGAS evaluation script
├── conftest.py # pytest path configuration
├── articles/ # Drop knowledge base files here
│ └── rag_overview.txt
├── docs/
│ └── screenshot.png # App screenshot
├── tests/
│ └── test_rag.py # Unit + integration tests (mocked, no API key needed)
├── .env.example # Environment variable template
├── requirements.txt
└── .github/
└── workflows/
└── tests.yml # CI: pytest + codecov on Python 3.11 & 3.12
All settings via .env file:
| Variable | Default | Description |
|---|---|---|
OPENAI_API_KEY |
— | Required |
OPENAI_MODEL |
gpt-4o-mini |
LLM for answer generation |
EMBEDDING_MODEL |
text-embedding-3-small |
Embedding model |
CHUNK_SIZE |
512 |
Characters per chunk |
CHUNK_OVERLAP |
64 |
Overlap between chunks |
RETRIEVAL_K |
5 |
Chunks to retrieve per query |
CHROMA_PATH |
chroma_persistent_storage |
ChromaDB persistence path |
ARTICLES_DIR |
./articles |
Knowledge base directory |
pytest tests/ -v
# With coverage report
pytest tests/ -v --cov=. --cov-report=term-missingAll tests use mocked LLM calls no API key required to run the test suite.
12/12 tests passing on Python 3.11 and 3.12.
- Core RAG pipeline (load → chunk → embed → retrieve → generate)
- PDF support via PyPDF
- Document upload via Streamlit UI
- LangChain LCEL chain with source citations
- Streamlit web UI with chat history
- RAGAS evaluation script
- Pydantic v2 settings
- 12 pytest tests (mocked, no API key needed)
- CI/CD (GitHub Actions + Codecov)
- Deployed on Streamlit Cloud
- Conversational memory (multi-turn Q&A)
- Advanced retrieval: HyDE + cross-encoder reranking
- Pinecone / Qdrant as vector store alternatives
- Docker deployment
| Layer | Tool |
|---|---|
| LLM | OpenAI GPT-4o-mini |
| Embeddings | OpenAI text-embedding-3-small |
| RAG Framework | LangChain 0.2 |
| Vector Store | ChromaDB |
| Evaluation | RAGAS |
| Web UI | Streamlit |
| Config | Pydantic BaseSettings |
| Testing | pytest + pytest-cov (12 tests) |
| CI/CD | GitHub Actions + Codecov |
| Deployment | Streamlit Cloud |
Babar Ali AI Engineer · Vienna, Austria
MIT