This project is a Retrieval-Augmented Generation (RAG) system implemented using Python, LangChain, and the DeepSeek R1 model. It combines traditional retrieval techniques (BM25) with modern dense embeddings (FAISS) to build a highly efficient document retrieval and question-answering system.
- Hybrid Retrieval: Combines BM25 and FAISS for robust and accurate document retrieval.
- Multi-PDF Support: Users can upload multiple PDF files for processing, which are stored in a dedicated
data/directory. - Streamlit UI: A user-friendly interface for uploading files, asking questions, and viewing results.
- Tracing and Analytics: Integrated tracing with LangSmith to analyze performance and monitor usage.
- Custom LLM Integration: Uses the DeepSeek R1 model (via Ollama) for question answering.
- Dynamic Context Handling: Automatically handles and prepares context for queries.
- Context-Aware Memory: Implement dynamic context retention to remember the flow of conversations.
- Framework: LangChain's updated
ConversationBufferMemoryorEntityMemory. - Use Case: Retaining context across multiple user queries for more coherent interactions.
- Framework: LangChain's updated
- User-Specific Memory: Allow memory reset or persistence for different users.
- Framework: Redis or PostgreSQL for memory persistence across sessions.
- Support for Multiple File Formats:
- Additional Formats: Microsoft Word, CSV, and image files (via Tesseract or Amazon Textract for OCR).
- Library:
python-docxfor Word,pandasfor CSV, andpytesseractor AWS Textract for images.
- File Listing UI:
- Feature: A sidebar UI for managing uploaded files (view/delete).
- Library: Streamlit components (
st.sidebarandst.selectbox).
- Usage Analytics:
- Framework: LangSmith or OpenTelemetry.
- Metrics: Number of queries, response times, and user feedback.
- Error Logging:
- Framework: Sentry or Python's built-in
logginglibrary. - Storage: Centralized logs for troubleshooting.
- Framework: Sentry or Python's built-in
- REST API:
- Framework: FastAPI for building a RESTful API.
- Use Case: Exposing functionalities for external applications.
- Access Control:
- Framework: FastAPI Users for authentication and role-based access.
- Feature: Secure endpoints for API access.
- Data Encryption:
- Library:
cryptographyfor encrypting files and query results.
- Library:
- Advanced Retrieval Techniques:
- Framework: DPR (Dense Passage Retrieval) using Hugging Face models.
- Improvement: Replace FAISS with Weaviate or Milvus for better vector storage and search.
- Semantic Clustering:
- Library: Scikit-learn for clustering similar documents.
- Parallel Processing:
- Framework:
concurrent.futuresormultiprocessing. - Use Case: Faster processing of large files.
- Framework:
- Caching System:
- Library: Redis or Memcached for caching embeddings and document chunks.
- User Feedback Loop:
- Framework: Streamlit widgets for rating responses.
- Use Case: Improve system accuracy with user feedback.
- Interactive Debugging:
- Feature: Flag incorrect answers directly from the UI.
- Automated Testing:
- Framework: Pytest for unit and integration tests.
- CI Tool: GitHub Actions for continuous integration.
- Continuous Deployment:
- Tool: Docker and AWS CodePipeline for seamless updates.
- Knowledge Base:
- Platform: GitBook or ReadTheDocs for user and developer documentation.
- Content: Guides, FAQs, and tutorials.
- Open Source Contribution:
- Platform: GitHub for hosting and collaboration.
- Feature: Contributor guidelines and issues for community involvement.
- Python 3.9+
- Pip
- Ollama installed (installation guide).
-
Clone the repository:
git clone https://github.com/your-repo/hybrid-rag.git cd hybrid-rag -
Create and activate a virtual environment:
python -m venv rag_env source rag_env/bin/activate # On Windows: rag_env\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Install Ollama and pull the DeepSeek R1 model:
# Install Ollama brew install ollama # macOS # Pull the DeepSeek R1 model ollama pull deepseek-r1:1.5b
-
Run the Streamlit app:
streamlit run app.py
- Upload one or more PDF files via the Streamlit UI.
- Ask questions based on the uploaded documents.
- View responses and source documents.
We welcome contributions! Please check the Contributing Guidelines.
This project is licensed under the MIT License. See the LICENSE file for details.