{"id":26541356,"url":"https://github.com/arulkumarann/legalrag","last_synced_at":"2026-04-05T21:35:16.976Z","repository":{"id":283747331,"uuid":"952158533","full_name":"arulkumarann/legalRAG","owner":"arulkumarann","description":"A FastAPI-based Retrieval-Augmented Generation (RAG) system for legal document analysis, powered by Pinecone, LangChain, and Llama 3.3","archived":false,"fork":false,"pushed_at":"2025-03-21T22:38:54.000Z","size":22,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-21T23:28:38.844Z","etag":null,"topics":["chatbot","fastapi","langchain","llama","pinecone","rag","vector"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arulkumarann.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2025-03-20T20:33:38.000Z","updated_at":"2025-03-21T22:38:58.000Z","dependencies_parsed_at":"2025-03-21T23:28:43.785Z","dependency_job_id":"9bde882a-6dab-4f18-b1c9-1eeb3d009a13","html_url":"https://github.com/arulkumarann/legalRAG","commit_stats":null,"previous_names":["arulkumarann/legalrag"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arulkumarann%2FlegalRAG","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arulkumarann%2FlegalRAG/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arulkumarann%2FlegalRAG/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arulkumarann%2FlegalRAG/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arulkumarann","download_url":"https://codeload.github.com/arulkumarann/legalRAG/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244890790,"owners_count":20527153,"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","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":["chatbot","fastapi","langchain","llama","pinecone","rag","vector"],"created_at":"2025-03-22T01:20:09.828Z","updated_at":"2025-12-30T23:54:17.567Z","avatar_url":"https://github.com/arulkumarann.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# **LegalRAG**  \n\nA Retrieval-Augmented Generation (RAG) system for legal document analysis, built with **FastAPI**, **Pinecone**, and **Llama 3.3 via Groq Inference**.  \n\n## **Overview**  \n\nLegalRAG is an AI-powered system that retrieves and analyzes legal documents based on user queries. It utilizes **vector-based search** to provide relevant case law, legal statutes, and precedents in response to legal queries.  \n\n## **Features**  \n\n**Legal Document Retrieval** – Uses Pinecone for fast and efficient case law retrieval.  \n **Natural Language Querying** – Allows users to search legal documents using plain English.  \n **Session-Based Handling** – Supports session-based query tracking for better user experience.  \n **FastAPI Backend** – Provides a scalable and efficient REST API.  \n **Concurrency Handling** – Manages multiple legal research sessions efficiently.  \n **Llama 3.3 via Groq Inference** – High-speed, low-latency language model inference.  \n\n---  \n\n## **Installation**  \n\n### **1. Clone the repository**  \n```bash\ngit clone https://github.com/arulkumarann/legalRAG.git\ncd legalRAG\n```\n\n### **2. Create a virtual environment**  \n```bash\npython -m venv venv\n# On Windows\nvenv\\Scripts\\activate\n# On macOS/Linux\nsource venv/bin/activate\n```\n\n### **3. Install dependencies**  \n```bash\npip install -r requirements.txt\n```\n\n---  \n\n## **Configuration**  \n\nCreate a `.env` file and add the following variables:  \n```\nPINECONE_API_KEY=your_pinecone_api_key\nINDEX_NAME=your_pinecone_index_name\nGROQ_API_KEY=your_groq_api_key\n```\n\n---  \n\n## **Running the Application**  \n\n### **Local Development**  \n```bash\nuvicorn app.main:app --reload\n```\nAPI will be available at **http://localhost:8000**  \n\n### **Running the Streamlit Interface**\n```bash\nstreamlit run app.py\n```\nThe Streamlit interface will be available at **http://localhost:8501**\n\n---  \n\n## **API Endpoints**  \n\n### **1. Root Check**  \n- **GET `/`** – Health check endpoint  \n\n### **2. Chat with RAG**  \n- **POST `/chat`** – Query legal documents with RAG  \n  - **Body:**  \n    ```json\n    {\n      \"session_id\": \"abc123\",\n      \"query\": \"What are the key points of Smith v. Johnson?\"\n    }\n    ```\n  - **Response:**  \n    ```json\n    {\n      \"response\": \"The key points are breach of contract and negligence...\",\n      \"sources\": [\"case_smith_v_johnson.pdf\"]\n    }\n    ```\n\n### **3. Session Management**  \n- **DELETE `/session/{session_id}`** – End a legal research session  \n- **POST `/session/reset/{session_id}`** – Reset a session's state  \n- **GET `/sessions/count`** – Get the total number of active sessions  \n\n### **4. Retrieve Source Documents**  \n- **GET `/sources/{session_id}`** – Fetch relevant legal documents for a session  \n\n---  \n\n## **Llama 3.3 via Groq Inference**  \n\n- **Inference Speed:** \u003c15ms per query response  \n- **Token Throughput:** ~500 tokens/sec  \n- **Latency:** Low-latency response optimized for real-time queries  \n- **Memory Usage:** Efficient memory footprint compared to traditional on-device LLMs  \n- **Scalability:** Supports concurrent user queries without degradation  \n\n---  \n\n## **Concurrency \u0026 Session Handling**  \n\nThis RAG system supports multiple concurrent users by assigning unique `session_id` values for each session.  \n\n- **Sessions track user queries** to improve context and accuracy.  \n- **Each session has its own vector search scope** in Pinecone, ensuring faster retrieval of case-specific documents.  \n- **Automatic cleanup** – Sessions can be ended manually (`DELETE /session/{session_id}`) or reset (`POST /session/reset/{session_id}`).  \n\n---  \n\n## **Deployment**  \n\n### **Deploy on Render**  \n1. **Build Command:**  \n   ```bash\n   pip install -r requirements.txt\n   ```\n2. **Start Command:**  \n   ```bash\n   gunicorn app.main:app -k uvicorn.workers.UvicornWorker --workers 1 --threads 2 --timeout 120\n   ```\n3. **Environment Variables:**  \n   - `PINECONE_API_KEY`  \n   - `INDEX_NAME`  \n   - `GROQ_API_KEY`  \n\n---  \n\n## **Memory Optimization**  \n\n- Uses **lazy model loading** to reduce memory usage.  \n- **Batch processing** to prevent memory spikes.  \n- **Garbage collection** after query execution.  \n\n---  \n\n\n## **License**  \nThis project is open-source under the **MIT License**.  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farulkumarann%2Flegalrag","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farulkumarann%2Flegalrag","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farulkumarann%2Flegalrag/lists"}