OpenViking

Open-Source Context Database for AI Agents

Filesystem paradigm for unified memory, resources, and skills

agent37.club

The Context Problem in Agent Systems

Five pain points OpenViking addresses

  • Fragmented context -- memory, docs, and skills scattered across separate systems (vector DBs, file stores, prompt templates)
  • Surging context demand -- agents consume more tokens as tasks grow complex, but context windows are finite
  • Poor retrieval -- flat vector search (RAG) lacks structural awareness; returns fragments without hierarchy
  • Unobservable retrieval -- no visibility into why certain context was selected or missed
  • No memory iteration -- agents cannot learn across sessions; each run starts cold

Core Thesis

Context is the bottleneck, not the model. A smarter context layer makes any LLM more capable.

Architecture: Five Pillars

1. Filesystem Management Paradigmviking:// URI protocol
2. Tiered Context Loading (L0/L1/L2)100 -> 2k -> full tokens
3. Directory Recursive Retrievalhierarchical semantic search
4. Visualized Retrieval Trajectoryobservable search paths
5. Automatic Session Managementself-evolving memory

Each pillar addresses one of the five pain points. Let's dig into each.

Pillar 1: Filesystem Paradigm

Context organized as a virtual filesystem under viking://

viking://
  |-- resources/      # project docs, repos, web
  |   |-- github.com/
  |   |   |-- volcengine/OpenViking/
  |   |       |-- README.md
  |   |       |-- docs/
  |   |       |-- examples/
  |   |-- uploads/
  |-- user/           # preferences, habits
  |-- agent/          # skills, instructions
      |-- skills/
      |-- memories/

Why a filesystem?

  • Agents already understand ls, find, tree, glob -- zero new abstractions
  • Hierarchical structure enables directory-level retrieval, not just flat vector search
  • Every context item gets a unique URI, enabling precise references
  • Natural mapping: repos become directories, docs become files, sections become sub-files

Working with the Viking Filesystem

Standard CLI commands for context navigation

# Add a GitHub repo as a resource
ov add-resource https://github.com/volcengine/OpenViking

# List contents of a directory
ov ls viking://resources/

# View tree structure (depth-limited)
ov tree viking://resources/volcengine -L 2

# Semantic search across all context
ov find "how does authentication work"

# Grep within a specific subtree
ov grep "openviking" --uri viking://resources/volcengine/OpenViking/docs

# Check server status
ov status

The CLI maps directly to the Python SDK. Every ov command has a corresponding client.method() call.

Pillar 2: Tiered Context Loading

L0 / L1 / L2 -- progressive detail on demand

TierSizeContentWhen Loaded
L0~100 tokensOne-sentence abstractAlways (index browsing)
L1~2,000 tokensCore info, usage, key conceptsWhen directory is relevant
L2Full sizeComplete original contentOnly when explicitly needed

Automatic Processing

When you add a resource, OpenViking's VLM automatically generates L0 and L1 summaries. The L2 data is stored as-is. No manual summarization needed.

# Get each tier programmatically
l0 = client.abstract(uri)  # L0
l1 = client.overview(uri)  # L1
l2 = client.read(uri)      # L2

Why Tiers Matter: Token Economics

Consider an agent with access to 50 documents averaging 10,000 tokens each.

Naive RAG Approach

Stuff everything
500,000 tokens

Load all 50 docs into context. Expensive, slow, often exceeds context window.

OpenViking Tiered

L0 scan (50 docs)
5,000 tok
L1 drill (5 relevant)
10,000 tok
L2 load (1 target)
10,000 tok

25,000 tokens total -- 95% reduction

Real-World Benchmark

OpenClaw evaluation: OpenViking with memory used 2.1M tokens vs. LanceDB RAG at 51.6M tokens. That is a 96% reduction in token consumption.

Pillar 3: Directory Recursive Retrieval

Hierarchical search that combines structure with semantics

Step 1: Intent Analysis

Parse the query into multiple retrieval conditions. "How to deploy with K8s" becomes conditions for deployment, Kubernetes, infrastructure.

Step 2: Directory-Level Vector Search

Match conditions against L0 abstracts to find high-relevance directories (not individual chunks).

Step 3: Intra-Directory Retrieval

Within matched directories, search L1 overviews to narrow to specific files/sections.

Step 4: Recursive Drill-Down

If a match is itself a directory, recurse into its subdirectories. Continues until leaf nodes are reached.

Step 5: Result Aggregation

Aggregate scored results across all branches. Return ranked context with full URI paths.

Directory Retrieval vs. Flat RAG

Traditional RAG

  • Chunk documents into fixed-size pieces
  • Embed all chunks into a flat vector space
  • Query returns top-K most similar chunks
  • No structural awareness -- related chunks may not be returned together
  • Chunk boundaries often split meaningful context

OpenViking Retrieval

  • Preserves document hierarchy as directories
  • Searches at directory level first, then drills down
  • Returns coherent context units (whole files/sections)
  • L0/L1 tiers act as natural "summaries" for matching
  • Recursive search ensures related content stays grouped

Think of it as: RAG is grep across a flat text dump. OpenViking is find + cd + cat across a structured tree.

Pillar 4: Visualized Retrieval Trajectory

Every search path is preserved and inspectable

When the agent retrieves context, OpenViking records the full trajectory:

# Retrieval trajectory for:
# "How to configure K8s deployment"

Query decomposition:
  cond_1: kubernetes deployment config
  cond_2: helm chart setup

Directory scan:
  viking://resources/ -> score: 0.82
    docs/deployment/ -> score: 0.94
      k8s-guide.md -> score: 0.97
    examples/k8s-helm/ -> score: 0.91

Selected: 2 resources, 4200 tokens

Why This Matters

  • Debugging -- see exactly why the agent got wrong context
  • Optimization -- identify poorly-scored directories, improve L0/L1 summaries
  • Trust -- verify the agent is using the right sources before acting
  • Auditing -- trace every decision back to its information source

Pillar 5: Automatic Session Management

Agents that learn from every interaction

At the end of each session, OpenViking's memory extraction mechanism processes the conversation to extract:

  • Tool call patterns -- which tools worked, with what parameters
  • Operational tips -- "this API needs retry logic with backoff"
  • User preferences -- communication style, output format preferences
  • Task strategies -- successful approaches for recurring task types

Extracted knowledge is stored under viking://user/ and viking://agent/ and surfaced in future sessions via L0/L1 retrieval.

Self-Evolving Memory

This is not a simple chat history store. The VLM processes raw session data into distilled, actionable knowledge -- extracting patterns from noise. Over time, the agent's context database becomes a growing knowledge base.

Compression

Session content is automatically compressed. Tool calls are extracted for reuse. Resource references are deduplicated. The memory grows in knowledge, not in tokens.

Python SDK: Quick Start

import openviking as ov

# Initialize (embedded mode -- no server needed)
client = ov.OpenViking(path="./data")
# Or connect to a running server:
# client = ov.SyncHTTPClient(url="http://localhost:1933")

client.initialize()

# Add a resource (URL, file, or directory)
res = client.add_resource(path="https://github.com/volcengine/OpenViking")
root_uri = res["root_uri"]

# Browse the indexed structure
client.ls(root_uri)
client.glob(pattern="**/*.md", uri=root_uri)

# Wait for L0/L1 processing to complete
client.wait_processed()

# Access tiered summaries
abstract = client.abstract(root_uri)  # L0
overview = client.overview(root_uri)  # L1
content  = client.read(uri)           # L2

# Semantic search
results = client.find("how does auth work", target_uri=root_uri)
for r in results.resources:
    print(f"  {r.uri} (score: {r.score:.4f})")

Deployment: Server Architecture

Two Modes

ModeUse Case
EmbeddedSingle-process, local dev. ov.OpenViking(path=...)
Client-ServerMulti-agent, production. openviking-server on port 1933

Components

  • openviking-server -- Python server (REST API)
  • ov CLI -- Rust-based CLI client
  • openviking Python SDK -- programmatic access
  • AGFS -- Go-based filesystem layer

K8s / Helm Deployment

# Production deployment
helm install openviking \
  ./deploy/helm/openviking \
  --set vlm.provider=openai \
  --set vlm.model=gpt-4o \
  --set embedding.provider=openai

Multi-Tenancy

Server mode supports workspace isolation. Each tenant gets a separate viking:// filesystem. See examples/multi_tenant/.

Model Configuration: Flexible Backends

VLM and embedding providers

ProviderVLM ModelsEmbeddings
Volcenginedoubao-seed-2.0-prodoubao-embedding-vision
OpenAIgpt-4o, gpt-4-visiontext-embedding-3-large
LiteLLMclaude-3.5, deepseek, gemini--
Jina--jina-embeddings-v3
Ollamallama3.1, mistral, etc.--
# ov.conf -- LiteLLM with Claude
{
  "vlm": {
    "provider": "litellm",
    "model": "claude-3-5-sonnet",
    "api_key": "sk-..."
  },
  "embedding": {
    "dense": {
      "provider": "openai",
      "model": "text-embedding-3-large",
      "dimension": 3072
    }
  }
}

Integration: Plugins and MCP

OpenViking as a context layer for existing tools

Available Integrations

IntegrationDescription
claude-memory-pluginPersistent memory for Claude
opencode-memory-pluginMemory for OpenCode agents
openclaw-pluginContext for OpenClaw framework
mcp-queryModel Context Protocol server
VikingBotBuilt-in chat interface

VikingBot Quick Start

# Install with bot support
pip install "openviking[bot]"

# Start server with built-in bot
openviking-server --with-bot

# Chat with your context
ov chat

MCP Server

The mcp-query example exposes OpenViking as an MCP tool server -- any MCP-compatible agent can use it for context retrieval.

Benchmarks: OpenClaw Evaluation

LoCoMo10 long-range dialogues -- 1,540 test cases, seed-2.0-code model

Task Completion Rate

OpenClaw baseline
35.65%
+ LanceDB (RAG)
44.55%
+ OpenViking (no mem)
52.08%
+ OpenViking (+mem)
51.23%

Input Token Consumption

OpenClaw baseline
24.6M
+ LanceDB (RAG)
51.6M
+ OpenViking (no mem)
4.3M
+ OpenViking (+mem)
2.1M

Key takeaway: +43% task completion over baseline, 96% fewer tokens than RAG. Memory mode trades ~1% accuracy for an additional 50% token savings.

Repository Structure: Polyglot Codebase

volcengine/OpenViking
|-- openviking/        # Python core package
|-- openviking_cli/    # Python CLI wrapper
|-- crates/ov_cli/     # Rust CLI (fast)
|-- src/               # Core implementation
|-- deploy/helm/       # K8s Helm charts
|-- examples/          # Integration demos
|   |-- claude-memory-plugin/
|   |-- mcp-query/
|   |-- openclaw-plugin/
|   |-- multi_tenant/
|   |-- server_client/
|   |-- skills/
|-- tests/             # Test suite

Language Mix

LanguageComponent
PythonCore server, SDK, VLM integration
RustCLI tool (performance-critical)
GoAGFS filesystem components
C++Low-level storage/indexing

Requires Python 3.10+, Go 1.22+, GCC 9+ or Clang 11+. Linux, macOS, or Windows.

Key Design Decisions

Why Not Just RAG?

  • RAG treats all documents as flat bags of chunks -- no hierarchy
  • Chunk boundaries are arbitrary, splitting semantic units
  • Top-K retrieval returns isolated fragments, not coherent context
  • No built-in memory evolution -- every session starts cold

Why Not Just Long Context?

  • 128K-1M token windows are still finite
  • Cost scales linearly with context size
  • Retrieval accuracy degrades in the "lost in the middle" zone
  • No persistence between sessions

OpenViking's Position

OpenViking is not a replacement for RAG or long context. It is a structured layer on top that organizes context hierarchically, loads it progressively, and learns across sessions.

  • Hierarchical -- filesystem structure preserves document relationships
  • Progressive -- L0/L1/L2 tiers load only what is needed
  • Persistent -- memory survives across sessions
  • Observable -- every retrieval path is traceable
  • Evolving -- knowledge base grows with usage

Comparison: Context Approaches

Feature Vector DB (RAG) Long Context OpenViking
Structure Flat chunks Linear prompt Hierarchical filesystem
Retrieval Top-K similarity Full window Recursive directory drill-down
Token Efficiency Medium (chunks) Low (load everything) High (L0/L1/L2 tiers)
Cross-Session Memory Manual None Automatic extraction
Observability Score only N/A Full trajectory
Agent Familiarity Custom API Prompt engineering ls, find, tree, glob
Multi-Tenancy Index per tenant N/A Workspace isolation

Configuration: ov.conf Deep Dive

// ~/.openviking/ov.conf
{
  "storage": {
    "workspace": "/data/openviking"
  },
  "log": {
    "level": "INFO",
    "output": "stdout"
  },
  "embedding": {
    "dense": {
      "api_base": "https://api.openai.com/v1",
      "api_key": "sk-...",
      "provider": "openai",
      "dimension": 3072,
      "model": "text-embedding-3-large"
    },
    "max_concurrent": 10
  },
  "vlm": {
    "api_base": "https://api.openai.com/v1",
    "api_key": "sk-...",
    "provider": "openai",
    "model": "gpt-4o",
    "max_concurrent": 100
  }
}

Key Settings

  • workspace -- filesystem root for all stored context
  • embedding.dense -- vector model for semantic matching
  • vlm -- vision-language model for L0/L1 generation and memory extraction
  • max_concurrent -- parallel request limits (tune for your API tier)

VLM Is Required

The VLM is not optional -- it powers L0/L1 summary generation, memory extraction, and intent analysis during retrieval. Choose a capable model.

Running Locally with Ollama

Fully local setup -- no API keys needed

# 1. Start Ollama with a model
ollama pull llama3.1
ollama serve

# 2. Configure OpenViking
# ~/.openviking/ov.conf
{
  "vlm": {
    "provider": "litellm",
    "model": "ollama/llama3.1",
    "api_base": "http://localhost:11434"
  },
  "embedding": {
    "dense": {
      "provider": "jina",
      "model": "jina-embeddings-v3",
      "api_key": "jina_...",
      "dimension": 1024
    }
  }
}

# 3. Launch
openviking-server

LiteLLM Auto-Detection

LiteLLM automatically routes based on model name prefix:

PrefixRoutes To
claude-*Anthropic
deepseek-*DeepSeek
gemini-*Google
ollama/*Local Ollama
hosted_vllm/*vLLM server

When to Use OpenViking

Strong Fit

  • Agents that operate on large codebases or documentation sets
  • Multi-session agents that need persistent memory
  • Teams building agent frameworks who want a drop-in context layer
  • Projects where token cost is a significant concern
  • Systems requiring auditable context retrieval

Consider Alternatives If

  • Your context fits comfortably in a single prompt (small projects)
  • You need sub-millisecond retrieval (OpenViking trades latency for structure)
  • You are building a simple chatbot without tool use or multi-step reasoning
  • You want a pure vector database (use Pinecone, Weaviate, LanceDB)

Sweet Spot

OpenViking shines for complex agents that work across many documents, learn over time, and need to manage token budgets intelligently.

Open Questions and Trade-offs

Things to Watch

  • VLM dependency -- L0/L1 generation quality depends heavily on your VLM choice. Weak models produce poor summaries.
  • Processing latency -- adding a large repo triggers async VLM calls for every file. Initial indexing can be slow.
  • Go + C++ requirements -- AGFS needs Go 1.22+ and a C++ compiler. Not trivial for all environments.
  • Young ecosystem -- 17.3k stars but still early. API may evolve.

Discussion Points

  • How does the filesystem paradigm scale to millions of files?
  • Can L0/L1 summaries be incrementally updated without full reprocessing?
  • How does multi-agent contention work in server mode?
  • What happens when memory extraction captures incorrect patterns?
  • How does this compare to emerging standards like MCP for context management?

OpenViking

Context is the bottleneck. Structure is the solution.

pip install openviking

github.com/volcengine/OpenViking  ·  openviking.ai/docs

agent37.club