Improve RAG context budgeting#7
Open
Treasure520520 wants to merge 3 commits into
Open
Conversation
|
I would like to work on this bounty. /claim https://algora.io/isaac/bounties/clq18zr98000ejs0gt0nv7gwu I will implement:
|
Author
|
Pushed a focused follow-up commit (
Validation re-run:
|
Author
|
Pushed a small compatibility follow-up (
Validation re-run:
|
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.
Part of the open Algora bounty for
[ISAAC-497] Implement an enhanced RAG Pipeline for Scientific/Research Workflows./claim #45
Bounty reference: https://algora.io/isaac/bounties/clq18zr98000ejs0gt0nv7gwu
Summary
fetch-documentssorag-chatcan use a stable context string instead of formatting raw Chroma arrays inlineWhy this helps the scientific RAG bounty
Scientific PDFs often contain repeated abstracts, headers, references, or near-identical chunks. The current RAG path sends the first 4 raw Chroma matches directly into the prompt without deduplication or a context budget, which can waste context and make citations noisier.
This PR is intentionally a scoped reliability slice that complements the larger citation/reranking PRs already open. It keeps the current Chroma + LangChain architecture, avoids new dependencies, and improves the quality of the context that reaches the model.
Validation
npm install --no-audit --no-fundnpx vitest run __tests__/rag-context.test.tsnpx tsc --noEmit --pretty falsenpx prettier --check pages/api/fetch-documents.ts pages/api/rag-chat.ts utils/server/rag-context.ts __tests__/rag-context.test.ts