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
Search query string. Can be natural language or specific technical terms.
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 object for context-aware search (Python SDK only). Provides conversation history for intent analysis.
Session ID for context-aware search (HTTP API only). References an existing session.
Maximum number of results to return. The retrieval system may search more candidates internally but will only return the top N.
Minimum relevance score threshold (0-1). Only results with scores above this threshold will be returned.
Additional metadata filters for constraining search results. Structure depends on your metadata schema.
Response Structure
Returns aFindResult object with the following structure:
Matched memory contexts from user/agent memory spaces.
Matched resource contexts from the resources space.
Matched skill contexts from the agent skills space.
Query plan used for intent analysis. Contains:
queries: List of generated typed queriesreasoning: LLM reasoning for query generationsession_context: Session context summary
Detailed results for each generated query, including searched directories and thinking traces.
Total number of matched contexts across all types.
MatchedContext Structure
Each matched context contains:Viking URI of the matched context. May include level suffix (
.abstract.md, .overview.md).Type of context:
memory, resource, or skill.Context layer level:
0: L0 (abstract/directory)1: L1 (overview)2: L2 (full content/file)
L0 abstract content - concise summary of the context.
L1 overview content (for directories).
Relevance score (0-1). Higher scores indicate better matches. Combines semantic similarity with hotness scoring.
Explanation of why this context matched the query.
Category or classification of the context.
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()
| Use Case | Method | Reason |
|---|---|---|
| Conversational search | search() | Understands context from conversation |
| Multi-turn interactions | search() | Session history improves results |
| Complex queries | search() | Intent analysis and query expansion |
| Simple lookup | find() | Faster, no session overhead |
| One-shot queries | find() | No conversation context needed |
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
