RAG · Reranking

ARE: Aviation Regulation Explainer

Plain-language answers about US aviation regulations, grounded in eCFR text.

Last commit
May 2025
Stack
  • LangChain
  • ChromaDB
  • OpenAI embeddings
  • Cohere Rerank
  • GPT-3.5 Turbo
  • Streamlit
  • eCFR API

Problem

Title 14 is large and deeply nested, so finding the section that answers a question is slow. The app turns the official XML into searchable chunks tagged with their Part and Section, and answers only from retrieved regulation text, saying so plainly when the answer isn’t there.

Architecture

eCFR XMLPart/Section chunksembedChromaDBquestiontop 10 searchCohere top 5answersource sections
eCFR XMLPart/Section chunksembedChromaDBquestiontop 10 searchCohere top 5answersource sections

A one-time build indexes a dated Title 14 snapshot. Each question retrieves 10 chunks, Cohere keeps the best 5, and the model answers only from those.

  • Streamlit appapp.py

    Builds the database on first run, then a question box with expandable sources.

  • eCFR ingestiondata_processing.py

    Fetches Title 14 XML and walks Part → Section into documents.

  • Retrieval chainrag_setup.py

    Chroma retriever wrapped in a Cohere reranking compressor, answer and sources in parallel.

Key decisions

  • Chunks follow the regulation’s structure

    The parser walks Part → Section and makes one document per heading or paragraph element, splitting only elements longer than 800 characters (75 overlap).

    data_processing.py:46-119
  • Hierarchy kept as metadata

    Each chunk carries title, part and section numbers plus a hierarchy id like Title-14/Part-x/Section-y, which the UI shows for every source.

    data_processing.py:92-111
  • Two-stage retrieval

    Chroma returns 10 candidates and Cohere rerank-v3.5 keeps the top 5 through a contextual compression retriever.

    rag_setup.py:51-80
  • Context-only prompt with a refusal

    The prompt allows answers only from the retrieved context, returns a fixed “cannot be found” sentence otherwise, gives no legal advice, and runs at temperature 0.

    rag_setup.py:83-101

In action

ARE answering “Explain what IFR conditions are” with five source documents listed below the answer
From the repo: answering a question about IFR conditions, with its source sections below.

Run it

Appstreamlit run app.py