Overview
Thesearch() method performs intelligent semantic search with optional session context. It analyzes conversation history to understand intent and generate optimized queries for better retrieval accuracy.
Key Differences from find():
- Intent Analysis: Understands query intent from session context
- Session Context: Uses conversation history for context-aware search
- Query Expansion: Generates multiple optimized queries
- Conversational: Ideal for multi-turn conversations
Basic Usage
Parameters
string
required
Search query string. Can be natural language or specific technical terms.
string
default:""
Limit search to specific Viking URI prefix. Examples:
viking://resources/- Search only resourcesviking://user/memories/- Search only user memoriesviking://resources/my-project/- Search in specific project
Session
default:"None"
Session object for context-aware search (Python SDK only). Provides conversation history for intent analysis.
string
default:"None"
Session ID for context-aware search (HTTP API only). References an existing session.
integer
default:"10"
Maximum number of results to return. The retrieval system may search more candidates internally but will only return the top N.
float
default:"None"
Minimum relevance score threshold (0-1). Only results with scores above this threshold will be returned.
Dict[str, Any]
default:"None"
Additional metadata filters for constraining search results. Structure depends on your metadata schema.
Response Structure
Returns aFindResult object with the following structure:
List[MatchedContext]
Matched memory contexts from user/agent memory spaces.
List[MatchedContext]
Matched resource contexts from the resources space.
List[MatchedContext]
Matched skill contexts from the agent skills space.
QueryPlan
Query plan used for intent analysis. Contains:
queries: List of generated typed queriesreasoning: LLM reasoning for query generationsession_context: Session context summary
List[QueryResult]
Detailed results for each generated query, including searched directories and thinking traces.
integer
Total number of matched contexts across all types.
MatchedContext Structure
Each matched context contains:string
Viking URI of the matched context. May include level suffix (
.abstract.md, .overview.md).ContextType
Type of context:
memory, resource, or skill.integer
Context layer level:
0: L0 (abstract/directory)1: L1 (overview)2: L2 (full content/file)
string
L0 abstract content - concise summary of the context.
string
L1 overview content (for directories).
float
Relevance score (0-1). Higher scores indicate better matches. Combines semantic similarity with hotness scoring.
string
Explanation of why this context matched the query.
string
Category or classification of the context.
List[RelatedContext]
Related contexts with URIs and abstracts.
Examples
Context-Aware Search
Search Without Session
Search with Filters
HTTP API Example
Retrieval Strategy
Thesearch() method uses a sophisticated hierarchical retrieval pipeline:
1. Intent Analysis
- Analyzes session context (recent messages + compression summary)
- Generates multiple typed queries targeting different context types
- Expands queries based on conversation understanding
2. Hierarchical Retrieval
- Starting Points: Identifies relevant directories using global vector search
- Recursive Search: Explores directory hierarchies depth-first
- Score Propagation: Propagates scores from parent to child contexts
- Convergence: Stops when top-k results stabilize
3. Reranking (Optional)
- Uses reranker model for more accurate relevance scoring
- Combines semantic similarity with content-based scoring
- Applies hotness scoring based on
active_countandupdated_at
4. Result Merging
- Merges results from multiple typed queries
- Deduplicates by URI (keeps highest-scored)
- Sorts by final blended score
When to Use search() vs find()
Related Methods
- find() - Simple semantic search without session context
- Session Management - Creating and managing sessions
- Progressive Content Reading - Reading L0/L1/L2 content layers
Best Practices
- Use Sessions for Conversations: Create a session and add conversation history for better context-aware results
-
Scope Your Search: Use
target_urito limit search to relevant namespaces -
Set Score Thresholds: Filter low-quality matches with
score_threshold - Progressive Loading: Start with abstracts, then load overview/content as needed
-
Monitor Query Plans: Check
query_plan.reasoningto understand how queries were expanded
Performance Notes
- Intent Analysis: Adds ~100-200ms for LLM call (only when session provided)
- Caching: Query embeddings and session summaries are cached
- Convergence: Recursive search typically converges in 2-3 rounds
- Reranking: Optional reranker adds ~50-100ms but significantly improves accuracy
