An open API service indexing awesome lists of open source software.

https://github.com/emredeveloper/rag-with-cache

A comprehensive study and implementation of best practices for Retrieval-Augmented Generation (RAG) systems. This project includes advanced features like model caching, multilingual support, and evaluation metrics to enhance the performance and usability of RAG systems.
https://github.com/emredeveloper/rag-with-cache

artificial-intelligence documentation llm python rag

Last synced: about 1 month ago
JSON representation

A comprehensive study and implementation of best practices for Retrieval-Augmented Generation (RAG) systems. This project includes advanced features like model caching, multilingual support, and evaluation metrics to enhance the performance and usability of RAG systems.

Awesome Lists containing this project

README

          

# ๐Ÿš€ RAG-With-Cache

A compact reference implementation of **Retrieval-Augmented Generation (RAG)**
that focuses on the core building blocks: PDF ingestion, vector search, and
language model generation. The codebase has been simplified so the main RAG
pipeline lives in a dedicated `rag/` package with minimal dependencies and a
clean entry point.

---

## ๐ŸŒŸ Features

- **Modular package layout** โ€“ Embedding, language, data-loading, and
retriever utilities are organised under `rag/` for easier reuse.
- **FAISS and HyDE retrievers** โ€“ Switch between traditional dense retrieval
and HyDE-style hypothetical document retrieval from the command line.
- **Model caching** โ€“ Embedding and language models are cached locally to
avoid repeated downloads.
- **PDF utilities** โ€“ Lightweight helpers for loading and chunking documents.
- **Test coverage** โ€“ Pytest suite that exercises each major component with
fast stubs.

---

## ๐Ÿš€ Quick Start

1. **Install dependencies**

```bash
pip install -r requirements.txt
```

2. **Prepare your documents**

Place PDFs inside `data/pdfs/`. The directory is created automatically when
running the CLI, but adding files ahead of time lets you test retrieval
immediately.

3. **Run the demo CLI**

```bash
python main.py
```

Choose between FAISS or HyDE retrieval when prompted and start asking
questions about your documents.

---

## ๐Ÿ“ Project Structure

```text
โ”œโ”€โ”€ rag/
โ”‚ โ”œโ”€โ”€ config.py # Configuration dataclass
โ”‚ โ”œโ”€โ”€ data/ # PDF loading utilities
โ”‚ โ”œโ”€โ”€ embeddings.py # SentenceTransformer wrapper with caching
โ”‚ โ”œโ”€โ”€ language.py # HuggingFace causal LM wrapper with caching
โ”‚ โ”œโ”€โ”€ retrievers/ # FAISS and HyDE retrievers
โ”‚ โ””โ”€โ”€ system.py # High-level RAG orchestration
โ”œโ”€โ”€ data/pdfs/ # PDF documents for retrieval
โ”œโ”€โ”€ tests/ # Pytest suite
โ”œโ”€โ”€ main.py # Command-line entry point
โ”œโ”€โ”€ requirements.txt # Minimal dependency set
โ””โ”€โ”€ setup.py # Package metadata
```

---

## ๐Ÿงช Running the Tests

```bash
pytest
```

The HyDE tests rely on stubbed models so they run quickly without downloading
large checkpoints.