Skip to content

Add store answer endpoint (query across a collection)#57

Merged
hallelx2 merged 1 commit into
mainfrom
feat/store-answer-endpoint
Jul 4, 2026
Merged

Add store answer endpoint (query across a collection)#57
hallelx2 merged 1 commit into
mainfrom
feat/store-answer-endpoint

Conversation

@hallelx2

@hallelx2 hallelx2 commented Jul 4, 2026

Copy link
Copy Markdown
Owner

@

What

POST /v1/answer/store — ask a question over a set of documents (a store/collection) and get one synthesised answer with per-document citations. The map-reduce companion to the single-doc tree-walk.

  • mapretrieval.MultiDoc fans the selection strategy across every document_id → relevant sections per doc.
  • reduce — one LLM call reads the gathered, source-labelled evidence ([1], [2], … tagged with document title + page range) → a single answer citing sources with [n] markers.

Request: {document_ids[], query, model?, max_sections_per_doc?, max_tokens?}
Response: {answer, citations[{index, document_id, document_title, start_page, end_page, section_ids, quote}], documents_searched, documents_with_matches, usage, elapsed_ms}

Empty evidence → honest refusal, not a hallucination. Org + store scope come from the injected headers (a key only reads its own docs). Returns 501 when no LLM is configured. Wired from Deps — no main.go change.

Design notes

  • The dashboard resolves store → its ready document_ids and passes them, so the engine stays scope-agnostic and this also works for an arbitrary ad-hoc doc set.
  • Citations carry document_id; the dashboard maps id→title for display (it already lists the store).
  • Reducer output is tolerant-parsed (JSON, code-fenced JSON, or raw prose with scraped [n] markers) so a formatting slip never drops the answer.

Tests

  • TestParseStoreAnswer (clean/fenced/deduped/fallback), TestBuildStoreCitations, TestFormatPageRange.
  • go build ./... + go test ./... green.

Follow-up: SSE streaming variant + the dashboard "Store" playground mode.
@

@
Add store answer endpoint (query across a collection)

POST /v1/answer/store synthesises ONE grounded answer across a set of
documents (a store/collection), with per-document citations. It is the
map-reduce companion to the single-document tree-walk:

  map    — retrieval.MultiDoc fans the selection strategy across every
           document_id and returns the relevant sections per document.
  reduce — one LLM call reads the gathered, source-labelled evidence
           ([1], [2], … tagged with document title + page range) and
           writes a single answer citing sources with [n] markers.

Response: {answer, citations[{index, document_id, document_title,
start_page, end_page, section_ids, quote}], documents_searched,
documents_with_matches, usage, elapsed_ms}. Empty evidence yields an
honest refusal rather than a hallucinated answer.

Org + store scope come from the injected headers, so a key only ever
reads its own documents. Wired from Deps (MultiDoc + LLM); returns 501
when no LLM is configured.
@

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @hallelx2, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@hallelx2, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 52 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9c030376-bd94-42da-9183-e935881fab4a

📥 Commits

Reviewing files that changed from the base of the PR and between d148f4c and 3a2e628.

📒 Files selected for processing (3)
  • internal/handler/answer_store.go
  • internal/handler/answer_store_test.go
  • internal/handler/router.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/store-answer-endpoint

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 8630d0c into main Jul 4, 2026
8 checks passed
@hallelx2 hallelx2 deleted the feat/store-answer-endpoint branch July 4, 2026 03:13
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