An end-to-end maritime generative AI stack spanning an open 4B base, dense/sparse hybrid RAG, domain LoRA adaptation, local embeddings, FastAPI/SSE serving, GGUF conversion and llama.cpp inference.
A local generative maritime model stack where retrieval, adaptation, jurisdiction, temporal applicability, refusal, and audit evidence remain independently reviewable.
These figures come from the repository’s pinned release-acceptance set—not a third-party user study, production SLA, legal opinion, or global knowledge-coverage estimate. Xiaoyi explicitly separates curated public knowledge, the operations sandbox, authorized live interfaces, and production-action authority.
固定证据总览:同屏核对三套数据血缘、五算法矩阵、观测/动作/目标、小懿训练顾问和后端按钮联动。
能力全景 / Capability map
能力平面 / Plane
已实现 / Implemented
工程边界 / Guardrail
港航RAG / Maritime RAG
open-weight 真实稠密向量 + Hybrid Sparse/BM25 对照、跨轮问题改写、复杂问题分解、证据融合、逐项引用及词面对齐校验 open-weight dense vectors plus Hybrid Sparse/BM25, history-aware rewriting, decomposition, evidence fusion and citation verification
小懿AI/
app/
main.py # FastAPI服务入口 / service entry
operations.py # 运营、任务与报告API / operations, tasks, reports
port_runtime.py # 沙箱/生产数据适配器 / sandbox/live adapters
rl_lab/ # 数据、4种RL、PID与评估 / data, 4 RL, PID, evaluation
operator_assistant.py # 一线口语与对象追问 / frontline language and clarification
xiaoyi.py # 小懿回答引擎 / answer engine
retrieval.py # Hybrid Sparse与BM25对照 / retrieval and baseline
prompts.py # 港航专业提示词 / maritime prompts
models.py # 请求与响应模型 / request-response models
config.py # 路径与配置 / paths and configuration
data/
kb/ # 港航知识库 / maritime knowledge base
evaluation/ # 固定检索与证据评测 / pinned retrieval and policy set
public/ # 公开RL数据与血缘 / public RL data and provenance
port_profiles/ # 可替换港口参数与边界 / swappable port profiles
rl_datasets.json # 数据集目录 / dataset registry
xiaoyi_index.json # 检索索引 / retrieval index
scripts/
build_index.py # 构建知识索引 / build knowledge index
build_vector_index.py # 可恢复的1024维稠密索引 / resumable dense index
build_lora_dataset.py # 来源隔离的LoRA数据 / source-isolated LoRA data
train_lora.py # PEFT LoRA训练与审计报告 / PEFT LoRA training
export_lora_gguf.py # 导出llama.cpp LoRA / export GGUF adapter
fetch_public_rl_dataset.py # 下载并校验公开RL数据 / fetch and verify
fetch_large_public_rl_dataset.py # 409,887行大规模基准 / large benchmark
fetch_noaa_port_ais_dataset.py # NOAA港区AIS场景 / public port AIS
run_rl_dataset_benchmark.py # 三数据集多种子RL证据 / multi-seed RL evidence
run_rag_benchmark.py # 固定RAG基准与哈希报告 / benchmark and hash report
web/
index.html # Web交互页面 / Web interface
tests/
test_retrieval.py # 检索验证 / retrieval verification
test_operations_api.py # 运营API与回归 / operations API and regression
快速运行 / Quick start
推荐直接使用项目启动脚本;首次运行会创建 .venv、安装运行依赖、重建索引并启动服务:
Use the project launcher. On first run it creates .venv, installs runtime dependencies, rebuilds the index, and starts the service:
Model weights are not committed. Supply local GGUF paths through environment
variables; the public registry retains only parameter count, quantization,
artifact size, context limits, and optional checksum contracts.
Xiaoyi is now an open-weight generative maritime model stack: 4B provides the default local dialogue layer, 0.6B-Embedding adds dense retrieval alongside Sparse/BM25, and an exact-base 1.7B profile supports reproducible LoRA engineering on this Intel Mac. RAG remains authoritative for current, private, and jurisdiction-sensitive facts; citation, claim-alignment, and numeric-integrity gates can reject a generated rewrite and retain the deterministic strict-evidence answer. The 1.7B adapter is never attached to the 4B model, and remote data egress still requires explicit authorization.
The operations dashboard consumes a continuously generated backend sandbox event stream. It uses production-shaped entities, timestamps, quality codes, latency, and source adapters while remaining explicitly labelled non-production. A live integration retains the port-ops.v1 contract and a read-only gateway. High-risk tasks still return requires_human_confirmation: true; real data never grants write authority automatically.
证据约束对话:现场数据未接入时明确拒绝生成运营实绩,同时保留自然语言研判、证据状态和人工确认入口。
港口运营数据 API / Port-operations API
GET /api/dashboard 聚合概况、能耗、预警、任务 / aggregate operations, energy, alerts, tasks
GET /api/runtime/status 模式、来源、质量与边界 / mode, provenance, quality, boundary
GET /api/runtime/snapshot 船舶、泊位、设备等对象 / vessels, berths, equipment, yard, gates
GET /api/operations/overview 运营概况 / operations overview
GET /api/energy?range=today 能碳趋势 / energy-carbon trend (today / 7d / 30d)
GET /api/alerts 预警筛选 / alerts filtered by level/status
GET /api/tasks/templates 任务模板 / executable task templates
POST /api/tasks 创建沙箱任务 / create sandbox task
POST /api/tasks/{task_id}/next 推进任务步骤 / advance current step
POST /api/reports 生成结构化报告 / generate structured report
GET /api/reports/{report_id} 获取报告 / retrieve report
GET /api/operator/scenarios 岗位问法与安全边界 / frontline prompts and safety limits
See the port-operations data adapter for live-data switching. No configuration is needed by default. For a production gateway, set XIAOYI_PORT_DATA_MODE=live, XIAOYI_PORT_BASE_URL, and an optional read-only token. The service fails closed unless the gateway returns live_data_verified=true and contract version port-ops.v1; unverified data is never presented as production performance.
本地模式仅用于回环开发。生产模式必须使用签名 JWT、显式主机名和 CORS 来源,否则服务拒绝启动。对话、任务、报告、自动化计划、反馈与审计保存在 SQLite;中断工作在重启后会安全标记为失败或取消,不会无声续跑。
Local mode is for loopback development only. Production requires signed JWTs, explicit hostnames, and CORS origins or the service refuses to start. Conversations, tasks, reports, automation plans, feedback, and audit evidence persist in SQLite. Interrupted work is safely marked failed or cancelled after restart rather than resuming silently.
GET /health/live 进程存活 / process liveness
GET /health/ready 深度就绪 / storage, index, RL, model, deployment readiness
GET /metrics Prometheus指标 / metrics; restrict in production
GET /api/system/info 安全与运维能力 / security and operations capability
GET /api/models 模型、回退与熔断 / models, fallback, circuit breaker
GET /api/conversations/{id} 持久对话 / identity-scoped conversation history
POST /api/chat/stream SSE流式回答 / server-sent-event answer stream
See the categorized question library, which separates current sandbox questions, knowledge-base questions, and questions that require a verified live production connection.
The RL panel no longer replays historical curves from another project. It runs Q-learning, SARSA, Expected SARSA, and Double Q-learning in a real background worker, with PID as the control-theory baseline. Progress is derived from completed episodes; each algorithm artifact is saved and SHA-256 hashed.
The repository retains the original 19,735-row UCI benchmark, a 409,887-row five-minute UCI benchmark, and 710 observed minute buckets from public NOAA AIS messages in the Los Angeles–Long Beach port area. UCI data demonstrates algorithm scale, not port performance. AIS vessel count, speed, navigation status, and vessel class are measured; service, backlog, waiting, and score are calibrated sandbox proxies. Every dataset is split chronologically into train, validation, and sealed test segments. Training is headless and only post-training evaluation creates trajectories.
# 仓库已带数据;可从UCI重建 / bundled data; optionally rebuild from pinned UCI source
.venv/bin/python scripts/fetch_public_rl_dataset.py
.venv/bin/python scripts/fetch_large_public_rl_dataset.py
.venv/bin/python scripts/fetch_noaa_port_ais_dataset.py
# 复验固定三数据集×三种子报告 / verify the pinned multi-dataset report
.venv/bin/python scripts/run_rl_dataset_benchmark.py verify
# 运行全部测试 / run all tests
.venv/bin/python -m pytest -q
接口:
GET /api/rl-lab/health
GET /api/rl-lab/algorithms
GET /api/rl-lab/datasets
GET /api/rl-lab/contracts
GET /api/rl-lab/evidence
POST /api/rl-lab/advisor
POST /api/rl-lab/runs
GET /api/rl-lab/runs/{run_id}
POST /api/rl-lab/runs/{run_id}/cancel
POST /api/rl-lab/runs/{run_id}/evaluate
The energy environment requires timestamp,load_kw. The port-operations environment requires timestamp,vessel_count,anchored_vessels,avg_sog_knots, XIAOYI_RL_ENVIRONMENT_TYPE=port_operations, and a port profile. Site columns are mapped through JSON without changing the trainer. See the swappable port RL contract and landing checklist.
The project defines connector contracts for TOS, PCS, EMS, EAM, VTS, AIS, metocean services, and maritime single windows. All are offline by default, with no real endpoint or credential bundled. See the port-connector integration manual for secure configuration, site commissioning, write gates, rollback, and audit requirements, and .env.connectors.example for environment templates.
GET /api/connectors 目录与状态 / catalogue and status
GET /api/connectors/{id}/field-mappings 字段映射 / field-mapping template
POST /api/connectors/{id}/health-check 真实健康探测 / real health probe
POST /api/connectors/{id}/write-preflight 写预检,不下发 / write preflight; no dispatch
智能操作与可审计知识库 / Intelligent operations and auditable knowledge
POST /api/automation/plans 自然语言转白名单步骤 / language-to-allowlisted steps
POST /api/automation/plans/{id}/next 回写并推进 / record result and advance
POST /api/automation/plans/{id}/confirm 人工确认或拒绝 / bind human approval or rejection
GET /api/knowledge/status 文档、来源与索引哈希 / docs, sources, index hashes
GET /api/knowledge/catalog 24类/96主题路线图 / 24-domain, 96-topic roadmap
GET /api/knowledge/authority-coverage 权威覆盖与缺口 / authority coverage and gaps
POST /api/knowledge/search 来源与双SHA-256检索 / search with source and dual hashes
GET /api/knowledge/sources 来源登记与等级 / source registry and verification level
POST /api/knowledge/intake 待审资料暂存 / stage material for human review
小懿只承担港航知识、RAG、上下文识别、能力路由、结果解释和审计,不复制能碳驾驶舱、数字孪生平台、马六甲沙盘或航行模拟器的业务功能。跨系统能力默认 offline,不访问其他系统;dry-run 只检查契约,显式配置为 live 后也只允许登记的 GET 只读能力。
Xiaoyi owns maritime knowledge, RAG, context resolution, capability routing, result explanation, and audit. It does not duplicate the CarbonOps cockpit, digital-twin platform, Malacca sandbox, or sailing simulator. Cross-system capabilities default to offline; dry-run verifies only contracts, and even explicit live mode permits registered read-only GET capabilities only.
Open “智能联动中心 / Intelligence Hub” from the left navigation to inspect 7/7 capability status, the system registry, safe cross-system previews, RAG evaluation, and the feedback loop. See the intelligence-hub guide for verification.
“Four-system linkage” validates and connects the port digital twin, energy-carbon cockpit, Malacca sandbox, and sailing simulator. It performs verified local calls, returns trace/duration/SHA-256 receipts, reuses identity-checked services, and fails closed on port conflicts.
可复现港航 RAG 与证据安全基准 / Reproducible maritime RAG and evidence-safety benchmark
The repository publishes six versioned fixed benchmarks totaling 260 cases. v1 contains 40 retrieval and 20 evidence-policy cases, with 35 in the pinned release-test partition. v2 adds 60 challenge cases for dialogue rewriting, compound-question decomposition, and adversarial evidence boundaries. v3 adds 30 decision-assurance cases for readiness, conflict, freshness, risk, and escalation actions. v4 adds 20 cases for citation roles, deterministic lexical claim–evidence alignment, and numeric/date/value integrity. v5 adds 60 daily-operations cases across energy, vessel/berth, yard/gate, shift coordination, documents, and equipment, plus three separately counted clarification/live-data boundary checks. v6 defines 390 intent cells and 780 formal/daily matrix prompts across 15 domains and 26 question forms, then tests 30 pinned domain cases plus five separately counted safety-boundary cases. The current snapshot contains 129 documents, 882 chunks, and 68 officially verified sources. On the 24 v1 retrieval tests, Hybrid Sparse reaches Hit@1/3/5 of 100%/100%/100%, versus 95.83%/95.83%/95.83% for BM25-only; MRR is 1.0000 versus 0.9583 (+4.17 percentage points). All 11 v1 policy tests pass. The three v2 categories each pass 20/20; v3 passes 14/14 query-chain and 16/16 assurance cases; v4 passes 6/6 citation, 6/6 alignment, and 8/8 numeric-integrity cases; all six v5 daily categories pass 10/10 and the boundary checks pass 3/3; v6 passes 30/30 domain cases and 5/5 boundary cases.
# 快速哈希核验 / verify report-bound data, index, and policy-code hashes
.venv/bin/python scripts/run_rag_benchmark.py verify
# 深度复算60题 / rerun all 60 cases; may take minutes on one CPU core
.venv/bin/python scripts/run_rag_benchmark.py verify --deep
# 重新生成报告 / regenerate the report
.venv/bin/python scripts/run_rag_benchmark.py run
# 核验/复跑 v2 助手困难集 / verify or rerun the v2 assistant challenge set
.venv/bin/python scripts/run_assistant_benchmark.py verify
.venv/bin/python scripts/run_assistant_benchmark.py run
# 核验/复跑 v3 决策保障 / verify or rerun v3 decision assurance
.venv/bin/python scripts/run_decision_benchmark.py verify
.venv/bin/python scripts/run_decision_benchmark.py run
# 核验/复跑 v4 主张—证据对齐 / verify or rerun v4 claim-evidence alignment
.venv/bin/python scripts/run_alignment_benchmark.py verify
.venv/bin/python scripts/run_alignment_benchmark.py run
# 核验/复跑 v5 港口日常问答 / verify or rerun the v5 daily-operations set
.venv/bin/python scripts/run_daily_operations_benchmark.py verify
.venv/bin/python scripts/run_daily_operations_benchmark.py run
# 生成问题全集并核验/复跑 v6 / build the universe and verify or rerun v6
.venv/bin/python scripts/build_port_question_universe.py
.venv/bin/python scripts/run_question_universe_benchmark.py verify
.venv/bin/python scripts/run_question_universe_benchmark.py run
The fixed questions, JSON evidence report, and readable report ship with the repository. The partition is a v1 release-acceptance set that has exposed defects during engineering fixes; it is not a never-inspected independent holdout, and it is maintained by this project rather than a third-party user study. These are repository retrieval and safety metrics—not port-production benefits, global knowledge coverage, legal advice, or an online SLA.