Improve scientific RAG evidence and citation grounding#14
Improve scientific RAG evidence and citation grounding#14victortran0904 wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a server-side “scientific evidence” contract for RAG: it normalizes Chroma query results into a bounded evidenceContext, stable SRC-* citation keys, citations, and a sourceManifest, and updates the retrieval + rag-chat flow to use that evidence/citation payload.
Changes:
- Added
buildScientificEvidencePayloadto convert Chroma results intoevidenceContext,citations, andsourceManifestwith size bounds and deduplication. - Updated ingestion to persist citation-friendly primitive metadata (title/source/page/chunk identifiers, plus optional PDF info fields).
- Updated
fetch-documentsto return bounded evidence/citation payload andrag-chatto consume it via same-origin retrieval.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| ui/utils/server/scientific-evidence.ts | New evidence/citation payload builder for Chroma query results, including bounding/deduplication and manifest creation. |
| ui/pages/api/fetch-documents.ts | Adds request validation + bounded nResults/evidence size, returns evidence context + citations/manifest alongside raw Chroma results. |
| ui/pages/api/inject-documents.ts | Normalizes/stores primitive PDF/chunk metadata during ingestion to support citations/manifest. |
| ui/pages/api/rag-chat.ts | Switches retrieval to same-origin /api/fetch-documents and prompts the model to cite using provided SRC-* keys. |
| ui/tests/scientific-evidence.test.ts | Adds unit tests for dedupe, normalization, and evidence-size bounding behavior. |
Comments suppressed due to low confidence (1)
ui/pages/api/rag-chat.ts:184
temperatureToUseis computed earlier, but the OpenAI call hard-codes0for temperature. This makes thetemperaturerequest parameter andDEFAULT_TEMPERATUREineffective for rag-chat. PasstemperatureToUsetoOpenAIStream(as done inpages/api/chat.ts).
const stream = await OpenAIStream(
model,
promptToSend,
0,
key,
messagesToSend,
);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Follow-up pushed in
Validation after the follow-up:
|
|
Additional small follow-up pushed in
Validation after this follow-up:
|
|
Verified current head Evidence:
Validation:
No new code changes were needed for this pass. |
Candidate for Algora ISAAC-497 bounty: https://algora.io/isaac/bounties/clq18zr98000ejs0gt0nv7gwu
/claim #45
Summary:
Verification:
Notes: