[Feature]: Add configurable search result limits and per-query retrieval options
Issue Origin
Observed or reproduced in a real environment
Problem Statement
When using OpenViking as a retrieval layer for agent applications, different queries often require different retrieval depths. A simple factual query may only need a few highly relevant results, while a broader research or planning query may benefit from retrieving more candidates.
Currently, applications may need to handle this behavior outside OpenViking or rely on a fixed/default retrieval configuration. This makes it harder to tune the retrieval quality and latency for different workloads.
A per-query way to control the number of returned results and related retrieval parameters would make OpenViking more flexible for production agent workflows.
Proposed Solution
Add optional per-query retrieval parameters so callers can override the default search configuration when needed.
For example, allow callers to specify:
top_k— maximum number of results to return.min_score— optional minimum relevance threshold.mode— optionally select between lightweight/simple retrieval and deeper retrieval when supported.- Preserve the existing defaults when these parameters are omitted.
The global configuration should remain available as the default, while query-level parameters take precedence for that individual request.
This would allow applications to optimize the trade-off between retrieval quality, latency, and downstream context size without maintaining separate OpenViking configurations for different query types.
Alternatives Considered
- Maintain separate OpenViking configurations for different workloads. This adds unnecessary configuration complexity.
- Retrieve a large fixed number of results and filter them in the application. This increases latency, memory usage, and potentially the amount of context sent to an LLM.
- Implement query-specific filtering entirely on the client side. This duplicates retrieval logic and makes behavior less consistent across applications.
Feature Area
Other
Use Case
This would be useful for RAG systems, coding agents, knowledge assistants, and other applications using OpenViking as their memory or retrieval layer.
For example, an agent could request only 3 highly relevant results for a quick lookup, while requesting 20 candidates for a research task. This gives the application better control over retrieval latency and the amount of context ultimately provided to the model.
It can also reduce unnecessary downstream LLM token usage when only a small number of relevant results are needed.
Example API (Optional)
results = client.search(
query="How is authentication implemented?",
top_k=5,
min_score=0.7,
)
Additional Context
The proposed parameters should be optional so existing applications remain backward compatible.
A useful implementation would keep the current global/default retrieval configuration unchanged and allow individual queries to override only the parameters they need.
This could also provide a foundation for more workload-specific retrieval strategies in the future.
Contribution
- [x] I am willing to contribute to implementing this feature
Thanks for the suggestion.
Most of these per-query controls already exist with slightly different names:
top_kis covered bylimit/node_limitmin_scoreis covered byscore_thresholdin REST/SDK, andmin_scorein the MCP toolfilter,level,context_type,tags, and time filters are also available per request
So callers can already override result count and score threshold per query without changing global config.
OpenViking currently already provides two retrieval APIs:
find: fast semantic retrieval without session context.search: retrieval with optional session context.
Both APIs already support per-query controls such as result limit, score threshold, target URI, context type, metadata filter, tags, time filters, and level filtering. So callers can tune result count and relevance threshold per request without changing the global server configuration.
For detailed parameter names and examples, please refer to the retrieval API documentation.