feat(retrieve): add provenance metadata to search results#852
Open
mvanhorn wants to merge 2 commits intovolcengine:mainfrom
Open
feat(retrieve): add provenance metadata to search results#852mvanhorn wants to merge 2 commits intovolcengine:mainfrom
mvanhorn wants to merge 2 commits intovolcengine:mainfrom
Conversation
Adds an opt-in `include_provenance` parameter to the search/find API
endpoints. When enabled, the response includes a `provenance` array
with per-query retrieval details: which directories were traversed,
which tier (L0/L1/L2) each result came from, match reasons, and the
full thinking trace.
The internal data was already being collected in MatchedContext.level,
MatchedContext.context_type, and QueryResult.thinking_trace. This
change surfaces it through the API for retrieval observability, which
the README lists as a core design goal ("Visualized Retrieval
Trajectory").
Backward compatible: defaults to false, existing clients see no change.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Failed to generate code suggestions for PR |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Description
Adds an opt-in
include_provenanceparameter to the search/find API endpoints. When enabled, the response includes aprovenancearray showing which directories were traversed, which tier (L0/L1/L2) each result came from, match reasons, and the full thinking trace.The README states "Visualized Retrieval Trajectory" as a core feature, and the internal data structures already collect this information (MatchedContext.level, QueryResult.thinking_trace, QueryResult.searched_directories). This change surfaces it through the API.
Evidence:
Type of Change
Changes Made
include_provenance: bool = FalsetoFindRequestandSearchRequestinopenviking/server/routers/search.pyFindResult.to_dict()to acceptinclude_provenanceand conditionally includequery_resultswith thinking trace_query_result_to_dict()to serialize query results with tier labels (L0/L1/L2)include_provenancethrough the search/find endpoint handlersTesting
5 unit tests added in
tests/retrieve/test_provenance.pycovering:Screenshots
Provenance output (installed from modified branch, tested with realistic retrieval data):
The provenance section shows: which directories were searched, which tier (L0/L1/L2) each result came from, match reasons, and thinking trace statistics. All opt-in via
include_provenance: true- existing clients see no change.Example JSON response with provenance:
{ "provenance": [{ "query": "architecture design patterns", "searched_directories": ["resources/", "resources/docs/", "user/default/memories/"], "matched_contexts": [ {"uri": "viking://resources/docs/architecture.md", "tier": "L2", "score": 0.87, "match_reason": "semantic_match"}, {"uri": "viking://user/.../meeting-notes", "tier": "L1", "score": 0.62, "match_reason": "directory_match"} ], "thinking_trace": {"statistics": {"directories_searched": 2, "candidates_collected": 1}, "events": [...]} }] }Checklist
Additional Notes
This contribution was developed with AI assistance (Claude Code). The feature was proposed after dogfooding OpenViking's search API and noticing the provenance data was collected internally but not exposed to clients.