Skip to content

架构概述 ​

OpenViking 是为 AI Agent 设计的上下文数据库,将所有上下文(Memory、Resource、Skill)统一抽象为目录结构,支持语义检索和渐进式内容加载。

系统概览 ​

OpenViking system overview CLI, SDK and HTTP clients call the HTTP Server (REST API and the /mcp endpoint), which calls the Service Layer. The Service Layer drives three pipelines: Retrieval; Sessions with memory extraction; and Resource and Skill import with parse and semantic queues. All three read and write VikingFS, which stores content in RAGFS and indexes it in the vector index. CLI · SDK · HTTP clientHTTP ServerREST API · /mcpService LayerFS · Search · Session · Resource · Pack · DebugRetrievalsearch · findSessionsMemoryextractionResource /Skill importParse /Semantic queuesVikingFSvirtual filesystemRAGFSsource filesVector indexvector records
文本版本
text
CLI / SDK / HTTP client
          |
      HTTP Server
          |
      Service Layer
          |
   +------+------+----------------+
   |             |                |
Retrieval     Sessions       Resource / Skill import
   |             |                |
   |       Memory extraction  Parse / Semantic queues
   |             |                |
   +-------------+----------------+
                 |
             VikingFS
           /          \
      RAGFS         Vector index

核心模块 ​

模块职责关键能力
Client统一入口通过 HTTP API 提交 SDK/CLI 支持的操作
Service业务逻辑FSService、SearchService、SessionService、ResourceService、PackService、DebugService
Retrieve上下文检索意图分析(IntentAnalyzer)、全局检索(HierarchicalRetriever)、Rerank 精排
Session会话管理消息记录、使用追踪、会话归档、触发记忆提交
Parse上下文提取文档解析(PDF/MD/HTML)、树构建(TreeBuilder)、异步语义生成
Memory记忆提取按 MemoryType Schema 提取记忆(ExtractLoop),由 LLM 合并去重后以 patch 写回(MemoryUpdater);由 SessionCompressorV3 编排
Storage存储层VikingFS 虚拟文件系统、向量索引、RAGFS 集成

Service 层 ​

Service 层将业务逻辑与传输层解耦,CLI 和 SDK 通过 HTTP Server 访问业务能力:

Service职责主要方法
FSService文件系统操作ls, mkdir, rm, mv, tree, stat, read, abstract, overview, grep, glob
SearchService语义搜索search, find
SessionService会话管理session, sessions, commit, delete
ResourceService资源导入add_resource, add_skill, wait_processed
PackService导入导出、备份恢复export_ovpack, import_ovpack, backup_ovpack, restore_ovpack
DebugService调试服务observer (ObserverService)

双层存储 ​

OpenViking 采用双层存储架构,实现内容与索引分离(详见 存储架构):

存储层职责内容
RAGFS内容存储L0/L1/L2 完整内容、多媒体文件、关联关系
向量库索引存储URI、向量、元数据和检索需要的文本(包括摘要)

数据流概览 ​

添加上下文 ​

输入 → Parser → TreeBuilder → ResourceProcessor → RAGFS → SemanticQueue → 向量库
  1. Parser:将源文档解析为文件与目录;是否调用模型取决于所选 Parser
  2. TreeBuilder:确定目标 URI,保留临时产物引用
  3. ResourceProcessor:将内容写入 RAGFS,入队语义处理
  4. SemanticQueue:异步自底向上生成 L0/L1
  5. 向量库:建立索引用于语义搜索

检索上下文 ​

查询 → 意图分析 → 全局检索 → Rerank → 结果
  1. 意图分析:分析查询意图,生成 0-5 个类型化查询
  2. 全局检索:每条查询在权限范围内执行一次向量搜索
  3. Rerank:可选,对召回候选统一精排一次
  4. 结果:返回按相关性排序的上下文

会话提交 ​

消息 → 归档边界 → 归档 → 记忆提取 → 存储
  1. 消息:累积对话消息和使用记录
  2. 归档边界:按提交参数划分归档消息和保留消息;默认归档全部当前消息
  3. 归档:生成历史片段的 L0/L1
  4. 记忆提取:根据记忆策略和 MemoryType Schema 从消息中提取记忆
  5. 存储:写入 RAGFS + 向量库

部署模式 ​

HTTP 模式 ​

用于团队共享、生产环境和跨语言集成:

python
# Python SDK 连接 OpenViking Server
from openviking_sdk import SyncHTTPClient

client = SyncHTTPClient(url="http://localhost:1933", api_key="your-key")
bash
# 或使用 curl / 任意 HTTP 客户端
curl http://localhost:1933/api/v1/search/find \
  -H "X-API-Key: your-key" \
  -H "Content-Type: application/json" \
  -d '{"query": "how to use openviking"}'
  • Server 作为独立进程运行(openviking-server)
  • 客户端通过 HTTP API 连接
  • 支持任何能发起 HTTP 请求的语言
  • 参见 服务部署 了解配置方法

设计原则 ​

原则说明
存储层纯粹存储层只做 RAGFS 操作和基础向量搜索,Rerank 在检索层完成
三层信息L0/L1/L2 实现渐进式详情加载,节省 Token 消耗
两阶段检索向量搜索召回候选 + Rerank 精排提高准确性
单一数据源RAGFS 保存源文件,向量记录保留检索需要的文本与元数据

相关文档 ​

Open source under the AGPL-3.0 License. Font licenses