Nepal Legal RAG

A CLI retrieval prototype for asking questions about the Constitution of Nepal.

By Nirdesh Pokharel · Backend Software Engineer

Read as Markdown

Architecture

PDF → 800-character chunks / 100-character overlap → OpenAI embeddings → Qdrant → top-5 retrieval → streamed answer

Problem

Explore question answering over a legal PDF by providing the language model with relevant source passages.

Ingestion and retrieval

The indexing script extracts and splits PDF text, batches OpenAI embeddings, and stores vectors in Qdrant. The CLI retrieves five chunks for a question and streams an answer using the retrieved context.

Response boundaries

The prompt requests article citations when they are available in context. The interface reports when nothing relevant is found, and conversation history lasts only for the current session.

Limitations

This is a prototype rather than a production legal-advice service. Retrieval quality depends on the source PDF and extracted text. Re-indexing recreates the collection, and grounding does not guarantee that every generated answer is correct.

Index lifecycle

The indexing script recreates the nepali-constitution collection and batches embeddings in groups of 150. Text chunks use 800 characters with 100 characters of overlap. Rebuilding simplifies this prototype, but replacing a collection is an operational limitation if serving queries continuously.

Retrieval tradeoffs

The five retrieved chunks bound the context sent to the chat model. Overlap can preserve sentences near chunk boundaries, but it also repeats text in the index. A fixed chunk size and retrieval count do not establish recall or answer accuracy; those need evaluation against representative questions.

Evaluation priorities

Useful checks include questions with direct source support, cross-article questions, irrelevant questions, and malformed PDF extraction. Inspect whether cited articles support each answer. Missing retrieval context, ambiguous wording, and model-generated mistakes should be evaluated separately.

Source and maturity

The public repository contains shared configuration, indexing, a CLI chat loop, and a PDF inspection script. It is a small LangChain and Qdrant playground. There is no published production benchmark or claim that the tool can replace authoritative legal interpretation.

Source: public project repository →

More engineering notes

Contact

nirdeshpokhrel29@gmail.com