This repository demonstrates a basic Retrieval-Augmented Generation (RAG) pipeline using Hugging Face models and the LlamaIndex library, along with comprehensive unit tests for all major components.
- Loads documents from a Hugging Face dataset (e.g., SQuAD)
- Embeds documents and builds a vector index
- Retrieves relevant documents for a query
- Generates answers using a language model
- Includes robust unit and integration tests for the RAG workflow
main.py— Example script to run the RAG pipelinerag_system.py— Core RAG implementationtest_ragsystem.py— Unit and integration tests (usingunittestandunittest.mock)requirements.txt— Python dependencies
- Install dependencies:
pip install -r requirements.txt- Set your OpenAI API key in a
.envfile:
OPENAI_API_KEY=your_openai_api_key- Run the example:
python main.py- Run all tests:
python test_ragsystem.py- The RAG system uses Hugging Face models for embeddings and LLMs, and OpenAI for LLM inference.
- All major RAG steps are covered by unit tests, including error handling.
For learning and experimentation.