Retrieval
OpenViking provides multiple retrieval methods, including simple vector similarity search, intelligent retrieval with session context, regex pattern matching, and file pattern matching.
find vs search
| Aspect | find | search |
|---|---|---|
| Intent Analysis | No | Yes |
| Session Context | No | Yes |
| Query Expansion | No | Yes |
| Default Limit | 10 | 10 |
| Use Case | Simple queries | Conversational search |
Retrieval Pipeline
The core retrieval pipeline is as follows:
Query → Intent Analysis (search only) → Vector Search (L0) → Rerank (L1) → Results- Intent Analysis (search only): Understand query intent, expand queries
- Vector Search: Find candidates using embeddings
- Rerank: Re-score using content for better accuracy
- Results: Return top-k contexts
API Reference
find()
Basic vector similarity search without session context.
1. API Implementation Introduction
The find() method performs pure vector similarity search for simple query scenarios. It uses hierarchical retrieval to search at the L0 summary level first, then matches in detail at L1/L2 levels.
Processing Pipeline:
- Convert query text to vector
- Perform global vector search within specified target URI
- Use hierarchical retrieval strategy to recursively search relevant directories and files
- Optional: Use rerank model to optimize result ordering
- Return matched context list
Code Entry Points:
openviking_cli/client/sync_http.py:SyncHTTPClient.find()- Python SDK entry (HTTP)openviking/retrieve/hierarchical_retriever.py:HierarchicalRetriever.retrieve()- Core retrieval implementationopenviking/server/routers/search.py:find()- HTTP routercrates/ov_cli/src/commands/search.rs:find()- Rust CLI command
2. Interface and Parameter Description
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| query | str | No | "" | Search query string. Required unless image_url is provided |
| image_url | str | No | None | Image query as a data:image/...;base64,..., http(s)://, or viking:// URI. Requires a multimodal embedding model |
| target_uri | str | List[str] | No | "" | Limit search to specific URI prefix |
| context_type | str | List[str] | No | None | Limit results to one or more ContextType values: memory, resource, or skill |
| tags | List[str] | No | None | Explicit retrieval tags in strict k=v form. Multiple tags are combined with AND; a result must contain every requested tag |
| node_limit | int | No | None | Maximum number of results |
| score_threshold | float | No | None | Minimum relevance score threshold |
| filter | Dict | No | None | Metadata filter |
| since | str | No | None | Lower time bound, accepts 2h or ISO 8601 / YYYY-MM-DD. Timezone-less values are interpreted as UTC. CLI --after maps to this field |
| until | str | No | None | Upper time bound, accepts 30m or ISO 8601 / YYYY-MM-DD. Timezone-less values are interpreted as UTC. CLI --before maps to this field |
| time_field | "updated_at" | "created_at" | No | "updated_at" | Metadata time field used by since / until |
| level | str | No | None | Limit results to specific level(s), e.g., 0, 1, 2, or 0,1,2. CLI --level/-L maps to this field |
| include_provenance | bool | No | False | Include provenance/query-plan details in serialized result |
| telemetry | bool | object | No | False | Attach telemetry data to response |
Target resolution notes:
- With empty
target_uri, non-ROOT retrieval searches the current user root (viking://user/{user}) and sharedviking://resources. - To filter the current user's peer collection to one peer for filesystem and retrieval operations, send
X-OpenViking-Actor-Peer: <peer_id>or construct the SDK/CLI client withactor_peer_id. See Multi-Tenant: Peer Collection Filter. - Current-user shorthand target URIs such as
viking://user/memories,viking://user/resources, andviking://user/skillsare canonicalized from the authenticated request identity.
Image search notes:
- Image queries use the image vector as the query and search L2 resource leaf nodes in the target scope by default. Results are not limited to image files; multimodal embedding decides similarity between the query image and text/image resources.
- Text-only embedding models still index image summaries, but image query input is rejected.
- Existing image resources keep their existing vectors; image-vector recall applies to images vectorized after this capability is enabled or after a later reindex.
FindResult Structure
class FindResult:
memories: List[MatchedContext] # Memory contexts
resources: List[MatchedContext] # Resource contexts
skills: List[MatchedContext] # Skill contexts
query_plan: Optional[QueryPlan] # Query plan (search only)
query_results: Optional[List[QueryResult]] # Detailed results
total: int # Total count (auto-calculated)MatchedContext Structure
class MatchedContext:
uri: str # Viking URI
context_type: ContextType # "resource", "memory", or "skill"
level: int # Tier (0=L0, 1=L1, 2=L2)
abstract: str # L0 content
overview: Optional[str] # L1 overview (optional for non-leaf nodes)
category: str # Category
score: float # Relevance score (0-1)
match_reason: str # Why this matched
relations: List[RelatedContext] # Related contexts3. Usage Examples
HTTP API
POST /api/v1/search/findcurl -X POST http://localhost:1933/api/v1/search/find \
-H "Content-Type: application/json" \
-H "X-API-Key: your-key" \
-d '{
"query": "how to authenticate users",
"limit": 10
}'Search with Target URI and Time Filter
curl -X POST http://localhost:1933/api/v1/search/find \
-H "Content-Type: application/json" \
-H "X-API-Key: your-key" \
-d '{
"query": "authentication",
"target_uri": "viking://resources",
"since": "7d",
"time_field": "created_at"
}'Search by Context Type
curl -X POST http://localhost:1933/api/v1/search/find \
-H "Content-Type: application/json" \
-H "X-API-Key: your-key" \
-d '{
"query": "authentication",
"context_type": ["memory", "resource"]
}'Image Search
curl -X POST http://localhost:1933/api/v1/search/find \
-H "Content-Type: application/json" \
-H "X-API-Key: your-key" \
-d '{
"image_url": "viking://resources/images/cat.png",
"limit": 10
}'Search by Explicit Retrieval Tags
curl -X POST http://localhost:1933/api/v1/search/find \
-H "Content-Type: application/json" \
-H "X-API-Key: your-key" \
-d '{
"query": "rollback runbook",
"tags": ["env=prod", "team=search"]
}'Tags must use strict k=v strings. When multiple tags are provided, find() requires all of them; the example above only returns contexts whose explicit retrieval tags contain both env=prod and team=search.
Python SDK
import openviking as ov
from openviking.retrieve import ContextType
client = ov.SyncHTTPClient(url="http://localhost:1933", api_key="your-key")
client.initialize()
# Basic search
results = client.find("how to authenticate users")
# Search with filter and time range
recent_emails = client.find(
"invoice",
target_uri="viking://resources/email",
since="7d",
time_field="created_at",
)
# Search only memories and resources
typed_results = client.find(
"authentication",
context_type=[ContextType.MEMORY, ContextType.RESOURCE],
)
# Search by local image, bytes, data URI, HTTP URL, or viking:// URI
image_results = client.find(image="/path/to/photo.png")
# Search by explicit retrieval tags. Multiple tags are AND-ed.
tagged_results = client.find(
"rollback runbook",
tags=["env=prod", "team=search"],
)
# Iterate through results
for ctx in results.resources:
print(f"URI: {ctx.uri}")
print(f"Score: {ctx.score:.3f}")
print(f"Type: {ctx.context_type}")
print(f"Abstract: {ctx.abstract[:100]}...")
print("---")Search with Target URI Limitation
# Search only in resources
results = client.find(
"authentication",
target_uri="viking://resources"
)
# Search only in user memories
results = client.find(
"preferences",
target_uri="viking://user/memories"
)
# Search only in current-user resources
results = client.find(
"private docs",
target_uri="viking://user/resources"
)
# Search with the peer collection filtered to one peer
peer_client = ov.SyncHTTPClient(
url="http://localhost:1933",
api_key="your-key",
actor_peer_id="web-visitor-alice",
)
peer_results = peer_client.find("invoice follow-up")
# Search only in skills
results = client.find(
"web search",
target_uri="viking://user/skills"
)
# Search in specific project
results = client.find(
"API endpoints",
target_uri="viking://resources/my-project"
)TypeScript SDK
console.log(await client.find("authentication", { targetUri: "viking://resources/docs/" }));Go SDK
result, err := client.Find(ctx, "how to authenticate users", &openviking.FindOptions{
TargetURI: "viking://resources/docs",
Limit: 10,
ContextType: []string{"resource"},
})
if err != nil {
return err
}
for _, item := range result.Resources {
fmt.Println(item.URI, item.Score)
}CLI
# Basic search
openviking find "how to authenticate users"
# Specify URI scope
openviking find "how to authenticate users" --uri "viking://resources"
# Limit to context types
openviking find "authentication" --context-type memory,resource
# With time filter
openviking find "invoice" --after 7d
# With limit
openviking find "how to authenticate users" --limit 20
# Limit to specific level(s) (L0 only)
openviking find "how to authenticate users" --level 0
# Limit to specific level(s) (L1 and L2) using short option
openviking find "how to authenticate users" -L 1,2
# Image queries use only --image; pass a local path, viking://, http(s)://, or data:image URI
openviking find --image ./query.png --uri "viking://resources/images" --limit 5
# Search by an image already stored in VikingFS
openviking find --image "viking://resources/images/cat.png" --uri "viking://resources/images" --limit 5
# Search by a public image URL
openviking find --image "https://example.com/images/cat.png" --uri "viking://resources/images" --limit 5
# Combine text and image
openviking find "red poster style" --image ./poster.png --uri "viking://resources/images"Response Example
{
"status": "ok",
"result": {
"memories": [],
"resources": [
{
"context_type": "resource",
"uri": "viking://resources/01-overview/API_Overview/Documentation_Reading_P_2c6ae38b.md",
"level": 2,
"score": 0.12808319406977778,
"category": "",
"match_reason": "",
"relations": [],
"abstract": "This document is an API documentation reading plan that outlines the structure of subsequent API reference materials organized by functional module. Main sections or topics covered include resource management API, search API, file system operations, ses...",
"overview": null
},
{
"context_type": "resource",
"uri": "viking://resources/01-overview/API_Overview/API_Endpoints/.abstract.md",
"level": 0,
"score": 0.12054087276495282,
"category": "",
"match_reason": "",
"relations": [],
"abstract": "This directory contains structured API reference documentation for the OpenViking platform, compiling detailed HTTP endpoint specifications for core and extended platform capabilities. It covers functional modules including system health checks, semanti...",
"overview": null
}
],
"skills": [],
"total": 2
}
}search()
Intelligent retrieval with session context and intent analysis.
1. API Implementation Introduction
The search() method adds session context understanding and intent analysis capability on top of find(). It better understands user query intent based on conversation history, performs query expansion, and provides more relevant search results.
Processing Pipeline:
- Load session context (if session_id is provided)
- Analyze query intent, understand actual needs combined with conversation history
- Expand queries to improve recall rate
- Execute same hierarchical retrieval pipeline as
find() - Return search results with query plan
Code Entry Points:
openviking_cli/client/sync_http.py:SyncHTTPClient.search()- Python SDK entry (HTTP)openviking/retrieve/hierarchical_retriever.py:HierarchicalRetriever.retrieve()- Core retrieval implementationopenviking/server/routers/search.py:search()- HTTP routercrates/ov_cli/src/commands/search.rs:search()- Rust CLI command
2. Interface and Parameter Description
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| query | str | No | "" | Search query string. Required unless image_url is provided |
| image_url | str | No | None | Image query as a data:image/...;base64,..., http(s)://, or viking:// URI. Requires a multimodal embedding model |
| target_uri | str | List[str] | No | "" | Limit search to specific URI prefix |
| session | Session | No | None | Session for context-aware search (SDK) |
| session_id | str | No | None | Session ID for context-aware search (HTTP) |
| context_type | str | List[str] | No | None | Limit results to one or more ContextType values: memory, resource, or skill |
| tags | List[str] | No | None | Explicit retrieval tags in strict k=v form. Multiple tags are combined with AND; a result must contain every requested tag |
| node_limit | int | No | None | Maximum number of results |
| score_threshold | float | No | None | Minimum relevance score threshold |
| filter | Dict | No | None | Metadata filter |
| since | str | No | None | Lower time bound, accepts 2h or ISO 8601 / YYYY-MM-DD. Timezone-less values are interpreted as UTC. CLI --after maps to this field |
| until | str | No | None | Upper time bound, accepts 30m or ISO 8601 / YYYY-MM-DD. Timezone-less values are interpreted as UTC. CLI --before maps to this field |
| time_field | "updated_at" | "created_at" | No | "updated_at" | Metadata time field used by since / until |
| level | str | No | None | Limit results to specific level(s), e.g., 0, 1, 2, or 0,1,2. CLI --level/-L maps to this field |
| include_provenance | bool | No | False | Include provenance/query-plan details in serialized result |
| telemetry | bool | object | No | False | Attach telemetry data to response |
search() uses the same target resolution and explicit tag filtering rules as find(), including the peer collection filter selected by X-OpenViking-Actor-Peer or SDK actor_peer_id. When image_url is provided, search() uses direct image retrieval and skips session query planning.
3. Usage Examples
HTTP API
POST /api/v1/search/searchcurl -X POST http://localhost:1933/api/v1/search/search \
-H "Content-Type: application/json" \
-H "X-API-Key: your-key" \
-d '{
"query": "best practices",
"session_id": "abc123",
"context_type": "skill",
"since": "2h",
"time_field": "updated_at",
"limit": 10
}'Search without Session (Still Performs Intent Analysis)
curl -X POST http://localhost:1933/api/v1/search/search \
-H "Content-Type: application/json" \
-H "X-API-Key: your-key" \
-d '{
"query": "how to implement OAuth 2.0 authorization code flow"
}'Image Search
curl -X POST http://localhost:1933/api/v1/search/search \
-H "Content-Type: application/json" \
-H "X-API-Key: your-key" \
-d '{
"query": "similar poster",
"image_url": "data:image/png;base64,...",
"limit": 10
}'Python SDK
import openviking as ov
from openviking.retrieve import ContextType
from openviking.message import TextPart
client = ov.SyncHTTPClient(url="http://localhost:1933", api_key="your-key")
client.initialize()
# Create session with conversation context
session = client.session()
session.add_message("user", [
TextPart(text="I'm building a login page with OAuth")
])
session.add_message("assistant", [
TextPart(text="I can help you with OAuth implementation.")
])
# Search understands conversation context
results = client.search(
"best practices",
session=session,
context_type=ContextType.SKILL,
since="2h"
)
for ctx in results.resources:
print(f"Found: {ctx.uri}")
print(f"Abstract: {ctx.abstract[:200]}...")Search without Session
# search can also be used without session
# It still performs intent analysis on the query
results = client.search(
"how to implement OAuth 2.0 authorization code flow"
)
for ctx in results.resources:
print(f"Found: {ctx.uri} (score: {ctx.score:.3f})")Image Search
results = client.search("similar poster", image="/path/to/poster.png")TypeScript SDK
console.log(await client.search("authentication", { targetUri: "viking://resources/docs/" }));Go SDK
result, err := client.Search(ctx, "best practices", &openviking.SearchOptions{
SessionID: "abc123",
ContextType: "skill",
Limit: 10,
})
if err != nil {
return err
}
fmt.Println(result.Total)CLI
# Search with session ID
openviking search "best practices" --session-id abc123
# Limit to a context type
openviking search "best practices" --context-type skill
# Search with time filter
openviking search "watch vs scheduled" --after 2026-03-15 --before 2026-03-20
# Search without session (still performs intent analysis)
openviking search "how to implement OAuth 2.0 authorization code flow"
# Limit to specific level(s) (L0 only)
openviking search "best practices" --level 0
# Limit to specific level(s) (L1 and L2) using short option
openviking search "how to implement OAuth" -L 1,2
# Image queries also use --image; they use direct retrieval and skip session planning
openviking search "similar poster" --image ./poster.png --uri "viking://resources/images"Response Example
{
"status": "ok",
"result": {
"memories": [],
"resources": [
{
"context_type": "resource",
"uri": "viking://resources/docs/oauth-best-practices",
"level": 1,
"score": 0.95,
"category": "",
"match_reason": "Context-aware match: OAuth login best practices",
"relations": [],
"abstract": "OAuth 2.0 best practices for login pages...",
"overview": "This guide covers OAuth 2.0 best practices including secure token handling, redirect URI validation, and state parameter usage..."
}
],
"skills": [],
"query_plan": {
"reasoning": "User is asking about OAuth implementation best practices, expanding to related security topics",
"queries": [
{
"query": "OAuth 2.0 best practices",
"context_type": "resource",
"intent": "Find OAuth 2.0 implementation guidelines",
"priority": 3
},
{
"query": "login page security",
"context_type": "resource",
"intent": "Find login page security recommendations",
"priority": 2
}
]
},
"total": 1
}
}grep()
Search content by pattern (regex).
1. API Implementation Introduction
The grep() method performs regex pattern matching search in the file system, used to find files and content lines containing specific patterns. Unlike semantic search, grep is exact pattern matching.
Processing Pipeline:
- Traverse file system starting from specified URI
- Perform regex matching on each file content
- Collect matching lines and position information
- Return matching results list
Code Entry Points:
openviking_cli/client/sync_http.py:SyncHTTPClient.grep()- Python SDK entry (HTTP)openviking/server/routers/search.py:grep()- HTTP routercrates/ov_cli/src/commands/search.rs:grep()- Rust CLI command
2. Interface and Parameter Description
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| uri | str | Yes | - | Viking URI to search in |
| pattern | str | Yes | - | Search pattern (regex) |
| case_insensitive | bool | No | False | Ignore case |
| exclude_uri | str | No | None | URI prefix to exclude from search |
| node_limit | int | No | 256 | Maximum number of results. Omitted requests default to 256; pass a larger integer when you need more results |
| level_limit | int | No | Python SDK: 5; HTTP API / CLI / Go SDK: 10 | Maximum directory depth to traverse. The Go SDK currently uses the HTTP API default. |
3. Usage Examples
HTTP API
POST /api/v1/search/grepcurl -X POST http://localhost:1933/api/v1/search/grep \
-H "Content-Type: application/json" \
-H "X-API-Key: your-key" \
-d '{
"uri": "viking://resources",
"pattern": "authentication",
"case_insensitive": true
}'Python SDK
import openviking as ov
client = ov.SyncHTTPClient(url="http://localhost:1933", api_key="your-key")
client.initialize()
results = client.grep(
"viking://resources",
"authentication",
case_insensitive=True,
node_limit=1024,
)
print(f"Found {results['count']} matches")
for match in results['matches']:
print(f" {match['uri']}:{match['line']}")
print(f" {match['content']}")TypeScript SDK
console.log(await client.grep("viking://resources/docs/", "authentication"));Go SDK
nodeLimit := 1024
result, err := client.Grep(ctx, "viking://resources", "authentication", &openviking.GrepOptions{
CaseInsensitive: true,
NodeLimit: &nodeLimit,
})
if err != nil {
return err
}
fmt.Println(result["count"])CLI
# Basic search
openviking grep "authentication" --uri viking://resources
# Ignore case
openviking grep "authentication" --uri viking://resources --ignore-case
# Specify depth limit
openviking grep "TODO" --uri viking://resources --level-limit 3Response Example
{
"status": "ok",
"result": {
"matches": [
{
"uri": "viking://resources/docs/auth.md",
"line": 15,
"content": "User authentication is handled by..."
}
],
"count": 1
},
"time": 0.1
}glob()
Match files by glob pattern.
1. API Implementation Introduction
The glob() method uses file wildcard pattern matching URIs, similar to Unix shell glob functionality. Used to find files and directories by name patterns.
Supported Pattern Syntax:
*matches any character (except path separator)**recursively matches any directory?matches single character[]matches character range
Code Entry Points:
sdk/python/openviking_sdk/client.py:SyncHTTPClient.glob()- Python SDK entry (HTTP)openviking/server/routers/search.py:glob()- HTTP routercrates/ov_cli/src/commands/search.rs:glob()- Rust CLI command
2. Interface and Parameter Description
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| pattern | str | Yes | - | Glob pattern (e.g., **/*.md) |
| uri | str | No | "viking://" | Starting URI |
| node_limit | int | No | 256 | Maximum number of matches to return. Omitted requests default to 256; pass a larger integer when you need more results |
3. Usage Examples
HTTP API
POST /api/v1/search/globcurl -X POST http://localhost:1933/api/v1/search/glob \
-H "Content-Type: application/json" \
-H "X-API-Key: your-key" \
-d '{
"pattern": "**/*.md",
"uri": "viking://resources"
}'Python SDK
import openviking as ov
client = ov.SyncHTTPClient(url="http://localhost:1933", api_key="your-key")
client.initialize()
# Find all markdown files (defaults to returning at most 256 matches)
results = client.glob("**/*.md", "viking://resources")
print(f"Found {results['count']} markdown files:")
for uri in results['matches']:
print(f" {uri}")
# Find all Python files with a higher explicit cap
results = client.glob("**/*.py", "viking://resources", node_limit=1024)
print(f"Found {results['count']} Python files")TypeScript SDK
console.log(await client.glob("**/*.md", "viking://resources/docs/"));Go SDK
result, err := client.Glob(ctx, "**/*.md", "viking://resources", &openviking.GlobOptions{
NodeLimit: openviking.Int(1024),
})
if err != nil {
return err
}
fmt.Println(result["count"])CLI
# Find all markdown files
openviking glob "**/*.md" --uri viking://resources
# Find all Python files
openviking glob "**/*.py"Response Example
{
"status": "ok",
"result": {
"matches": [
"viking://resources/docs/api.md",
"viking://resources/docs/guide.md"
],
"count": 2
},
"time": 0.1
}Working with Results
Read Content Progressively
Retrieval results usually only contain L0 summaries, you can progressively load more detailed content as needed.
Python SDK
import openviking as ov
client = ov.SyncHTTPClient(url="http://localhost:1933", api_key="your-key")
client.initialize()
results = client.find("authentication")
for ctx in results.resources:
# Start with L0 (abstract) - already in ctx.abstract
print(f"Abstract: {ctx.abstract}")
if ctx.level < 2:
# Get L1 (overview) for directories
overview = client.overview(ctx.uri)
print(f"Overview: {overview[:500]}...")
else:
# Load L2 (content) for files
content = client.read(ctx.uri)
print(f"File content: {content}")HTTP API
# Step 1: Search
curl -X POST http://localhost:1933/api/v1/search/find \
-H "Content-Type: application/json" \
-H "X-API-Key: your-key" \
-d '{"query": "authentication"}'
# Step 2: Read overview for directory result
curl -X GET "http://localhost:1933/api/v1/content/overview?uri=viking://resources/docs/auth" \
-H "X-API-Key: your-key"
# Step 3: Read full content for file result
curl -X GET "http://localhost:1933/api/v1/content/read?uri=viking://resources/docs/auth.md" \
-H "X-API-Key: your-key"Get Related Resources
Python SDK
import openviking as ov
client = ov.SyncHTTPClient(url="http://localhost:1933", api_key="your-key")
client.initialize()
results = client.find("OAuth implementation")
for ctx in results.resources:
print(f"Found: {ctx.uri}")
# Get related resources
relations = client.relations(ctx.uri)
for rel in relations:
print(f" Related: {rel['uri']} - {rel['reason']}")HTTP API
# Get relations for resource
curl -X GET "http://localhost:1933/api/v1/relations?uri=viking://resources/docs/auth" \
-H "X-API-Key: your-key"Best Practices
Use Specific Queries
import openviking as ov
client = ov.SyncHTTPClient(url="http://localhost:1933", api_key="your-key")
client.initialize()
# Good - specific query
results = client.find("OAuth 2.0 authorization code flow implementation")
# Less effective - too broad
results = client.find("auth")Scope Your Searches
import openviking as ov
client = ov.SyncHTTPClient(url="http://localhost:1933", api_key="your-key")
client.initialize()
# Search in relevant scope for better results
results = client.find(
"error handling",
target_uri="viking://resources/my-project"
)Use Session Context for Conversations
import openviking as ov
from openviking.message import TextPart
client = ov.SyncHTTPClient(url="http://localhost:1933", api_key="your-key")
client.initialize()
# For conversational search, use session
session = client.session()
session.add_message("user", [
TextPart(text="I'm building a login page")
])
# Search understands context
results = client.search("best practices", session=session)Related Documentation
- Resources - Resource management
- Sessions - Session context
- Context Layers - L0/L1/L2
