openviking-context-database
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOpenViking Context Database
OpenViking 上下文数据库
Skill by ara.so — Daily 2026 Skills collection.
OpenViking is an open-source context database for AI Agents that replaces fragmented vector stores with a unified filesystem paradigm. It manages agent memory, resources, and skills in a tiered L0/L1/L2 structure, enabling hierarchical context delivery, observable retrieval trajectories, and self-evolving session memory.
由ara.so提供的技能指南 — 2026每日技能合集。
OpenViking是一款面向AI Agents的开源上下文数据库,它以统一的文件系统范式取代了碎片化的向量存储。它采用L0/L1/L2分层结构管理智能体的记忆、资源与技能,支持分层上下文交付、可观测的检索轨迹,以及自我演化的会话记忆。
Installation
安装
Python Package
Python 包
bash
pip install openviking --upgrade --force-reinstallbash
pip install openviking --upgrade --force-reinstallOptional Rust CLI
可选 Rust CLI
bash
undefinedbash
undefinedInstall via script
通过脚本安装
Or build from source (requires Rust toolchain)
或从源码构建(需要Rust工具链)
cargo install --git https://github.com/volcengine/OpenViking ov_cli
undefinedcargo install --git https://github.com/volcengine/OpenViking ov_cli
undefinedPrerequisites
前置依赖
- Python 3.10+
- Go 1.22+ (for AGFS components)
- GCC 9+ or Clang 11+ (for core extensions)
- Python 3.10+
- Go 1.22+(用于AGFS组件)
- GCC 9+ 或 Clang 11+(用于核心扩展)
Configuration
配置
Create :
~/.openviking/ov.confjson
{
"storage": {
"workspace": "/home/user/openviking_workspace"
},
"log": {
"level": "INFO",
"output": "stdout"
},
"embedding": {
"dense": {
"api_base": "https://api.openai.com/v1",
"api_key": "$OPENAI_API_KEY",
"provider": "openai",
"dimension": 1536,
"model": "text-embedding-3-large"
},
"max_concurrent": 10
},
"vlm": {
"api_base": "https://api.openai.com/v1",
"api_key": "$OPENAI_API_KEY",
"provider": "openai",
"model": "gpt-4o",
"max_concurrent": 100
}
}Note: OpenViking readsvalues as strings; use environment variable injection at startup rather than literal secrets.api_key
创建:
~/.openviking/ov.confjson
{
"storage": {
"workspace": "/home/user/openviking_workspace"
},
"log": {
"level": "INFO",
"output": "stdout"
},
"embedding": {
"dense": {
"api_base": "https://api.openai.com/v1",
"api_key": "$OPENAI_API_KEY",
"provider": "openai",
"dimension": 1536,
"model": "text-embedding-3-large"
},
"max_concurrent": 10
},
"vlm": {
"api_base": "https://api.openai.com/v1",
"api_key": "$OPENAI_API_KEY",
"provider": "openai",
"model": "gpt-4o",
"max_concurrent": 100
}
}注意: OpenViking会将值读取为字符串;请在启动时使用环境变量注入,而非直接写入明文密钥。api_key
Provider Options
提供商选项
| Role | Provider Value | Example Model |
|---|---|---|
| VLM | | |
| VLM | | |
| VLM | | |
| Embedding | | |
| Embedding | | |
| Embedding | | |
| 角色 | 提供商值 | 示例模型 |
|---|---|---|
| VLM | | |
| VLM | | |
| VLM | | |
| Embedding | | |
| Embedding | | |
| Embedding | | |
LiteLLM VLM Examples
LiteLLM VLM 示例
json
{
"vlm": {
"provider": "litellm",
"model": "claude-3-5-sonnet-20240620",
"api_key": "$ANTHROPIC_API_KEY"
}
}json
{
"vlm": {
"provider": "litellm",
"model": "ollama/llama3.1",
"api_base": "http://localhost:11434"
}
}json
{
"vlm": {
"provider": "litellm",
"model": "deepseek-chat",
"api_key": "$DEEPSEEK_API_KEY"
}
}json
{
"vlm": {
"provider": "litellm",
"model": "claude-3-5-sonnet-20240620",
"api_key": "$ANTHROPIC_API_KEY"
}
}json
{
"vlm": {
"provider": "litellm",
"model": "ollama/llama3.1",
"api_base": "http://localhost:11434"
}
}json
{
"vlm": {
"provider": "litellm",
"model": "deepseek-chat",
"api_key": "$DEEPSEEK_API_KEY"
}
}Core Concepts
核心概念
Filesystem Paradigm
文件系统范式
OpenViking organizes agent context like a filesystem:
workspace/
├── memories/ # Long-term agent memories (L0 always loaded)
│ ├── user_prefs/
│ └── task_history/
├── resources/ # External knowledge, documents (L1 on demand)
│ ├── codebase/
│ └── docs/
└── skills/ # Reusable agent capabilities (L2 retrieved)
├── coding/
└── analysis/OpenViking像管理文件系统一样组织智能体上下文:
workspace/
├── memories/ # 智能体长期记忆(L0始终加载)
│ ├── user_prefs/
│ └── task_history/
├── resources/ # 外部知识、文档(L1按需加载)
│ ├── codebase/
│ └── docs/
└── skills/ # 可复用智能体能力(L2检索获取)
├── coding/
└── analysis/Tiered Context Loading (L0/L1/L2)
分层上下文加载(L0/L1/L2)
- L0: Always loaded — core identity, persistent preferences
- L1: Loaded on demand — relevant resources fetched per task
- L2: Semantically retrieved — skills pulled by similarity search
This tiered approach minimizes token consumption while maximizing context relevance.
- L0:始终加载 — 核心身份、持久化偏好
- L1:按需加载 — 针对任务获取相关资源
- L2:语义检索 — 通过相似性搜索获取技能
这种分层方法在最大化上下文相关性的同时,最小化了令牌消耗。
Python API Usage
Python API 使用
Basic Setup
基础设置
python
import os
from openviking import OpenVikingpython
import os
from openviking import OpenVikingInitialize with config file
使用配置文件初始化
ov = OpenViking(config_path="~/.openviking/ov.conf")
ov = OpenViking(config_path="~/.openviking/ov.conf")
Or initialize programmatically
或以编程方式初始化
ov = OpenViking(
workspace="/home/user/openviking_workspace",
vlm_provider="openai",
vlm_model="gpt-4o",
vlm_api_key=os.environ["OPENAI_API_KEY"],
embedding_provider="openai",
embedding_model="text-embedding-3-large",
embedding_api_key=os.environ["OPENAI_API_KEY"],
embedding_dimension=1536,
)
undefinedov = OpenViking(
workspace="/home/user/openviking_workspace",
vlm_provider="openai",
vlm_model="gpt-4o",
vlm_api_key=os.environ["OPENAI_API_KEY"],
embedding_provider="openai",
embedding_model="text-embedding-3-large",
embedding_api_key=os.environ["OPENAI_API_KEY"],
embedding_dimension=1536,
)
undefinedManaging a Context Namespace (Agent Brain)
管理上下文命名空间(智能体大脑)
python
undefinedpython
undefinedCreate or open a namespace (like a filesystem root for one agent)
创建或打开一个命名空间(相当于单个智能体的文件系统根目录)
brain = ov.namespace("my_agent")
brain = ov.namespace("my_agent")
Add a memory file
添加记忆文件
brain.write("memories/user_prefs.md", """
brain.write("memories/user_prefs.md", """
User Preferences
用户偏好
- Language: Python
- Code style: PEP8
- Preferred framework: FastAPI """)
- 编程语言:Python
- 代码风格:PEP8
- 偏好框架:FastAPI """)
Add a resource document
添加资源文档
brain.write("resources/api_docs/stripe.md", open("stripe_docs.md").read())
brain.write("resources/api_docs/stripe.md", open("stripe_docs.md").read())
Add a skill
添加技能
brain.write("skills/coding/write_tests.md", """
brain.write("skills/coding/write_tests.md", """
Skill: Write Unit Tests
技能:编写单元测试
When asked to write tests, use pytest with fixtures.
Always mock external API calls. Aim for 80%+ coverage.
""")
undefined当被要求编写测试时,使用pytest及夹具。
始终模拟外部API调用。目标覆盖率80%以上。
""")
undefinedQuerying Context
查询上下文
python
undefinedpython
undefinedSemantic search across the namespace
在命名空间内进行语义搜索
results = brain.search("how does the user prefer code to be formatted?")
for result in results:
print(result.path, result.score, result.content[:200])
results = brain.search("用户偏好的代码格式是什么?")
for result in results:
print(result.path, result.score, result.content[:200])
Directory-scoped retrieval (recursive)
目录范围检索(递归)
skill_results = brain.search(
query="write unit tests for a FastAPI endpoint",
directory="skills/",
top_k=3,
)
skill_results = brain.search(
query="为FastAPI端点编写单元测试",
directory="skills/",
top_k=3,
)
Direct path read (L0 always available)
直接路径读取(L0始终可用)
prefs = brain.read("memories/user_prefs.md")
print(prefs.content)
undefinedprefs = brain.read("memories/user_prefs.md")
print(prefs.content)
undefinedSession Memory & Auto-Compression
会话记忆与自动压缩
python
undefinedpython
undefinedStart a session — OpenViking tracks turns and auto-compresses
启动会话 — OpenViking会跟踪对话轮次并自动压缩
session = brain.session("task_build_api")
session = brain.session("task_build_api")
Add conversation turns
添加对话轮次
session.add_turn(role="user", content="Build me a REST API for todo items")
session.add_turn(role="assistant", content="I'll create a FastAPI app with CRUD operations...")
session.add_turn(role="user", content="为待办事项构建一个REST API")
session.add_turn(role="assistant", content="我将创建一个带CRUD操作的FastAPI应用...")
After many turns, trigger compression to extract long-term memory
多轮对话后,触发压缩以提取长期记忆
summary = session.compress()
summary = session.compress()
Compressed insights are automatically written to memories/
压缩后的见解会自动写入memories/目录
End session — persists extracted memories
结束会话 — 持久化提取的记忆
session.close()
undefinedsession.close()
undefinedRetrieval Trajectory (Observable RAG)
检索轨迹(可观测RAG)
python
undefinedpython
undefinedEnable trajectory tracking to observe retrieval decisions
启用轨迹跟踪以观测检索决策
with brain.observe() as tracker:
results = brain.search("authentication best practices")
trajectory = tracker.trajectory()
for step in trajectory.steps:
print(f"[{step.level}] {step.path} → score={step.score:.3f}")
# Output:
# [L0] memories/user_prefs.md → score=0.82
# [L1] resources/security/auth.md → score=0.91
# [L2] skills/coding/jwt_auth.md → score=0.88
---with brain.observe() as tracker:
results = brain.search("身份验证最佳实践")
trajectory = tracker.trajectory()
for step in trajectory.steps:
print(f"[{step.level}] {step.path} → score={step.score:.3f}")
# 输出示例:
# [L0] memories/user_prefs.md → score=0.82
# [L1] resources/security/auth.md → score=0.91
# [L2] skills/coding/jwt_auth.md → score=0.88
---Common Patterns
常见使用模式
Pattern 1: Agent with Persistent Memory
模式1:带持久化记忆的智能体
python
import os
from openviking import OpenViking
ov = OpenViking(config_path="~/.openviking/ov.conf")
brain = ov.namespace("coding_agent")
def agent_respond(user_message: str, conversation_history: list) -> str:
# Retrieve relevant context
context_results = brain.search(user_message, top_k=5)
context_text = "\n\n".join(r.content for r in context_results)
# Build prompt with retrieved context
system_prompt = f"""You are a coding assistant.python
import os
from openviking import OpenViking
ov = OpenViking(config_path="~/.openviking/ov.conf")
brain = ov.namespace("coding_agent")
def agent_respond(user_message: str, conversation_history: list) -> str:
# 检索相关上下文
context_results = brain.search(user_message, top_k=5)
context_text = "\n\n".join(r.content for r in context_results)
# 构建包含检索上下文的提示词
system_prompt = f"""你是一个编程助手。Relevant Context
相关上下文
{context_text}
"""
# ... call your LLM here with system_prompt + conversation_history
response = call_llm(system_prompt, conversation_history, user_message)
# Store interaction for future memory
brain.session("current").add_turn("user", user_message)
brain.session("current").add_turn("assistant", response)
return responseundefined{context_text}
"""
# ... 在此处调用LLM,传入system_prompt + conversation_history
response = call_llm(system_prompt, conversation_history, user_message)
# 存储交互内容以用于未来记忆
brain.session("current").add_turn("user", user_message)
brain.session("current").add_turn("assistant", response)
return responseundefinedPattern 2: Hierarchical Skill Loading
模式2:分层技能加载
python
undefinedpython
undefinedRegister skills from a directory structure
从目录结构中注册技能
import pathlib
skills_dir = pathlib.Path("./agent_skills")
for skill_file in skills_dir.rglob("*.md"):
relative = skill_file.relative_to(skills_dir)
brain.write(f"skills/{relative}", skill_file.read_text())
import pathlib
skills_dir = pathlib.Path("./agent_skills")
for skill_file in skills_dir.rglob("*.md"):
relative = skill_file.relative_to(skills_dir)
brain.write(f"skills/{relative}", skill_file.read_text())
At runtime, retrieve only relevant skills
在运行时,仅检索相关技能
def get_relevant_skills(task: str) -> list[str]:
results = brain.search(task, directory="skills/", top_k=3)
return [r.content for r in results]
task = "Refactor this class to use dependency injection"
skills = get_relevant_skills(task)
def get_relevant_skills(task: str) -> list[str]:
results = brain.search(task, directory="skills/", top_k=3)
return [r.content for r in results]
task = "重构此类以使用依赖注入"
skills = get_relevant_skills(task)
Returns only DI-related skills, not all registered skills
仅返回与依赖注入相关的技能,而非所有已注册技能
undefinedundefinedPattern 3: RAG over Codebase
模式3:针对代码库的RAG
python
import subprocess
import pathlib
brain = ov.namespace("codebase_agent")python
import subprocess
import pathlib
brain = ov.namespace("codebase_agent")Index a codebase
索引代码库
def index_codebase(repo_path: str):
for f in pathlib.Path(repo_path).rglob("*.py"):
content = f.read_text(errors="ignore")
# Store with relative path as key
rel = f.relative_to(repo_path)
brain.write(f"resources/codebase/{rel}", content)
index_codebase("/home/user/myproject")
def index_codebase(repo_path: str):
for f in pathlib.Path(repo_path).rglob("*.py"):
content = f.read_text(errors="ignore")
# 以相对路径为键存储
rel = f.relative_to(repo_path)
brain.write(f"resources/codebase/{rel}", content)
index_codebase("/home/user/myproject")
Query with directory scoping
按目录范围查询
def find_relevant_code(query: str) -> list:
return brain.search(
query=query,
directory="resources/codebase/",
top_k=5,
)
hits = find_relevant_code("database connection pooling")
for h in hits:
print(h.path, "\n", h.content[:300])
undefineddef find_relevant_code(query: str) -> list:
return brain.search(
query=query,
directory="resources/codebase/",
top_k=5,
)
hits = find_relevant_code("数据库连接池")
for h in hits:
print(h.path, "\n", h.content[:300])
undefinedPattern 4: Multi-Agent Shared Context
模式4:多智能体共享上下文
python
undefinedpython
undefinedAgent 1 writes discoveries
智能体1写入发现的内容
agent1_brain = ov.namespace("researcher_agent")
agent1_brain.write("memories/findings/api_rate_limits.md", """
agent1_brain = ov.namespace("researcher_agent")
agent1_brain.write("memories/findings/api_rate_limits.md", """
API Rate Limits Discovered
发现的API速率限制
- Stripe: 100 req/s in live mode
- SendGrid: 600 req/min """)
- Stripe:生产环境100次请求/秒
- SendGrid:600次请求/分钟 """)
Agent 2 reads shared workspace findings
智能体2读取共享工作区中的发现
agent2_brain = ov.namespace("coder_agent")
agent2_brain = ov.namespace("coder_agent")
Cross-namespace read (if permitted)
跨命名空间读取(如果允许)
shared = ov.namespace("shared_knowledge")
rate_limits = shared.read("memories/findings/api_rate_limits.md")
---shared = ov.namespace("shared_knowledge")
rate_limits = shared.read("memories/findings/api_rate_limits.md")
---CLI Commands (ov_cli)
CLI 命令(ov_cli)
bash
undefinedbash
undefinedCheck version
查看版本
ov --version
ov --version
List namespaces
列出命名空间
ov namespace list
ov namespace list
Create a namespace
创建命名空间
ov namespace create my_agent
ov namespace create my_agent
Write context file
写入上下文文件
ov write my_agent/memories/prefs.md --file ./prefs.md
ov write my_agent/memories/prefs.md --file ./prefs.md
Read a file
读取文件
ov read my_agent/memories/prefs.md
ov read my_agent/memories/prefs.md
Search context
搜索上下文
ov search my_agent "how to handle authentication" --top-k 5
ov search my_agent "如何处理身份验证" --top-k 5
Show retrieval trajectory for a query
显示查询的检索轨迹
ov search my_agent "database migrations" --trace
ov search my_agent "数据库迁移" --trace
Compress a session
压缩会话
ov session compress my_agent/task_build_api
ov session compress my_agent/task_build_api
List files in namespace
列出命名空间中的文件
ov ls my_agent/skills/
ov ls my_agent/skills/
Delete a context file
删除上下文文件
ov rm my_agent/resources/outdated_docs.md
ov rm my_agent/resources/outdated_docs.md
Export namespace to local directory
将命名空间导出到本地目录
ov export my_agent ./exported_brain/
ov export my_agent ./exported_brain/
Import from local directory
从本地目录导入
ov import ./exported_brain/ my_agent_restored
---ov import ./exported_brain/ my_agent_restored
---Troubleshooting
故障排除
Config Not Found
配置文件未找到
bash
undefinedbash
undefinedVerify config location
验证配置文件位置
ls -la ~/.openviking/ov.conf
ls -la ~/.openviking/ov.conf
OpenViking also checks OV_CONFIG env var
OpenViking也会检查OV_CONFIG环境变量
export OV_CONFIG=/path/to/custom/ov.conf
undefinedexport OV_CONFIG=/path/to/custom/ov.conf
undefinedEmbedding Dimension Mismatch
嵌入维度不匹配
If you switch embedding models, the stored vector dimensions will conflict:
python
undefined如果切换嵌入模型,存储的向量维度会冲突:
python
undefinedCheck current dimension setting vs stored index
检查当前维度设置与存储的索引
Solution: re-index after model change
解决方案:更换模型后重新索引
brain.reindex(force=True)
undefinedbrain.reindex(force=True)
undefinedWorkspace Permission Errors
工作区权限错误
bash
undefinedbash
undefinedEnsure workspace directory is writable
确保工作区目录可写
chmod -R 755 /home/user/openviking_workspace
chmod -R 755 /home/user/openviking_workspace
Check disk space (embedding indexes can be large)
检查磁盘空间(嵌入索引可能很大)
df -h /home/user/openviking_workspace
undefineddf -h /home/user/openviking_workspace
undefinedLiteLLM Provider Not Detected
LiteLLM 提供商未被检测到
python
undefinedpython
undefinedUse explicit prefix for ambiguous models
对模糊模型使用显式前缀
{
"vlm": {
"provider": "litellm",
"model": "openrouter/anthropic/claude-3-5-sonnet", # full prefix required
"api_key": "$OPENROUTER_API_KEY",
"api_base": "https://openrouter.ai/api/v1"
}
}
undefined{
"vlm": {
"provider": "litellm",
"model": "openrouter/anthropic/claude-3-5-sonnet", # 需要完整前缀
"api_key": "$OPENROUTER_API_KEY",
"api_base": "https://openrouter.ai/api/v1"
}
}
undefinedHigh Token Usage
令牌使用量过高
Enable tiered loading to reduce L1/L2 fetches:
python
undefined启用分层加载以减少L1/L2的获取量:
python
undefinedScope searches tightly to avoid over-fetching
严格限定搜索范围以避免过度获取
results = brain.search(
query=user_message,
directory="skills/relevant_domain/", # narrow scope
top_k=2, # fewer results
min_score=0.75, # quality threshold
)
undefinedresults = brain.search(
query=user_message,
directory="skills/relevant_domain/", # 缩小范围
top_k=2, # 减少结果数量
min_score=0.75, # 质量阈值
)
undefinedSlow Indexing on Large Codebases
大型代码库索引缓慢
python
undefinedpython
undefinedIncrease concurrency in config
在配置中增加并发数
{
"embedding": {
"max_concurrent": 20 # increase from default 10
},
"vlm": {
"max_concurrent": 50
}
}
{
"embedding": {
"max_concurrent": 20 # 从默认10增加
},
"vlm": {
"max_concurrent": 50
}
}
Or batch-write with async
或使用异步批量写入
import asyncio
async def index_async(files):
tasks = [brain.awrite(f"resources/{p}", c) for p, c in files]
await asyncio.gather(*tasks)
---import asyncio
async def index_async(files):
tasks = [brain.awrite(f"resources/{p}", c) for p, c in files]
await asyncio.gather(*tasks)
---Environment Variables Reference
环境变量参考
| Variable | Purpose |
|---|---|
| Path to |
| OpenAI API key for VLM/embedding |
| Anthropic Claude via LiteLLM |
| DeepSeek via LiteLLM |
| Google Gemini via LiteLLM |
| Override log level ( |
| Override workspace path |
| 变量 | 用途 |
|---|---|
| 覆盖 |
| 用于VLM/嵌入的OpenAI API密钥 |
| 通过LiteLLM使用Anthropic Claude |
| 通过LiteLLM使用DeepSeek |
| 通过LiteLLM使用Google Gemini |
| 覆盖日志级别( |
| 覆盖工作区路径 |
Resources
资源
- Website: https://openviking.ai
- Docs: https://www.openviking.ai/docs
- GitHub: https://github.com/volcengine/OpenViking
- Issues: https://github.com/volcengine/OpenViking/issues
- Discord: https://discord.com/invite/eHvx8E9XF3
- LiteLLM Providers: https://docs.litellm.ai/docs/providers