{"id":23932835,"url":"https://github.com/dongdongunique/LLM_RAG","last_synced_at":"2025-09-11T15:32:41.029Z","repository":{"id":268862732,"uuid":"893386056","full_name":"dongdongunique/LLM_RAG","owner":"dongdongunique","description":"This repository implements a Retrieval-Augmented Generation (RAG) system using FAISS for vector-based retrieval and GPT for generative response. It is designed to process large datasets, index them with FAISS, and use GPT to answer queries with retrieved context.","archived":false,"fork":false,"pushed_at":"2025-01-01T08:47:41.000Z","size":13208,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-01T09:25:30.423Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dongdongunique.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-24T10:03:11.000Z","updated_at":"2025-01-01T08:47:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"c9934ef0-e882-423f-af84-b7ea5b72aa35","html_url":"https://github.com/dongdongunique/LLM_RAG","commit_stats":null,"previous_names":["dongdongunique/llm_rag"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dongdongunique/LLM_RAG","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dongdongunique%2FLLM_RAG","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dongdongunique%2FLLM_RAG/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dongdongunique%2FLLM_RAG/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dongdongunique%2FLLM_RAG/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dongdongunique","download_url":"https://codeload.github.com/dongdongunique/LLM_RAG/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dongdongunique%2FLLM_RAG/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274660192,"owners_count":25326150,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-11T02:00:13.660Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-06T00:29:23.515Z","updated_at":"2025-09-11T15:32:40.257Z","avatar_url":"https://github.com/dongdongunique.png","language":"Python","funding_links":[],"categories":["Building"],"sub_categories":["Datasets"],"readme":"# **RAG System with FAISS and GPT** (Homework for Advanced Database)\n\nThis repository implements a **Retrieval-Augmented Generation (RAG)** system using **FAISS** for vector-based retrieval and **GPT** for generative response. It is designed to process large datasets, index them with FAISS, and use GPT to answer queries with context retrieved from the documents.\n\n## **Features**\n\n- **Document Loading**: Load and preprocess datasets (e.g., CSV, plain text).\n- **Embedding Generation**: Convert documents and queries into vector embeddings.\n- **Efficient Retrieval**: Use FAISS for similarity search over large corpora.\n- **GPT Integration**: Generate answers using GPT with context from retrieved documents.\n- **Modular Design**: Easily extend the system with new vector stores, LLMs, or document loaders.\n- **Interactive User Interface**: A Gradio-powered UI for easy interaction with the system. Supports:\n  - Uploading and viewing CSV files.\n  - Searching the indexed documents.\n  - Managing document chunks.\n  - Interacting with the system through intuitive input fields.\n- **CRUD Operations**: Add, delete, update, and query document chunks in real-time.\n\n---\n\n## **Installation**\n\n### **Requirements**\n\n- Python 3.8 or higher\n- FAISS\n- OpenAI API Key\n- Gradio (for the UI)\n\n### **Dependencies**\n\nInstall the required packages using `pip`:\n\n```bash\npip install -U -r requirements.txt\n```\n\n**`requirements.txt`:**\n\n```plaintext\nlangchain\nopenai\nfaiss-cpu\npython-dotenv\npandas\nlangchain-community\ntiktoken\ngradio\n```\n\n---\n\n## **Usage**\n\n### **1. Set Up Environment Variables**\n\nCreate a `.env` file in the project root directory and add your OpenAI API key:\n\n```env\nOPENAI_API_KEY=your_openai_api_key\n```\n\n### **2. Prepare Your Dataset**\n\n- Use the provided example dataset (`amazon_products.csv`) or upload your own CSV dataset.\n- Ensure the dataset contains a column with text-based content (e.g., `description`) to generate embeddings.\n\n### **3. Run the System**\n\nYou can run the system in two modes:\n\n#### **Command-Line Interface (CLI)**\n\nRun the system interactively via CLI:\n\n```bash\npython main.py\n```\n\nThis mode allows you to interact with the RAG system by asking questions and retrieving answers.\n\n#### **Gradio User Interface**\n\nRun the system with the Gradio-powered UI:\n\n```bash\npython app.py\n```\n\nThis launches a web-based interface for uploading datasets, managing document chunks, and querying the RAG system.\n\n---\n\n## **Project Structure**\n\n```plaintext\n.\n├── amazon_products.csv       # Example dataset for testing\n├── app.py                    # Gradio-based user interface\n├── app.log                   # Log file for application events\n├── dataset_cache.ipynb       # Notebook for dataset caching or analysis\n├── main.py                   # CLI entry point for the RAG system\n├── rag_system/               # Main source code for the RAG system\n│   ├── __init__.py\n│   ├── config.py             # Configuration settings (API keys, paths, etc.)\n│   ├── core.py               # Core logic for RAG system initialization\n│   ├── loaders.py            # Document loading and preprocessing\n│   ├── llms.py               # Integration with GPT or other LLMs\n│   ├── utils.py              # Utility functions (e.g., splitting documents)\n│   ├── vector_stores.py      # FAISS and other vector store implementations\n├── vector_store_index/       # Directory for storing FAISS index files\n├── requirements.txt          # Python dependencies\n├── SearchQ.md                # Markdown for documenting queries or use cases\n├── README.md                 # Project documentation (this file)\n├── .env                      # Environment variables for API keys\n```\n\n---\n\n## **Gradio User Interface**\n\nThe Gradio UI provides an intuitive interface for interacting with the RAG system. It supports:\n\n1. **Upload CSV Files**:\n   - Upload datasets containing documents for indexing.\n   - Automatically preprocesses and splits documents into chunks for embedding generation.\n\n2. **Search Documents**:\n   - Enter natural language queries in the search box.\n   - The system retrieves the most relevant documents and generates a response using GPT.\n\n3. **CRUD Operations**:\n   - Add new document chunks to the indexed dataset.\n   - Delete or update existing chunks based on specific criteria.\n\n### **Starting the Gradio Interface**\n\nRun the Gradio UI with:\n\n```bash\npython app.py\n```\n\nAfter launching, open the provided URL in a web browser to interact with the system.\n\n---\n\n## **Customization**\n\n### **1. Vector Store**\n\nThe system uses **FAISS** for vector-based retrieval by default. To integrate another vector database (e.g., Pinecone, Weaviate, Milvus):\n\n1. Create a new class in `rag_system/vector_stores.py` inheriting from `BaseVectorStore`.\n2. Update the `Config.VECTOR_STORE_TYPE` in `config.py`.\n\n### **2. LLM**\n\nThe system integrates with **OpenAI GPT**. To switch to another LLM (e.g., HuggingFace models):\n\n1. Add a new class in `rag_system/llms.py` inheriting from `BaseLLM`.\n2. Update `Config.LLM_TYPE` in `config.py`.\n\n### **3. Document Loaders**\n\nTo support additional formats (e.g., PDFs, JSON):\n\n1. Add a new class in `rag_system/loaders.py` inheriting from `BaseDocumentLoader`.\n2. Update the `load_documents` function to detect and handle the new format.\n\n### **4. Gradio UI**\n\nThe UI is modular and can be extended. To add new components:\n\n1. Modify `app.py` to include new Gradio widgets.\n2. Update the callback functions to handle the added functionality.\n\n---\n\n## **Logging**\n\nThe system logs important events (e.g., errors, indexing operations) in `app.log`. Check this file for debugging or monitoring purposes.\n\n---\n\n## **Future Improvements**\n\n- **Distributed Vector Stores**: Add support for scalable vector stores like Pinecone or Weaviate.\n- **Advanced Query Features**: Implement query expansion, semantic search, and ranking.\n- **Custom Embeddings**: Allow users to upload precomputed embeddings.\n- **User Authentication**: Add authentication and access control for the Gradio interface.\n- **Visualization**: Display results with data visualizations (e.g., charts for document relevance scores).\n- **Batch Processing**: Optimize retrieval and generation for bulk queries.\n\n---\n\n## **Contributing**\n\nContributions are welcome! To contribute:\n\n1. Fork the repository.\n2. Create a new branch for your feature or bug fix.\n3. Submit a pull request with detailed explanations of your changes.\n\n---\n\n## **License**\n\nThis project is licensed under the [MIT License](https://opensource.org/licenses/MIT).\n\n---\n\n## **Acknowledgments**\n\n- [FAISS](https://github.com/facebookresearch/faiss): Efficient similarity search.\n- [OpenAI](https://openai.com/): Embedding and generative APIs.\n- [LangChain](https://langchain.readthedocs.io/): Framework for building applications with LLMs.\n- [Gradio](https://gradio.app/): User-friendly interface for ML applications.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdongdongunique%2FLLM_RAG","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdongdongunique%2FLLM_RAG","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdongdongunique%2FLLM_RAG/lists"}