feat(retrieve): add RetrievalObserver for retrieval quality metrics#622
Merged
MaojiaSheng merged 1 commit intovolcengine:mainfrom Mar 15, 2026
Merged
Conversation
Add retrieval quality observability following the existing observer pattern (QueueObserver, VLMObserver, VikingDBObserver). - RetrievalStatsCollector: thread-safe singleton that accumulates per-query metrics (result counts, scores, latency, rerank usage) - RetrievalObserver: reads accumulated stats, reports health based on zero-result rate, formats status table with tabulate - Instrumented HierarchicalRetriever.retrieve() to record stats - Added /api/v1/observer/retrieval endpoint - Included in system-wide observer health check - 17 unit tests covering stats, collector, and observer This contribution was developed with AI assistance (Claude Code).
MaojiaSheng
approved these changes
Mar 15, 2026
Contributor
Author
|
Thanks for reviewing and merging all of these, @MaojiaSheng - great working with you on OpenViking. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add retrieval quality observability following the existing observer pattern. A new
RetrievalObservertracks query metrics (result counts, scores, latency, rerank usage) and reports health via the observer API.Problem Statement
The observer infrastructure covers queue, VikingDB, VLM, and transaction subsystems, but the retrieval pipeline has no observability beyond debug logs. When retrieval quality degrades, users have no metrics to diagnose the problem. The
HierarchicalRetrieverlogs individual queries at DEBUG level, but there are no aggregate stats for hit rates, score distributions, or latency.Evidence
The observer pattern is well-established in the codebase. This PR follows it exactly.
Changes
New files:
openviking/retrieve/retrieval_stats.py(165 lines) - Thread-safeRetrievalStatsCollectorsingleton that accumulates per-query metricsopenviking/storage/observers/retrieval_observer.py(99 lines) -RetrievalObserverimplementingBaseObservertests/unit/retrieve/test_retrieval_stats.py(175 lines) - 17 unit testsModified files:
openviking/retrieve/hierarchical_retriever.py- Record stats after eachretrieve()call (3 lines added)openviking/storage/observers/__init__.py- ExportRetrievalObserveropenviking/service/debug_service.py- Register retrieval in observer service + system healthopenviking/server/routers/observer.py- AddGET /api/v1/observer/retrievalendpointMetrics tracked
Health logic
Testing
All 17 unit tests pass:
The
RetrievalObserveruses a lazy import ofget_stats_collector()to avoid a circular dependency with the storage module. This follows the same pattern astabulateimports in other observers.This contribution was developed with AI assistance (Claude Code).
Relates to #578