A governance-first maritime assistant where retrieval, jurisdiction, temporal applicability, refusal, task progression, and audit evidence are 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.
小懿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
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:
小懿是面向港航场景的小型 AI 助手。它采用本地港航知识库和 RAG 检索,结合专业问答、SOP 生成、告警解释和运营建议。默认 local_rules 生成路径不依赖外部模型;也可显式配置 OpenAI-compatible 模型网关。只有已通过证据门禁、不含沙箱运营数据且完成外发授权的回答才允许发往外部模型;其他情况保留本地严格证据答案。
Xiaoyi is a compact AI assistant for maritime and port operations. It combines a local maritime knowledge base and RAG retrieval with professional Q&A, SOP generation, alert explanation, and operational guidance. The default local_rules path does not depend on an external model; an OpenAI-compatible gateway can be configured explicitly. Only answers that pass the evidence gate, contain no sandbox operational data, and receive outbound authorization may reach an external model; all other cases retain the local strict-evidence answer.
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.
可复现港航 RAG 与证据安全基准 / Reproducible maritime RAG and evidence-safety benchmark
The repository publishes a fixed 60-question set: 40 retrieval cases and 20 evidence-policy cases, with 35 forming the pinned v1 test partition. The knowledge snapshot contains 112 documents, 708 chunks, and 60 officially verified sources. Across the 24 retrieval questions in the test partition, Hybrid Sparse reaches Hit@1/3/5 of 87.50%/100%/100%, versus 75.00%/95.83%/100% for BM25-only. Hybrid improves first-rank hit rate by 12.50 percentage points and MRR from 0.8507 to 0.9236 (+7.29 percentage points). Since both methods already reach 100% Hit@5, the README does not misrepresent the saturated Top-5 metric as an improvement. Eleven policy tests cover clause-level refusal, unsupported-answer blocking, jurisdiction routing, regulation-date switching, and live-data boundaries; all 11 pass.
# 快速哈希核验 / 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
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.