# Kenyan Law Document Query System
A LangChain-based system for querying Kenyan law documents and court cases using Python and Ollama for local LLM inference.
## Overview
This system allows you to:
- Load and process PDF files containing Kenyan law documents and court cases
- Create a searchable vector database using FAISS
- Query the documents using natural language with Ollama's local LLM
- Get answers with citations to specific source documents and page numbers
## Prerequisites
### 1. Ollama Installation
You must have Ollama installed on your Linux system. Install it with:
```bash
curl -fsSL
ollama.com | sh
```
### 2. Download Ollama Models
Download the required models:
```bash
# Download the LLM model (choose one)
ollama pull llama3.2 # Recommended
# OR
ollama pull mistral
# OR
ollama pull llama2
# Download the embedding model
ollama pull nomic-embed-text
```
### 3. Start Ollama Service
Make sure Ollama is running:
```bash
ollama serve
```
This should start Ollama on `
localhost`
## Setup
### 1. Environment Configuration
Copy the example environment file:
```bash
cp .env.example .env
```
Edit `.env` to configure your settings (optional, defaults should work):
```env
OLLAMA_BASE_URL=
localhost
OLLAMA_MODEL=llama3.2
OLLAMA_EMBEDDING_MODEL=nomic-embed-text
PDF_DIRECTORY=./kenyan_law_pdfs
CHUNK_SIZE=1000
CHUNK_OVERLAP=200
VECTOR_STORE_PATH=./faiss_index
```
### 2. Add PDF Documents
Place your Kenyan law PDF files in the `kenyan_law_pdfs` directory:
```bash
cp /path/to/your/pdfs/*.pdf kenyan_law_pdfs/
```
The system will recursively process all PDF files in this directory.
## Usage
### Step 1: Index Documents
First, you need to index all the PDF documents to create the vector database:
```bash
python main.py index
```
This will:
- Load all PDF files from `kenyan_law_pdfs/`
- Split documents into chunks
- Generate embeddings using Ollama
- Create and save a FAISS vector store
**Note:** Thi …