WEN JIAYI - AI for Smart Ports & Maritime Systems
AI 应用 · 港航知识 AI APPLICATION × MARITIME KNOWLEDGE

Xiaoyi AI

港航垂直生成式AI大模型(“小懿”)

Maritime Generative AI Model · Hybrid RAG & Local Inference

“4B开源生成基座+港航稠密/稀疏混合RAG+17.29亿参数同架构模型领域LoRA调校+本地向量模型”端到端技术链路,覆盖多轮对话、复杂问题拆解、港航知识检索、SOP生成、法规资料定位、决策建议及来源追溯,并打通FastAPI服务、SSE流式输出、模型量化部署、PEFT适配器训练、GGUF转换及llama.cpp本地推理完整闭环。

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.

完整项目演示FULL PROJECT DEMO
主视频 · 小懿演示2K 1440p 高清4 秒分段流式加载正在准备高清流…
项目 READMEPROJECT README · GIT MAIN

完整项目说明Full Repository README

同步自 Git 主分支 Synced from Git main ab3234a 返回视频 Back to video

OPEN-WEIGHT LLM · RAG · LORA · EVIDENCE GOVERNANCE

小懿 AI · 港航垂直行业生成式大模型研发项目

Xiaoyi AI · Open-Weight Maritime LLM with RAG, LoRA & Evidence Governance

研发作者:温家懿 · Research Author: Wen Jiayi

把港航问答从“模型说了什么”,提升为“证据来自哪里、适用于哪个辖区和日期、何时必须拒答、谁允许推进任务”的可审计决策链。

A local generative maritime model stack where retrieval, adaptation, jurisdiction, temporal applicability, refusal, and audit evidence remain independently reviewable.

129 登记文档 · 882 知识分块 · 68 官方来源 · 260 题六版本基准

小懿AI港航助手原始形象

CI License Version Python FastAPI RAG benchmark Production boundary

核心指标 / Evidence · 能力全景 / Capabilities · 系统架构 / Architecture · 快速运行 / Quick start · 基准报告 / Benchmark · 决策保障 / Decision assurance · 证据对齐 / Evidence alignment · 日常问答 / Daily operations · 问题全集 / Question universe · 生成式模型栈 / Generative stack · 本机LoRA证据 / Local LoRA evidence · 升级路线 / Roadmap · RL证据 / RL evidence · 开源审计 / Audit


核心证明数据 / Headline evidence

证据维度 / Evidence dimension 固定结果 / Pinned result 可复验入口 / Verification entry
知识快照 / Knowledge snapshot 129份文档、882个分块、68份官方核验来源
129 documents, 882 chunks, 68 officially verified sources
data/xiaoyi_index.json + data/source_registry.json
稠密向量索引 / Dense vector index 0.6B-Embedding882 个分块生成 1024 维本地向量;内容哈希失配即失效
882 local embeddings × 1024 dimensions with content-hash invalidation
reports/local_dense_retrieval_v1.json
本机 LoRA 工程闭环 / Local LoRA loop 面向17.29亿参数训练基座,Rank 96训练104,595,456个适配器参数;含适配器总参数18.25亿,占5.730723%841条监督样本按来源隔离为622/94/125,64步后8例验证/测试loss分别下降43.55% / 40.49%,产出 PEFT + GGUF reports/local_lora_inference_v3.json + reports/local_rag_lora_e2e_v3.json
港航端到端模型评测 / Maritime model benchmark BEIR对齐检索、RAGAS概念对齐确定性代理与MLPerf风格TTFT;核心港航/证据边界35/35,港航人员日常题16/16;所有问答统一保留至少3秒可见核验窗口,单机单流非官方提交 reports/maritime_model_benchmark_v7_lora_r96.json
固定测试 / Fixed release acceptance 35题:24题检索 + 11题证据策略
35 tests: 24 retrieval + 11 evidence-policy cases
data/evaluation/maritime_qa_benchmark_v1.json
Hybrid检索 / Hybrid retrieval Hit@1/3/5 = 100% / 100% / 100% reports/maritime_rag_benchmark_v1.json
同快照对照 / Same-snapshot baseline MRR 0.9583 → 1.0000(+4.17个百分点 / pp) Hybrid Sparse vs BM25-only
证据治理 / Evidence governance 官方来源、Top-5纯度、双哈希完整率均 100%
Official-source rate, Top-5 purity, and dual-hash integrity all 100%
SHA-256固定索引、来源与核心策略代码
SHA-256-pinned index, source registry, and policy code
安全策略 / Safety policy 拒答、辖区、日期、实时数据边界 11/11通过
Refusal, jurisdiction, date, and live-data boundaries: 11/11 passed
python scripts/run_rag_benchmark.py verify --deep
助手困难集 / Assistant challenge set 多轮、复杂拆解、对抗边界各 20/20,v2 合计 60/60
Dialogue, decomposition, and adversarial boundaries: 20/20 each
reports/maritime_assistant_benchmark_v2.json
决策保障 / Decision assurance 真实问答决策就绪 14/14;冲突/新鲜度/失败关闭 16/16
Decision readiness 14/14; conflict, freshness, and fail-closed assurance 16/16
reports/maritime_decision_readiness_benchmark_v3.json
主张—证据对齐 / Claim–evidence alignment 引用角色 6/6;词面对齐 6/6;数字/日期/量值 8/8
Citation roles 6/6; lexical alignment 6/6; numeric/date/value integrity 8/8
reports/maritime_claim_alignment_benchmark_v4.json
日常运营问答 / Daily operations Q&A 能源、船舶泊位、堆场闸口、班组协同、单证、设备各 10/10;模糊/实时边界 3/3
Six frontline categories: 10/10 each; clarification/live-data boundaries: 3/3
reports/maritime_daily_operations_benchmark_v5.json
港口问题全集 / Port question universe 15业务域 × 26问题形式 = 390意图单元、780正式/日常矩阵问法;分域固定题30/30、安全边界5/5
390 intent cells and 780 formal/daily matrix prompts; fixed domain cases 30/30, boundaries 5/5
docs/PORT_QUESTION_UNIVERSE.md + reports/maritime_question_universe_benchmark_v6.json
RL 数据规模 / RL dataset scale 19,735 行 + 大规模 409,887 行(20.77×)+ NOAA港区AIS 710 个实测分钟桶 reports/rl_dataset_benchmark_v1.json
RL 固定对比 / Fixed RL comparison 3 数据集 × 3 种子 × 4 RL + PID;训练不渲染,测试后回放,所有算法平均投影约束违例 0 python scripts/run_rl_dataset_benchmark.py verify

Note

这些数字来自仓库固定发布验收集,不是第三方用户研究、生产SLA、法律意见或全球知识覆盖率。小懿默认将“公开/整理知识”“运营沙箱”“授权实时接口”和“生产动作权限”分开标识。

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
余弦相似度只参与召回,不冒充事实证明;普通问题无匹配证据时继续回答并在底部提示,高风险实时/法规事实保留核验边界
本地生成模型 / Local generative model Apache-2.0 4B Q4_K_M 作为默认生成档;1.7B Q8_0 + Rank 96建立1.046亿可训练参数的本机 LoRA 训练/推理闭环
4B quality profile plus an exact-base 1.7B Rank-96 LoRA profile
1.7B 适配器绝不挂到 4B;隔离loss只证明固定样本上的优化信号,回答质量仍需更大未见集和港航专家盲评
法规治理 / Regulatory governance 辖区、施行日期、官方来源要求、全文版权边界、证据冲突与新鲜度
Jurisdiction, applicability date, official-source and full-text boundaries, conflict and freshness checks
冲突证据阻断决策;回答不替代主管机关或法律意见
Conflicts block decision readiness; answers do not replace authorities or legal advice
SOP决策 / SOP decision support 告警解释、对象追问、步骤任务、报告生成
Alert explanation, entity clarification, stepwise tasks, reports
高风险任务强制 requires_human_confirmation
High-risk tasks force requires_human_confirmation
运营沙箱 / Operations sandbox 船舶、泊位、设备、能耗、预警与任务API
Vessel, berth, equipment, energy, alert, and task APIs
未验证网关显示“等待接入港口”,不冒充生产实绩
Unverified gateways display “awaiting port connection,” never production performance
RL实验室 / RL laboratory Q-learning、SARSA、Expected SARSA、Double Q + PID;能源与AIS港口作业双环境 UCI用于算法规模,AIS用于交通语义;服务量/等待为校准代理,不宣称现场收益
平台工程 / Platform engineering FastAPI、SSE、JWT/RBAC、SQLite、幂等、限流、审计
FastAPI, SSE, JWT/RBAC, SQLite, idempotency, rate limits, audit
外部模型调用受隐私、证据和角色门禁约束
External model calls are privacy-, evidence-, and role-gated
可观测性 / Observability readiness、Prometheus、JSON日志、请求追踪、熔断
Readiness, Prometheus, JSON logs, request tracing, circuit breaker
未配置依赖失败关闭并返回可诊断状态
Unconfigured dependencies fail closed with diagnosable status

系统架构 / Architecture

flowchart LR
  subgraph Sources["Knowledge & Runtime Sources / 知识与运行来源"]
    KB["129 docs / 882 chunks"]
    REG["Authority registry\n官方来源与辖区"]
    OPS["Sandbox or verified live adapter\n沙箱或验证实时适配器"]
  end
  subgraph Intelligence["Evidence Intelligence / 证据智能"]
    HYB["Hybrid Sparse + BM25"]
    ROUTE["Jurisdiction + effective date"]
    POLICY["Citation · refusal · privacy gates"]
    LLM["Local rules / optional compatible gateway"]
  end
  subgraph Workflow["Human-Gated Workflow / 人工门禁工作流"]
    CHAT["SSE chat + structured answer"]
    SOP["SOP task + report"]
    AUDIT["Receipt + audit persistence"]
  end
  KB --> HYB
  REG --> ROUTE --> HYB --> POLICY
  OPS --> POLICY
  POLICY --> LLM --> CHAT
  CHAT --> SOP --> AUDIT
Loading

小懿港航知识、运营和安全治理架构

项目结构 / Repository map

小懿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:

cd <xiaoyi-ai-repository>
.venv/bin/python scripts/local_model.py install-runtime
export XIAOYI_LOCAL_MODEL_PATH=/absolute/path/to/maritime-generation-4b-q4-k-m.gguf
export XIAOYI_EMBEDDING_MODEL_PATH=/absolute/path/to/maritime-embedding-0.6b-q8-0.gguf
bash run.sh

模型权重不进入公共仓库,部署时通过环境变量提供本地 GGUF 路径;公开注册表仅保留 参数规模、量化、字节数、上下文和可选 SHA-256 校验契约。模型存在且已安装 llama-server 时,run.sh 自动启用“4B 本地生成 + RAG + 回答后证据门禁”; 否则安全回退到确定性严格证据回答器。完整模型规模、LoRA 数据/训练和硬件边界见 生成式大模型方案

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.

默认使用 4B 流畅生成档;显式验证本机 LoRA 档:

XIAOYI_LOCAL_MODEL_PROFILE=lora bash run.sh

也可以手动运行:
Or run manually:

cd <xiaoyi-ai-repository>
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.lock
python scripts/build_index.py
uvicorn app.main:app --reload --port 8010

打开:
Open:

http://127.0.0.1:8010

命令行测试 / Command-line queries

cd <xiaoyi-ai-repository>
python -m app.cli "岸电 THDi 超标告警应该先检查什么?"
python -m app.cli "小懿的核心能力是什么?" --mode expert

系统说明 / System behavior

小懿是面向港航场景的本地生成式 AI 助手。它采用开源 4B 量化生成档、本地港航知识库和 RAG 检索,结合专业问答、SOP 生成、告警解释和运营建议;同时以可在本机完成反向传播的 1.7B 训练/推理档执行 LoRA,学习港航表达与回答逻辑。1.7B 适配器不会跨参数规模套到 4B。当前事实、私有资料和法规版本仍由 RAG 提供,生成结果继续通过引用、主张和数字完整性门禁。模型不可用或门禁不通过时自动回退到 local_rules 严格证据答案;只有远程模型才需要显式资料外发授权。

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.

运营看板默认使用后端持续生成的运营沙箱事件流。它具有生产形态的业务对象、时间戳、质量码、延迟和来源适配器,但明确标记为非生产实绩。切换生产时保持 port-ops.v1 契约并配置只读数据网关;高风险任务仍返回 requires_human_confirmation: true,不会因接入真实数据自动获得写权限。

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

生产数据切换说明见 港口运营数据适配器。默认无需配置;接生产网关时设置 XIAOYI_PORT_DATA_MODE=liveXIAOYI_PORT_BASE_URL 和可选只读令牌即可。网关未返回 live_data_verified=true 或版本不是 port-ops.v1 时,服务会失败关闭,绝不把数据冒充生产实绩。

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.

运行测试:
Run tests:

python -m pip install -r requirements-dev.lock
pytest -q

安全、持久化与运维 / Security, persistence, and operations

本地模式仅用于回环开发。生产模式必须使用签名 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

部署、TLS/SSO、密钥、备份、模型数据外发和多实例边界见 部署指南;信任边界见 系统架构;开源审计结论见 真实性与工程化评估

See the deployment guide for TLS/SSO, secrets, backups, model-data egress, and multi-instance boundaries; architecture for trust boundaries; and open-source readiness for the engineering audit.

当前适合问的问题 / Suitable questions

完整分类问题库见:小懿可询问问题库。其中已区分当前运营沙箱、知识库问答和生产系统接入后实时问题。

See the categorized question library, which separates current sandbox questions, knowledge-base questions, and questions that require a verified live production connection.

可复现 RL 训练实验室 / Reproducible RL laboratory

RL板块不再回放其他项目的历史训练曲线。当前实现会在后台真实执行 Q-learning、SARSA、Expected SARSA 和 Double Q-learning,并用 PID 作为控制 理论基线。训练百分比来自已完成 episode 数,模型按算法保存并计算 SHA-256。

仓库同时保留三套数据:UCI Appliances 的 19,735 条原基准、UCI Household Power 聚合得到的 409,887 条五分钟级大规模基准,以及 NOAA Los Angeles–Long Beach 港区 710 个包含 AIS 消息的一分钟实测交通桶。前两套 证明算法规模与回归稳定性,不是港口实绩;AIS中的船舶数、航速、航行状态和 船型为公开观测,服务量、积压、等待和得分为校准沙箱代理。

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.

真实RL五算法、三套公开数据与训练隔离配置
真实训练配置:三套公开数据、4 RL + PID、回合/时域/随机种子及训练无渲染、测试后回放边界均由后端接收。

# 仓库已带数据;可从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

能源环境最少提供 timestamp,load_kw;港口作业环境最少提供 timestamp,vessel_count,anchored_vessels,avg_sog_knots,并设置 XIAOYI_RL_ENVIRONMENT_TYPE=port_operations 与港口 profile。字段名不同只需 配置 JSON 映射,不改训练器。完整说明见港口RL可替换数据契约落地执行清单

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.

AIS驱动港口环境观测动作目标函数安全约束与生产写入边界
港口环境契约:11项观测、5项动作、目标函数、硬约束、动作屏蔽和生产写入边界可直接与站点字段逐项核对。

  • 港口由哪些核心业务模块组成? / What are the core operating domains of a port?
  • 集装箱码头从船舶靠泊到离港的流程是什么? / What is the container-terminal workflow from berthing to departure?
  • TOS 系统在港口运营里负责什么? / What does a TOS manage in port operations?
  • 岸电 THDi 超标告警应该先检查什么? / What should be checked first after a shore-power THDi alarm?
  • 台风红色预警下港区要启动哪些安全流程? / Which safety procedures apply under a red typhoon warning?
  • 港口碳排放盘查需要保留哪些证据? / What evidence must be retained for a port carbon inventory?
  • 小懿的系统架构是什么? / What is Xiaoyi’s system architecture?

真实港口连接器(待站点联调)/ Live-port connectors (site integration pending)

项目已预留 TOS、PCS、EMS、EAM、VTS、AIS、气象海洋和国际贸易单一窗口连接器契约,但默认全部离线,未配置任何真实端点或凭据。安全配置、站点联调、写操作门禁、回滚和审计要求见 港口连接器接入手册,环境变量模板见 .env.connectors.example

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

专业资料全目录与当前覆盖状态见 港航专业知识总目录;知识来源分级、资料审核、发布、索引重建与拒答边界见 知识库治理说明

一线调度、值班、设备、闸口、堆场和交接班人员的完整使用流程见 一线操作人员系统指南

See the maritime knowledge catalogue for current coverage and the knowledge-governance guide for source tiers, review, publication, index rebuilds, and refusal boundaries. The frontline operator guide covers dispatchers, duty teams, equipment, gates, yard personnel, and shift handover.

小懿智能联动中心(7项能力)/ Xiaoyi intelligence hub (7 capabilities)

小懿只承担港航知识、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.

小懿智能联动中心七项能力、跨系统隔离和RAG评测闭环
联动与评测闭环:7/7代表小懿平台能力已登记;标题同步给出4个系统与11项只读能力边界,并展示知识快照、检索对照、证据策略和持久审计。

GET  /api/hub/systems                            四系统目录 / four-system catalogue
GET  /api/hub/capabilities                       只读能力 / read-only capabilities
POST /api/hub/capabilities/{id}/invoke           隔离预览或授权只读 / isolated preview or approved read
POST /api/context/resolve                        统一业务上下文 / unified business context
POST /api/evidence/fuse                          证据融合 / knowledge-system-simulation fusion
POST /api/orchestrator/run                       跨系统编排 / natural-language orchestration
GET  /api/governance/audit                       SQLite持久审计 / persistent audit
POST /api/evaluation/run                         固定RAG回归 / pinned RAG regression
POST /api/evaluation/feedback                    人工反馈 / human feedback
POST /api/evaluation/feedback/{id}/review        审核入待审区 / reviewed intake staging

网页左侧点击“智能联动中心”即可查看 7/7 完成度、系统能力注册表、跨系统安全预览、RAG 评测和反馈闭环。完整验证步骤见 智能联动中心说明

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.

四系统真实联动 / Executable four-system linkage

左侧“四系统联动”会实际校验并连接港口数字孪生、能碳驾驶舱、马六甲沙盘和航行模拟器,而不是只提供启动链接。网页系统采用后端健康接口与前端页面双重身份校验;缺少的组件按固定端口契约补启动,已验证在线的服务直接复用。每次业务调用返回 trace ID、耗时和 SHA-256 回执。航行模拟器采用单次消费桥接,执行完成后清除控制指令并恢复原航线,避免重复移动。完整流程见 四系统联动中心说明

“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

仓库发布六套版本化固定基准,合计 260 题。v1 包含 40 题检索和 20 题证据 策略,其中 35 题构成固定发布测试分区;v2 新增 60 题困难集,分别检验多轮 上下文改写、复杂问题分治和对抗性证据边界;v3 新增 30 题决策保障集, 检验决策就绪度、证据冲突、新鲜度、风险级别和升级动作;v4 新增 20 题 主张—证据对齐集,检验引用角色、词面对齐及数字、日期、量值完整性;v5 新增 60 题日常运营集,覆盖能源、船舶泊位、堆场闸口、班组协同、单证和设备,并 单列 3 个模糊问法/实时边界用例;v6 建立 15 个业务域 × 26 种问题形式的 390 个意图单元与 780 条正式/日常矩阵问法,并抽取 30 题分域固定集,另列 5 题澄清、实时与官方全文边界。当前知识快照为 129 份文档、 882 个分块和 68 份官方核验来源。v1 测试分区的 24 个检索题上,Hybrid Sparse 的 Hit@1/3/5 为 100%/100%/100%,BM25-only 为 95.83%/95.83%/95.83%;MRR 为 1.0000 对 0.9583(+4.17 个百分点)。 11 个策略测试全部通过。v2 的多轮、复杂拆解与对抗边界分别为 20/20、20/20、20/20;v3 的真实问答链路与合成保障分别为 14/14、16/16; v4 的引用、对齐与数值门禁分别为 6/6、6/6、8/8;v5 六类日常问答均为 10/10,边界用例 3/3;v6 分域固定题 30/30,边界用例 5/5。

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

固定题集、JSON证据报告可读报告,以及 v2 困难集报告v3 决策保障报告v4 主张—证据对齐报告v5 日常运营问答报告v6 港口问题全集报告正式/日常问题清单 随仓库发布。六套题集都由项目维护、在开发中可见,不是“从未查看的独立留出集”或第三方 用户研究。上述数字是仓库基准上的检索与安全指标,不是港口生产收益、全球 知识覆盖率、法律意见或线上 SLA。

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.

简历可用声明与禁用表述见 简历指标口径
See resume claim semantics for permitted and prohibited wording.

112治理知识文档 GOVERNED DOCUMENTS港口、航运、海事合规与 SOP 权威资料
708检索知识分块 RETRIEVAL CHUNKS版本化知识切片与来源注册表统一治理
87.50%首位正确来源命中率 HIT@124 道固定检索题;较 BM25 提升 12.50 个百分点
0.9236混合检索 MRR HYBRID MRR同过滤 BM25-only 为 0.8507,提升 7.29 个百分点
11 / 11策略边界测试 POLICY BOUNDARY TESTS拒答、辖区、日期与实时数据边界全部通过
核心模块CORE MODULES

可治理的港航行业智能工作流Governed Maritime Intelligence Workflow

混合证据检索01 · Hybrid Evidence Retrieval

在统一版本化索引契约下实现 Sparse/BM25 检索、证据融合、来源分级与固定快照评测。

法规回答门禁02 · Regulatory Answer Guardrails

实现条款级拒答、无依据回答阻断、辖区路由、生效日期切换与实时数据边界。

SOP 与结构化报告03 · SOP & Structured Reporting

面向港航运营提供角色化流程、告警解读、追问澄清与可追溯结构化报告。

受控能力联动中心04 · Governed Capability Hub

通过工具注册、证据感知编排、JWT/RBAC、人工确认与持久化审计控制能力调用。

检索与边界评测RAG EVALUATION

固定知识快照、检索基线与安全策略评测Knowledge Snapshot, Retrieval Baseline & Safety Suite

基准设计 BENCHMARK DESIGN

60 道问题绑定官方来源键

固定基准包含 25 道历史验证题和 35 道固定测试题;测试分区由 24 道检索题与 11 个策略边界案例组成。

  • 60 份官方核验来源
  • 统计正确来源进入前 1 / 3 / 5 位的比例
  • 官方来源要求满足率:100%
基线对比 BASELINE COMPARISON

混合检索提升正确来源排序

BM25-only 是纯词法检索基线,按词频与稀有度排序且不进行语义融合;Hybrid 检索加入互补稀疏信号与证据感知重排。

  • Hit@1:75.00% → 87.50%
  • Hit@3:95.83% → 100%
  • MRR:0.8507 → 0.9236
知识治理 KNOWLEDGE GOVERNANCE

知识覆盖按目录登记,不夸大范围

权威来源注册表跟踪 41 个来源族:24 个已索引、10 个计划补充、7 个因许可隔离;24 类 / 96 主题目录记录已索引、部分覆盖和计划状态。

  • 69 个主题已索引
  • 25 个主题部分覆盖,2 个计划补充
  • 8 份核心证据文件绑定 SHA-256
评测指标结果含义
Hybrid Hit@1 / 3 / 587.50 / 100 / 100%24 道检索题中正确来源进入前 k 条结果
同过滤 BM25-only75.00 / 95.83 / 100%Hit@5 已饱和,不包装成提升
平均倒数排名 MRR0.8507 → 0.9236提升 7.29 个百分点,正确来源平均排序更靠前
证据治理完整性100%官方 Top-5 来源纯度、证据双哈希与辖区路由均通过
安全策略测试11 / 11覆盖拒答、无依据回答、辖区、日期和实时数据边界
仓库回归测试210 项通过完整 pytest、发布检查与基准哈希核验

证据边界 Evidence boundary以上为仓库固定知识快照与验收题集,不是盲测、生产客服 KPI 或“覆盖全部港航法规”的声明。离线连接器和目录型来源不等同于已索引正文;需要实时船期、气象或生产系统状态时,系统必须调用经核验适配器,否则失效关闭。

技术栈TECHNOLOGY STACK

工程与研究技术栈Engineering and Research Stack

Python · FastAPI · Pydantic
工程职责 RESPONSIBILITY

助手服务、运营接口与严格数据契约

Assistant services, operational APIs and strict data contracts
项目已实现IMPLEMENTED
Hybrid Sparse · BM25 · RAG
工程职责 RESPONSIBILITY

词法检索、证据融合与来源重排

Lexical retrieval, evidence fusion and source-aware reranking
项目已实现IMPLEMENTED
SSE · OpenAI-Compatible Gateway
工程职责 RESPONSIBILITY

流式回答与模型网关抽象

Streaming answers and model-provider abstraction
项目已实现IMPLEMENTED
JWT · RBAC · SQLite Audit
工程职责 RESPONSIBILITY

身份鉴权、权限与持久审计

Identity, authorization and persistent traceability
项目已实现IMPLEMENTED
Native JavaScript · CSS
工程职责 RESPONSIBILITY

轻依赖运营界面与报告流程

Low-dependency operator interface and report workflows
项目已实现IMPLEMENTED
Docker · GitHub Actions · pytest
工程职责 RESPONSIBILITY

可复现交付、回归与证据门禁

Reproducible delivery, regression and evidence gates
项目已实现IMPLEMENTED
项目价值PROJECT VALUE

将行业知识转化为安全运营辅助Domain Knowledge into Safe Operational Assistance

“小懿 AI”以提升行业决策质量和可追溯性为目标,而不是追求回答数量;证据排序、拒答正确性和知识覆盖状态均可见、可测试。

知识获取价值

将法规、规则、港口运营与船舶管理资料统一为可检索证据库,使调度与合规人员能够从回答直接追溯到来源,而不是依赖无法核验的模型记忆。

决策安全价值

对条款缺失、辖区错配、有效期冲突和实时数据不足执行拒答或降级,避免“语言流畅但依据错误”的专业风险,并保留人工确认。

知识治理价值

用来源注册、授权隔离、覆盖缺口、版本快照、固定题集和哈希门禁管理知识生命周期,使新增资料、模型替换和回归评测都可追踪。

能力概览CAPABILITY SUMMARY

港航行业 AI 助手全栈工程能力Full-Stack Maritime AI Assistant Engineering

该项目体现从 RAG 检索、领域提示词、API 工程、知识治理到运营工作流、审计和跨系统编排的独立全栈交付能力。

Independent full-stack delivery across RAG, domain prompting, API engineering, knowledge governance and auditable orchestration.

jiayiwen.cn/xiaoyi-ai