Skip to content

πŸ“š Legal Q&A RAG Bot | AI-powered chatbot for legal document understanding and question answering using LangChain, OpenAI, and FAISS.

License

Notifications You must be signed in to change notification settings

Vsandeep-ai-dev/legal-qa-rag-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– Legal Q&A RAG Bot

An AI-powered Legal Question-Answering system that uses Retrieval-Augmented Generation (RAG) to provide accurate responses from a legal document database. It combines LangChain, vector embeddings, and OpenAI’s GPT models to ensure reliable legal answers.


πŸš€ Features

  • βœ… Ask Legal Questions – Get answers based on actual legal documents.
  • βœ… Retrieval-Augmented Generation (RAG) – Combines document context with GPT for accuracy.
  • βœ… LangChain Integration – Handles document loading, chunking, and chaining.
  • βœ… Embedding + Vector Store – Converts documents into vectors for semantic search.
  • βœ… Simple Streamlit UI – Easy-to-use web interface.
  • βœ… OpenAI GPT – Powered by GPT-3.5/4 for final response generation.

πŸ“ Project Structure

legal-qa-rag-bot/
β”œβ”€β”€ .gitignore
β”œβ”€β”€ LICENSE
β”œβ”€β”€ README.md
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ app.py                # Streamlit app UI
β”œβ”€β”€ qa_chain.py           # LangChain question-answering logic
β”œβ”€β”€ vector_store.py       # Vector DB (FAISS) logic
β”œβ”€β”€ data/
β”‚   └── legal_docs/       # Upload your PDF/DOCX legal files here
β”œβ”€β”€ .env                  # API keys (DO NOT COMMIT)

πŸ› οΈ Tech Stack

  • Python 3.11+
  • LangChain
  • FAISS (Facebook AI Similarity Search)
  • OpenAI GPT-3.5/4
  • Streamlit for UI
  • python-dotenv

▢️ How to Run

  1. Create a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Set up .env file:

Create a .env file in the root with this line:

OPENAI_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  1. Add Legal Documents:

Place your .pdf or .docx files inside the data/legal_docs/ folder.

  1. Run the app:
streamlit run app.py

βœ… Best Practices

  • Never commit .env or API keys.
  • Add this to your .gitignore file:
.env
  • Clean up large or unnecessary files before pushing.

πŸ§ͺ Testing & Output

  • Ask natural language legal questions.
  • Answers will be based only on your uploaded documents.
  • Everything happens locally except OpenAI API calls.

πŸ’‘ Future Enhancements

  • πŸ” Authentication for private deployments
  • πŸ“Š Admin dashboard for monitoring usage
  • πŸ’¬ Chat history + feedback collection
  • 🌍 Multi-language support
  • 🧠 Plug into government APIs or court data

πŸ“ License

This project is licensed under the MIT License.


🀝 Contributing

Pull requests are welcome. For major changes, open an issue first to discuss the improvements you'd like to make.


πŸ“Έ Demo Screenshot (Optional)

Place your demo images or gifs in a `screenshots/` folder and reference like:

![App Screenshot](screenshots/demo.png)

πŸ”— Useful Commands

git init
git add .
git commit -m "Initial commit"
git branch -M main
git remote add origin https://github.com/YOUR_USERNAME/legal-qa-rag-bot.git
git push -u origin main

About

πŸ“š Legal Q&A RAG Bot | AI-powered chatbot for legal document understanding and question answering using LangChain, OpenAI, and FAISS.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages