Skip to content

LCORE-1333: Define max chunks to retrieve for RAG#1765

Open
are-ces wants to merge 3 commits into
lightspeed-core:mainfrom
are-ces:lcore-1333
Open

LCORE-1333: Define max chunks to retrieve for RAG#1765
are-ces wants to merge 3 commits into
lightspeed-core:mainfrom
are-ces:lcore-1333

Conversation

@are-ces
Copy link
Copy Markdown
Contributor

@are-ces are-ces commented May 19, 2026

Description

Add RAG_CONTENT_LIMIT constant (default: 10) to constants.py that caps the final merged BYOK + OKP inline RAG output from build_rag_context. Per-source constants (BYOK_RAG_MAX_CHUNKS, OKP_RAG_MAX_CHUNKS) remain as fetch hints for the reranking pool — users can increase them to feed more candidates to the cross-encoder reranker before the final cap is applied.

Tool RAG keeps its own TOOL_RAG_MAX_CHUNKS constant independently so that users can set different max chunk limits for tool RAG and inline RAG separately.

Also adds test_responses_byok_integration.py — the /responses endpoint had no BYOK RAG integration tests. The new file covers inline RAG, tool RAG, combined RAG, score multiplier, chunk capping, and RAG_CONTENT_LIMIT enforcement, matching the existing test coverage for /query and /streaming_query.

Type of change

  • Refactor
  • New feature
  • Bug fix
  • CVE fix
  • Optimization
  • Documentation Update
  • Configuration Update
  • Bump-up service version
  • Bump-up dependent library
  • Bump-up library or tool used for development (does not change the final image)
  • CI configuration change
  • Konflux configuration change
  • Unit tests improvement
  • Integration tests improvement
  • End to end tests improvement
  • Benchmarks improvement

Tools used to create PR

  • Assisted-by: Claude
  • Generated by: Claude Opus 4.6

Related Tickets & Documents

  • Closes LCORE-1333

Checklist before requesting a review

  • I have performed a self-review of my code.
  • PR has passed all pre-merge test jobs.
  • If it is a core feature, I have added thorough tests.

Testing

  • 2284 unit tests pass, 214 integration tests pass
  • uv run make verify passes all linters
  • New tests verify RAG_CONTENT_LIMIT caps inline RAG chunks when set below per-source constants (patched to 3, feeds 10 chunks, asserts cap at 3)
  • Existing capping tests updated to assert against RAG_CONTENT_LIMIT

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 19, 2026

Warning

Review limit reached

@are-ces, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 28 minutes and 3 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

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.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 3918252f-34d6-4141-bda3-4d14f7b29bf3

📥 Commits

Reviewing files that changed from the base of the PR and between 083d1ae and 72ba7a8.

📒 Files selected for processing (7)
  • docs/byok_guide.md
  • docs/rag_guide.md
  • src/constants.py
  • src/utils/vector_search.py
  • tests/integration/endpoints/test_query_byok_integration.py
  • tests/integration/endpoints/test_responses_byok_integration.py
  • tests/integration/endpoints/test_streaming_query_byok_integration.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified code

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 and usage tips.

@are-ces are-ces force-pushed the lcore-1333 branch 4 times, most recently from 6fbe0e9 to a18cf4c Compare May 19, 2026 07:36
@are-ces are-ces requested review from TamiTakamiya and syedriko May 19, 2026 10:44
Copy link
Copy Markdown
Contributor

@TamiTakamiya TamiTakamiya left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for providing the clear PR description.

Comment thread tests/integration/endpoints/test_responses_byok_integration.py
Comment thread docs/rag_guide.md
| `OKP_RAG_MAX_CHUNKS` | 5 | Max chunks retrieved from OKP (Inline RAG) |
| `BYOK_RAG_MAX_CHUNKS` | 10 | Max chunks retrieved from BYOK stores (Inline RAG) |
| `TOOL_RAG_MAX_CHUNKS` | 10 | Max chunks retrieved via Tool RAG (`file_search`) |
| `RAG_CONTENT_LIMIT` | 10 | Hard upper bound on the final merged inline RAG chunks (BYOK + OKP) delivered to the LLM |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The word "default" implies there's an override — but there isn't. May be replace Default with Value? The language is a bit misleading for someone reading the docs expecting a config knob.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

May be we should turn these into config knobs.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The existing naming convention is:

BYOK_RAG_MAX_CHUNKS
OKP_RAG_MAX_CHUNKS
TOOL_RAG_MAX_CHUNKS

All follow the pattern _RAG_MAX_CHUNKS. Then RAG_CONTENT_LIMIT breaks this — it's a different naming style for a constant that plays the same role (capping chunk count), just at a different stage in the pipeline.

Something like INLINE_RAG_MAX_CHUNKS or MERGED_RAG_MAX_CHUNKS ?

Copy link
Copy Markdown
Contributor Author

@are-ces are-ces May 26, 2026

Choose a reason for hiding this comment

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

Yes I agree on the config, I would expose the knobs there and change the naming to have:

BYOK_RAG_MAX_CHUNKS
OKP_RAG_MAX_CHUNKS
TOOL_RAG_MAX_CHUNKS
INLINE_RAG_MAX_CHUNKS  # from RAG_CONTENT_LIMIT

@TamiTakamiya what do you think about this?

PS: IMO the config needs restructuring because it's a bit of a mess now 😄

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The word "default" implies there's an override — but there isn't. May be replace Default with Value? The language is a bit misleading for someone reading the docs expecting a config knob.

I will fix it if we don't go with config knobs

are-ces and others added 2 commits May 26, 2026 09:33
Add test_responses_byok_integration.py with integration tests covering
inline RAG, tool RAG, combined RAG, score multiplier, chunk capping,
and RAG_CONTENT_LIMIT enforcement for the /responses endpoint.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add RAG_CONTENT_LIMIT constant (default: 10) that caps the final merged
BYOK + OKP output from build_rag_context. Per-source constants remain as
fetch hints for the reranking pool. Tool RAG is unaffected.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

3 participants