This project is a legal chatbot that provides legal advice and helps users with various legal queries. The chatbot uses a combination of advanced technologies such as Retrieval-Augmented Generation (RAG), semantic search, vector databases, and large language models (LLMs) to provide precise and relevant answers. It utilizes Milvus as a vector database for indexing legal documents, and Ollama (Llama 3.2 1B parameters) as the underlying large language model to interpret user queries.
The frontend is developed using React and Vite, while the backend is built using Flask.
- IPC Section Query Assistance: The chatbot can interpret and respond to user queries related to sections of the Indian Penal Code (IPC). It retrieves the most relevant IPC sections based on the user's query, with their brief descriptions.
- Legal Document Generation: The chatbot can help in drafting various legal documents, such as contracts, agreements, and notices, by guiding the user through the necessary inputs.
- Precedents Search: The chatbot can assist users in finding relevant case law precedents. It retreives key cases along with their citations and summaries, helping users understand judicial interpretations and their implications under Indian law.
- Frontend: React, Vite
- Backend: Flask
- Semantic Search: Retrieval-Augmented Generation (RAG) with Milvus vector database
- LLM: Ollama (Llama 3.2 with 1B parameters)
- Query Processing: The user enters a query through the frontend interface. The query is processed and sent to the backend Flask server.
- Semantic Search: The query is run against a vectorized database of legal documents stored in Milvus, using semantic search. This search retrieves relevant legal content, such as IPC sections, case precedents, or other legal information.
- LLM Response Generation: The retrieved information is passed to Ollama's LLM, which then generates a precise and coherent response to the user’s query.
- Frontend Display: The response is returned to the frontend, where it is displayed to the user in an easy-to-read format.
- Python 3.8 or higher
- Node.js (for React and Vite)
- Milvus (for vector storage)
- Ollama LLM
- Flask
-
Clone the repository:
git clone https://github.com/reethuthota/Legal_Chatbot.git cd Legal_Chatbot -
Create and activate a virtual environment:
python3 -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
-
Install backend dependencies:
pip install -r requirements.txt
-
If the previous one doesnt work and if you face anyy dependancy issues
pip install -r requirements1.txt
```
Run the create_collections.py file 2 times, once with "./IPC.pdf" as the path and once more with "./documentforms.pdf" as the path
- Run the script to make collections on the vector database.
create_collections.py
- Then run precedance_collections.py file with "./case_files" as the path
By doing steps 1 and 2 you insert the vector embeddings into milvus which should already be running in docker
-
Start the Flask backend:
cd backend python app.pyThe backend server will be running on
http://localhost:8080.
-
Install frontend dependencies:
cd frontend npm install -
Run the frontend development server:
npm run dev
The frontend will be available at
http://localhost:5173.
-
IPC Section Queries: To inquire about a specific section of the Indian Penal Code, simply type the section number or describe your query. For example: “What is Section 302 of the IPC?” The chatbot will retrieve the relevant sections and provide concise descriptions.
-
Legal Document Creation: To create a legal document (e.g., an affidavit, agreement, or contract), you must provide a detailed prompt that includes all the necessary information. For example, if you want to generate a rental agreement, your prompt should include the following details:
- Names of the parties (e.g., Landlord and Tenant)
- Property address
- Terms of the agreement (e.g., rent amount, security deposit)
- Duration of the lease (e.g., 1 year)
- Any special clauses or terms (e.g., restrictions on subletting, maintenance responsibilities)
-
Precedent Search: You can request the chatbot to search for relevant case law precedents by providing case details or describing the legal issue you're researching. The chatbot will search through past case law and return relevant cases along with citations and summaries.
If you'd like to contribute to the development of the Legal Chatbot, feel free to fork the repository and submit a pull request with your changes. Please ensure that your code follows the project's coding standards and is well-documented.
This project is licensed under the MIT License - see the LICENSE file for details.
