Skip to content

fuseai-fellowship/Law-search-Engine-Nepali

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nepali Law Search Engine

Overview

This project is a Retrieval-Augmented Generation (RAG) system built to search and understand Nepali legal documents.
It combines traditional keyword search (BM25), semantic vector search (FAISS), and cross-encoder reranking to provide the most relevant results, and can generate answers using Gemini API.

Features

  • Hybrid Search: Combines BM25 (Elasticsearch) and FAISS semantic similarity.
  • Cross-Encoder Reranker: Reorders retrieved documents using a transformer-based reranker for higher accuracy.
  • Multilingual Support: Handles both English and Nepali texts with multilingual models.
  • RAG Integration: Generates answers using the retrieved context and Gemini LLM.
  • Streamlit UI: Has a streamlit UI for the user

Project Structure

│
├── dataset/
|   ├── edited/
│   ├── indexes/
|   |   ├── faiss/
│   ├── processed/
│   ├── embeddings/
│   └── raw_pdfs/
├── notebooks/ 
├── scripts/
├── requirements.txt 
├── .gitignore 
└── README.md

How the Search Works

  1. User Query: The user inputs a question or keyword (either in English or Nepali).
  2. Document Retrieval: Both BM25 and FAISS independently retrieve top chunks from all law documents.
  3. Reranking: The cross-encoder model assigns relevance scores and ranks them accordingly.
  4. Context Formation: The top results are combined to form a structured context.
  5. Answer Generation: The RAG model (using Gemini API) generates a natural-language answer based on the retrieved context.
  6. Display: The Streamlit interface shows both the generated answer and the supporting references (chapter, section, law name).

Multilingual Handling

  • The system supports both Nepali and English queries and documents.
  • A multilingual sentence transformer is used for embeddings to ensure cross-language semantic understanding.
  • Each document in the dataset includes:
    • doc_id (unique per law or language version)
    • chunk_id
    • chapter
    • section
    • text
  • All documents (both languages) are stored under a single Elasticsearch index and included in the same FAISS index.

Pre-requisite

1. Elasticsearch 
2. Python(3.10+)

Installation

1.Clone the Repository

git clone https://github.com/fuseai-fellowship/Law-search-Engine-Nepali.git
cd Law-search-Engine-Nepali

2. Create and Activate Virtual Environment

python -m venv env
source env/bin/activate

3. Install Dependencies

pip install -r requirements.txt

4. Setup environment variable

ELASTIC_PASSWORD=your_elasticsearch_password 
GEMINI_API_KEY=google_studio_api_key

5. Start docker service

To setup elasticsearch indexing please visit our notebooks section

docker start elasticsearch_container

6. Run streamlit application

cd scripts/
streamlit run app.py

The app will be available at: 👉 http://localhost:8501

7. Demonstration

alt text

alt text

alt text

alt text

Future Enhancements

  • Add context summarization for long documents
  • Include Nepali Question Answering (QA) model fine-tuned on legal datasets
  • Integrate document upload and indexing directly from UI
  • Enhance search visualization and ranking transparency

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors