Skip to content

Latest commit

 

History

23 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⛵ SailRAG — Nautical Document Q&A

(OCR + Hybrid Search + Local LLM)

SailRAG is a production-style Retrieval-Augmented Generation (RAG) system for querying nautical and maritime documents.
It combines hybrid retrieval (BM25 + vector search), local LLM inference, and page-level citations to provide transparent, grounded answers.

The project is designed as a portfolio-quality, end-to-end system, focusing on correctness, explainability, and realistic tradeoffs rather than API shortcuts.


✨ Key Features

🔎 Hybrid Retrieval

  • BM25 keyword search + dense vector similarity (OpenSearch)
  • Tunable weighting between lexical and semantic retrieval

📄 Adaptive PDF Ingestion

  • Page-level decision between text extraction and OCR
  • Handles mixed documents (text pages + scanned diagrams)

✂️ High-Quality Chunking

  • Windowed chunking with overlap
  • Table-of-contents detection and filtering

🧠 Local Embeddings & LLM

  • Embeddings: nomic-embed-text via Ollama
  • Answer generation: local LLM (Ollama, CPU-only)

📌 Transparent Answers

  • Each answer includes page-level citations
  • Traceable chunk IDs and document references

🖥️ Interactive UI

  • Streamlit app for asking questions
  • Live control over retrieval parameters

🐳 Fully Dockerized

  • One-command startup
  • No external paid APIs required

📚 Dataset Choice

The system is intentionally limited to English-language public maritime documents
(COLREG, sailing manuals, navigation guides) to ensure:

  • consistent OCR quality
  • embedding alignment
  • reliable retrieval performance

Included documents:

  1. COLREG — International Regulations for Preventing Collisions at Sea
    https://www.dohle-yachts.com/wp-content/uploads/2022/07/COLREGS-The-Rules-of-the-Road.pdf

  2. Basic Sailing Manual (CSUN)
    https://www.csun.edu/sites/default/files/CSUN%20Sailing%20Manual%20updated%202016_0.pdf

  3. Sailing Made Simple (Full Book)
    https://www.sjsu.edu/people/shirley.reekie/courses/sailing/s2/Sailing-Made-Simple-whole-book.pdf

  4. Nautical Charts & Navigation Guide
    https://scuba.garykessler.net/library/Charts_Navigation.pdf

  5. USCG Navigation Rules (NavRules)
    https://www.navcen.uscg.gov/sites/default/files/pdf/navRules/navrules.pdf


🧭 Architecture Overview

image

🧠 Why Hybrid Retrieval?

Pure vector search can miss exact terminology and structured references. Pure keyword search lacks semantic understanding.

SailRAG combines:

  • BM25 → precise keyword matching (e.g. “hazards”, “bridge clearance”)

  • kNN vectors → semantic similarity across phrasing

Retrieval weights are configurable per query.

📊 Retrieval Evaluation

To validate retrieval quality, an offline evaluation harness was implemented to compare different retrieval strategies using standard IR metrics.

Methodology

  • A small, curated question–evidence dataset was created from the ingested nautical documents.

  • Each question is associated with an expected document and page number containing the correct evidence.

  • For each query, the system evaluates:

-> BM25-only retrieval

-> Vector-only (kNN) retrieval

-> Hybrid retrieval with different BM25 / kNN weightings

  • Metrics are computed over the top-k retrieved chunks.

Metrics

  • Recall@5 / Recall@10 — whether the correct evidence appears in the top-k results

  • MRR@10 (Mean Reciprocal Rank) — how highly the first correct result is ranked

Results

image

Conclusions

All strategies achieved perfect Recall@10, indicating reliable evidence coverage.

Hybrid retrieval with equal BM25 and vector weighting achieved the highest MRR, meaning relevant evidence was ranked highest on average.

Based on these results, hybrid retrieval with 50/50 weighting was selected as the default configuration.

This evaluation ensures that retrieval decisions are data-driven rather than heuristic, and provides a foundation for future tuning as more documents are ingested.

🧪 Example Query

Question

How do nautical charts help you avoid hazards in unfamiliar waters?

Answer

Nautical charts are an essential tool for avoiding hazards in unfamiliar waters. Here's how they can help:

Provide detailed information about the waterway and seabed, including:

  • Shape of the coast
  • Location of islands and hazards
  • Navigation markers
  • Warnings of hazards (e.g., shallow water, rocks, or reefs)
  • Height of bridges and other obstructions
  • Show nautical traffic lanes and boat movement restrictions
  • Offer a better understanding of coastal and navigational features

To use nautical charts effectively:

  • Choose the right scale for your needs:

Small-scale charts (1:150,000 to 1:600,000) for open seas navigation

Medium-scale charts (1:50,000 to 1:150,000) for inshore navigation and coastal areas

Large-scale charts (>1:50,000) for harbors, anchorage areas, and smaller waterways

  • Familiarize yourself with chart symbols and marking
  • Learn the basic channel markers (e.g., buoys, beacons)
  • Understand ATONs (Aids to Navigation) and how to interpret them
  • Use charts in conjunction with other navigation tools, such as GPS and radar, to stay safe and on course.

By using nautical charts effectively, you can reduce the risk of encountering hazards and navigate unfamiliar waters with confidence.

Citations

  • Charts_Navigation — page 8 — chunk p8-c3

  • Charts_Navigation — page 8 — chunk p8-c2

🚀 Running the Project

Requirements

  • Docker + Docker Compose

  • ~8 GB RAM recommended (CPU-only inference)

Start everything docker compose up --build

Services

🗂️ Project Structure

image

⚙️ Configuration

All configuration is handled via environment variables and typed settings.

Examples:

  • OPENSEARCH_URL

  • OLLAMA_URL

  • OLLAMA_LLM_MODEL

  • OPENSEARCH_INDEX

🧩 Design Tradeoffs

Local inference

  • ✅ No external API costs

  • ❌ Higher latency than hosted LLMs

Page-level OCR

  • ✅ Accurate handling of mixed PDFs

  • ❌ Slightly slower ingestion

Explicit citations

  • ✅ Trustworthy, debuggable answers

  • ❌ More complex retrieval pipeline

These choices were made intentionally to reflect real production constraints.

🔮 Future Work

  • Streaming responses from the LLM

  • Caching embeddings and retrieval results

  • UI support for document upload

  • Reranking with cross-encoders

  • Multi-document summarization

About

SailRAG is a production-style RAG system for querying nautical and maritime documents (OCR + Hybrid Search + Local LLM)

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages