Skip to content

fix(server): /v1/query leads with judgewalk's evidence pages; max_sections keeps them - #89

Merged
hallelx2 merged 2 commits into
mainfrom
halleluyaholudele/selfhost-query-evidence-pages
Oct 16, 2026
Merged

hallelx2 merged 2 commits into
mainfrom
halleluyaholudele/selfhost-query-evidence-pages

Conversation

@hallelx2

@hallelx2 hallelx2 commented Oct 16, 2026 •

Copy link
Copy Markdown
Owner

Closes HAL-3071

Why

cmd/server (self-host and production) read only SelectedIDs from a page-based strategy. /v1/query therefore returned the overlapping sections in document order and dropped the evidence pages that HAL-1390 added to the standalone engine (internal/api). With max_sections: 5 the gold evidence was often cut: on the rig, the section with 3M's FY2018 capex came 7th of 35.

What

  • Evidence pages lead the response, as page_<n> units titled "<section> · p.<n>" with the page text. This is the same contract as internal/api.
  • max_sections caps the combined list, so a small cap keeps the evidence.

Verified

  • New tests TestQueryLeadsWithEvidencePages and TestMaxSectionsKeepsTheEvidence. go build, go vet and the internal/handler tests pass on the rig's engine VM.
  • Live on the rig (FinanceBench, 10 questions, k=5), same questions before and after:
hit@5 MRR F1@5
Before 0.50 0.18 0.16
After 0.80 0.70 0.40

For comparison, vector RAG with Gemini embeddings scored hit@5 0.70.

Summary by Sourcery

Preserve page-level evidence in server query results and prioritize it when limiting returned sections.

New Features:

  • Include JudgeWalk evidence pages as leading page units in /v1/query responses, matching the standalone engine contract.

Bug Fixes:

  • Ensure max_sections preserves evidence pages before truncating document sections.

Tests:

  • Add handler coverage for evidence-page ordering and max_sections behavior.

Summary by CodeRabbit

  • New Features
    • Query responses now include evidence pages before selected document sections.
    • When a section limit is set, evidence pages are prioritized and selected sections fill any remaining slots.

…tions keeps them

The self-host and production server (cmd/server, internal/handler)
read only SelectedIDs from a page-based strategy, so /v1/query returned
the overlapping sections in document order and dropped the evidence
pages HAL-1390 added to the standalone engine. With max_sections 5 the
gold evidence was often cut: on the rig the 3M FY2018 capex question's
section came 7th of 35.

The evidence pages now lead (page_<n>, '<section> · p.<n>', page text),
the same contract as internal/api, and max_sections caps the combined
list so a small cap keeps the evidence.
@sourcery-ai

sourcery-ai Bot commented Oct 16, 2026

Copy link
Copy Markdown

Sorry @hallelx2, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 4 days and 6 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Oct 16, 2026

Copy link
Copy Markdown

Reviewer's Guide

The server handler now mirrors the standalone engine by prepending Judge-selected evidence pages to /v1/query results and applying max_sections across the combined list, prioritizing evidence; focused tests cover response shape, ordering, and cap behavior.

Sequence diagram for evidence-first query responses

sequenceDiagram
    participant Client
    participant QueryHandler
    participant CostStrategy
    participant Document

    Client->>QueryHandler: HandleQuery
    QueryHandler->>CostStrategy: SelectWithCost
    CostStrategy-->>QueryHandler: SelectedIDs and EvidencePages
    QueryHandler->>QueryHandler: evidencePageSections
    QueryHandler->>Document: FindByID for remaining sections
    Document-->>QueryHandler: Section content
    QueryHandler-->>Client: Evidence pages followed by sections
Loading

File-Level Changes

Change Details Files
Preserve and expose Judge-selected evidence pages in the server query response.
  • Capture evidence pages from cost-aware retrieval results.
  • Convert pages into page_<n> response units with section/page titles, text, page metadata, confidence, and token count.
  • Place evidence units before selected sections to match the standalone API contract.
internal/handler/query.go
Apply max_sections to the combined evidence-and-section response while prioritizing evidence.
  • Truncate evidence pages only when they exceed the cap.
  • Use remaining capacity for selected sections, ensuring small caps retain leading evidence.
internal/handler/query.go
Add handler coverage for evidence ordering and capped responses.
  • Verify evidence pages lead normal query results with the expected response shape.
  • Verify caps of two and one preserve the evidence page before sections.
internal/handler/query_evidence_test.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 47 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8a2a21e4-931b-4199-99a7-51b40ac7d04f
📥 Commits

Reviewing files that changed from the base of the PR and between 069f31e and b411303.

📒 Files selected for processing: 1
  • internal/handler/query.go

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f6a9ea95-feb3-4ea8-a00f-fea6dc698307
📥 Commits

Reviewing files that changed from the base of the PR and between 2d31c35 and 069f31e.

📒 Files selected for processing: 2
  • internal/handler/query.go
  • internal/handler/query_evidence_test.go

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Walkthrough

QueryHandler now includes evidence pages from successful cost-based strategy results in query responses. It places those pages before selected document sections and applies a positive max_sections limit to the combined list.

Changes: Query evidence pages

Layer / File(s) Summary
Build and limit evidence sections
internal/handler/query.go, internal/handler/query_evidence_test.go
QueryHandler converts evidence pages into response entries and places them before selected sections. A positive max_sections limit applies to the combined list. Tests check evidence ordering and limit behavior.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 069f3

Evidence pages appear first and remain within the section limit; no merge-blocking issue was identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and specifically describes the main changes: adding evidence pages to /v1/query results and preserving them when max_sections limits the response.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches: 💡 2
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@hallelx2
hallelx2 merged commit 1fc8d42 into main Oct 16, 2026
2 of 8 checks passed
@hallelx2
hallelx2 deleted the halleluyaholudele/selfhost-query-evidence-pages branch October 16, 2026 06:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant