(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.
- BM25 keyword search + dense vector similarity (OpenSearch)
- Tunable weighting between lexical and semantic retrieval
- Page-level decision between text extraction and OCR
- Handles mixed documents (text pages + scanned diagrams)
- Windowed chunking with overlap
- Table-of-contents detection and filtering
- Embeddings:
nomic-embed-textvia Ollama - Answer generation: local LLM (Ollama, CPU-only)
- Each answer includes page-level citations
- Traceable chunk IDs and document references
- Streamlit app for asking questions
- Live control over retrieval parameters
- One-command startup
- No external paid APIs required
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:
-
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 -
Basic Sailing Manual (CSUN)
https://www.csun.edu/sites/default/files/CSUN%20Sailing%20Manual%20updated%202016_0.pdf -
Sailing Made Simple (Full Book)
https://www.sjsu.edu/people/shirley.reekie/courses/sailing/s2/Sailing-Made-Simple-whole-book.pdf -
Nautical Charts & Navigation Guide
https://scuba.garykessler.net/library/Charts_Navigation.pdf -
USCG Navigation Rules (NavRules)
https://www.navcen.uscg.gov/sites/default/files/pdf/navRules/navrules.pdf
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.
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
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.
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
Requirements
-
Docker + Docker Compose
-
~8 GB RAM recommended (CPU-only inference)
Start everything docker compose up --build
Services
-
Streamlit UI → http://localhost:8501
-
Backend API → http://localhost:8000
-
OpenSearch → http://localhost:9200
-
Ollama → http://localhost:11434
All configuration is handled via environment variables and typed settings.
Examples:
-
OPENSEARCH_URL
-
OLLAMA_URL
-
OLLAMA_LLM_MODEL
-
OPENSEARCH_INDEX
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.
-
Streaming responses from the LLM
-
Caching embeddings and retrieval results
-
UI support for document upload
-
Reranking with cross-encoders
-
Multi-document summarization