Skip to content

LCORE-1473: Tool RAG is always enabled#1326

Merged
tisnik merged 1 commit into
lightspeed-core:mainfrom
are-ces:fix-default-rag-tool
Mar 16, 2026
Merged

LCORE-1473: Tool RAG is always enabled#1326
tisnik merged 1 commit into
lightspeed-core:mainfrom
are-ces:fix-default-rag-tool

Conversation

@are-ces

@are-ces are-ces commented Mar 16, 2026

Copy link
Copy Markdown
Contributor

Description

When rag.inline is configured in the lightspeed config but not rag.tool, the RAG Tool should be disabled. However, this is not the case as Tool RAG is always called.

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

Identify any AI code assistants used in this PR (for transparency and review context)

  • Assisted-by: Claude

Related Tickets & Documents

  • Related Issue # LCORE-1473
  • Closes # LCORE-1473

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

Test by configuring inline rag and not tool rag, make a query and see that the tool calls will be empty.

Summary by CodeRabbit

  • Documentation

    • Updated Tool RAG configuration documentation to clarify default behavior and fallback semantics when configuration is omitted.
    • Updated API schema to reflect new Tool RAG defaults and clarify resolution priority for vector store selection.
  • Tests

    • Added comprehensive test coverage for vector store resolution priority logic.
    • Updated existing tests to reflect new configuration defaults.

@are-ces are-ces marked this pull request as draft March 16, 2026 15:33
@coderabbitai

coderabbitai Bot commented Mar 16, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

This PR modifies the RagConfiguration schema to change the tool field from an optional field defaulting to None to a mandatory list field with an empty list default. It updates documentation, API schema, implementation logic for vector store resolution priority, and adds comprehensive tests validating the new behavior.

Changes

Cohort / File(s) Summary
Configuration Schema & Documentation
docs/byok_guide.md, docs/openapi.json, src/models/config.py
Updated RagConfiguration.tool from Optional[list[str]] with default None to list[str] with default_factory=list. Modified schema, OpenAPI definition, and docstrings to reflect that empty tool list disables Tool RAG, with fallback to all registered stores only when both tool and inline are empty.
Vector Store Resolution Logic
src/utils/responses.py
Introduced explicit resolution priority for vector store IDs in prepare_tools: per-request IDs take precedence, followed by rag.tool config IDs, then all registered stores if rag.inline is not configured. Added is_tool_rag_enabled and is_inline_rag_enabled flags to control branching and resolution strategy.
Configuration Tests
tests/unit/models/config/test_dump_configuration.py, tests/unit/models/config/test_rag_configuration.py
Updated test assertions to expect empty list [] instead of None for rag.tool default values across multiple test cases.
Resolution Logic Tests
tests/unit/utils/test_responses.py
Added new TestPrepareToolsVectorStoreResolution test collection with scenarios validating vector store resolution priority, config-to-internal ID translation, fallback behavior, and per-request ID override logic.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main objective: fixing the bug where Tool RAG is invoked regardless of configuration by changing tool from optional to mandatory with empty list default.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

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.

Tip

CodeRabbit can use your project's `pylint` configuration to improve the quality of Python code reviews.

Add a pylint configuration file to your project to customize how CodeRabbit runs pylint.

@are-ces are-ces force-pushed the fix-default-rag-tool branch from 2303f7a to 6c8c606 Compare March 16, 2026 15:37
@are-ces are-ces force-pushed the fix-default-rag-tool branch from 6c8c606 to c7704b1 Compare March 16, 2026 15:43
@are-ces are-ces marked this pull request as ready for review March 16, 2026 15:44

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 2

🧹 Nitpick comments (2)
src/models/config.py (1)

1720-1726: Field description is incomplete regarding fallback behavior.

The description states "When omitted, all registered BYOK vector stores are used (backward compatibility)." However, per the docstring above (lines 1709-1710) and the implementation in responses.py, this fallback only occurs when both inline and tool are empty. If inline is configured but tool is omitted, tool RAG is disabled (not fallback to all stores).

Consider updating the description for clarity:

📝 Suggested description update
     tool: list[str] = Field(
         default_factory=list,
         title="Tool RAG IDs",
         description="RAG IDs made available to the LLM as a file_search tool. "
         f"Use '{constants.OKP_RAG_ID}' to include the OKP vector store. "
-        "When omitted, all registered BYOK vector stores are used (backward compatibility).",
+        "Empty by default (no tool RAG). When both inline and tool are empty, "
+        "all registered BYOK vector stores are used as fallback.",
     )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/models/config.py` around lines 1720 - 1726, The description for the tool
Field in src/models/config.py is misleading about fallback behavior; update the
Field description for tool to state that the fallback to "all registered BYOK
vector stores" only occurs when both inline and tool are empty (i.e., if inline
is set but tool is omitted, tool RAG is disabled), and make the wording
consistent with the docstring and responses.py logic so readers understand the
three-state behavior (explicit tool list, inline-only, or fallback when both are
empty).
docs/byok_guide.md (1)

310-310: Consider making empty-list semantics explicit here.

Given rag.tool now defaults to [], this line would be even clearer as: if tool is empty and inline is empty, fallback uses all registered stores.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/byok_guide.md` at line 310, Update the sentence explaining fallback
semantics to explicitly state empty-list behavior: clarify that since rag.tool
defaults to [] an empty `tool` and an empty `inline` means the system falls back
to using all registered stores (i.e., replace "If omitted" wording with an
explicit condition like "If `tool` is empty (defaults to []) and `inline` is
empty, all registered stores are used as fallback"). Reference `rag.tool` and
`inline` so readers understand the empty-list default and the exact fallback
condition.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/openapi.json`:
- Around line 11035-11047: Update the RagConfiguration description to resolve
the contradiction about the "tool" field: clarify that "tool" defaults to [] (no
tool RAG) and does not by itself enable all BYOK stores, and then explicitly
state that the special-case fallback of registering all stores occurs only when
both "inline" and "tool" are empty; keep the note about the special ID "okp" and
references to byok_rag and constants "okp" intact so readers can find the unique
IDs and providers.

In `@src/models/config.py`:
- Line 10: Replace the import of Self from typing with Self from
typing_extensions: update the import line that currently reads "from typing
import Any, Literal, Optional, Self" to import Self from typing_extensions
instead, leaving other typing imports unchanged; then run a quick search to
ensure all `@model_validator` methods and their return annotations (instances
using Self) still type-check and update any import references if necessary.

---

Nitpick comments:
In `@docs/byok_guide.md`:
- Line 310: Update the sentence explaining fallback semantics to explicitly
state empty-list behavior: clarify that since rag.tool defaults to [] an empty
`tool` and an empty `inline` means the system falls back to using all registered
stores (i.e., replace "If omitted" wording with an explicit condition like "If
`tool` is empty (defaults to []) and `inline` is empty, all registered stores
are used as fallback"). Reference `rag.tool` and `inline` so readers understand
the empty-list default and the exact fallback condition.

In `@src/models/config.py`:
- Around line 1720-1726: The description for the tool Field in
src/models/config.py is misleading about fallback behavior; update the Field
description for tool to state that the fallback to "all registered BYOK vector
stores" only occurs when both inline and tool are empty (i.e., if inline is set
but tool is omitted, tool RAG is disabled), and make the wording consistent with
the docstring and responses.py logic so readers understand the three-state
behavior (explicit tool list, inline-only, or fallback when both are empty).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5cc744c1-7c53-4d35-9f4d-259a72f0a91a

📥 Commits

Reviewing files that changed from the base of the PR and between 3350016 and c7704b1.

📒 Files selected for processing (7)
  • docs/byok_guide.md
  • docs/openapi.json
  • src/models/config.py
  • src/utils/responses.py
  • tests/unit/models/config/test_dump_configuration.py
  • tests/unit/models/config/test_rag_configuration.py
  • tests/unit/utils/test_responses.py

Comment thread docs/openapi.json
Comment on lines 11035 to +11047
"tool": {
"anyOf": [
{
"items": {
"type": "string"
},
"type": "array"
},
{
"type": "null"
}
],
"items": {
"type": "string"
},
"type": "array",
"title": "Tool RAG IDs",
"description": "RAG IDs made available to the LLM as a file_search tool. Use 'okp' to include the OKP vector store. When omitted, all registered BYOK vector stores are used (backward compatibility)."
}
},
"additionalProperties": false,
"type": "object",
"title": "RagConfiguration",
"description": "RAG strategy configuration.\n\nControls which RAG sources are used for inline and tool-based retrieval.\n\nEach strategy lists RAG IDs to include. The special ID ``\"okp\"`` defined in constants,\nactivates the OKP provider; all other IDs refer to entries in ``byok_rag``.\n\nBackward compatibility:\n - ``inline`` defaults to ``[]`` (no inline RAG).\n - ``tool`` defaults to ``None`` which means all registered vector stores\n are used (identical to the previous ``tool.byok.enabled = True`` default)."
"description": "RAG strategy configuration.\n\nControls which RAG sources are used for inline and tool-based retrieval.\n\nEach strategy lists RAG IDs to include. The special ID ``\"okp\"`` defined in constants,\nactivates the OKP provider; all other IDs refer to entries in ``byok_rag``.\n\nBackward compatibility:\n - ``inline`` defaults to ``[]`` (no inline RAG).\n - ``tool`` defaults to ``[]`` (no tool RAG).\n\nIf no RAG strategy is defined (inline and tool are empty),\nthe RAG tool will register all stores available to llama-stack."

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.

⚠️ Potential issue | 🟠 Major

Resolve conflicting rag.tool behavior in the OpenAPI schema docs.

Line 11041 states that omitting tool enables all BYOK stores, but Line 11047 states tool defaults to [] and “all stores” is only a fallback when both inline and tool are empty. These semantics conflict and will mislead API/config consumers.

Suggested doc fix
                     "tool": {
                         "items": {
                             "type": "string"
                         },
                         "type": "array",
+                        "default": [],
                         "title": "Tool RAG IDs",
-                        "description": "RAG IDs made available to the LLM as a file_search tool. Use 'okp' to include the OKP vector store. When omitted, all registered BYOK vector stores are used (backward compatibility)."
+                        "description": "RAG IDs made available to the LLM as a file_search tool. Use 'okp' to include the OKP vector store. Defaults to an empty list (tool RAG disabled). If both rag.inline and rag.tool are empty, all stores available to llama-stack are registered as fallback."
                     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"tool": {
"anyOf": [
{
"items": {
"type": "string"
},
"type": "array"
},
{
"type": "null"
}
],
"items": {
"type": "string"
},
"type": "array",
"title": "Tool RAG IDs",
"description": "RAG IDs made available to the LLM as a file_search tool. Use 'okp' to include the OKP vector store. When omitted, all registered BYOK vector stores are used (backward compatibility)."
}
},
"additionalProperties": false,
"type": "object",
"title": "RagConfiguration",
"description": "RAG strategy configuration.\n\nControls which RAG sources are used for inline and tool-based retrieval.\n\nEach strategy lists RAG IDs to include. The special ID ``\"okp\"`` defined in constants,\nactivates the OKP provider; all other IDs refer to entries in ``byok_rag``.\n\nBackward compatibility:\n - ``inline`` defaults to ``[]`` (no inline RAG).\n - ``tool`` defaults to ``None`` which means all registered vector stores\n are used (identical to the previous ``tool.byok.enabled = True`` default)."
"description": "RAG strategy configuration.\n\nControls which RAG sources are used for inline and tool-based retrieval.\n\nEach strategy lists RAG IDs to include. The special ID ``\"okp\"`` defined in constants,\nactivates the OKP provider; all other IDs refer to entries in ``byok_rag``.\n\nBackward compatibility:\n - ``inline`` defaults to ``[]`` (no inline RAG).\n - ``tool`` defaults to ``[]`` (no tool RAG).\n\nIf no RAG strategy is defined (inline and tool are empty),\nthe RAG tool will register all stores available to llama-stack."
"tool": {
"items": {
"type": "string"
},
"type": "array",
"default": [],
"title": "Tool RAG IDs",
"description": "RAG IDs made available to the LLM as a file_search tool. Use 'okp' to include the OKP vector store. Defaults to an empty list (tool RAG disabled). If both rag.inline and rag.tool are empty, all stores available to llama-stack are registered as fallback."
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/openapi.json` around lines 11035 - 11047, Update the RagConfiguration
description to resolve the contradiction about the "tool" field: clarify that
"tool" defaults to [] (no tool RAG) and does not by itself enable all BYOK
stores, and then explicitly state that the special-case fallback of registering
all stores occurs only when both "inline" and "tool" are empty; keep the note
about the special ID "okp" and references to byok_rag and constants "okp" intact
so readers can find the unique IDs and providers.

Comment thread src/models/config.py
from pathlib import Path
from typing import Any, Optional, Literal, Self
from re import Pattern
from typing import Any, Literal, Optional, Self

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.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check minimum Python version in project configuration
echo "=== Checking pyproject.toml for Python version ==="
cat pyproject.toml 2>/dev/null | grep -A5 "python" | head -20

echo ""
echo "=== Checking setup.py/setup.cfg for Python version ==="
cat setup.py 2>/dev/null | grep -i python | head -10
cat setup.cfg 2>/dev/null | grep -i python | head -10

echo ""
echo "=== Checking if typing_extensions.Self was previously used ==="
git log -1 --format="%H" -- src/models/config.py 2>/dev/null
git show HEAD:src/models/config.py 2>/dev/null | head -15

Repository: lightspeed-core/lightspeed-stack

Length of output: 865


🏁 Script executed:

# Check if Self import was added in this PR
echo "=== Check git diff for src/models/config.py ==="
git diff HEAD -- src/models/config.py 2>/dev/null | head -50

echo ""
echo "=== Check actual usage of Self in the file ==="
rg "Self" src/models/config.py -B2 -A2

Repository: lightspeed-core/lightspeed-stack

Length of output: 4681


Change Self import to use typing_extensions.Self for consistency with coding guidelines.

The file imports Self from typing (line 10), but the coding guidelines specify using typing_extensions.Self for model validators in type annotations. This file has 18+ @model_validator methods that all use Self as return type, so update the import to comply with the guideline.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/models/config.py` at line 10, Replace the import of Self from typing with
Self from typing_extensions: update the import line that currently reads "from
typing import Any, Literal, Optional, Self" to import Self from
typing_extensions instead, leaving other typing imports unchanged; then run a
quick search to ensure all `@model_validator` methods and their return annotations
(instances using Self) still type-check and update any import references if
necessary.

@tisnik tisnik left a comment

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.

LGTM

@tisnik tisnik merged commit b2f54cf into lightspeed-core:main Mar 16, 2026
23 of 24 checks passed
@are-ces are-ces deleted the fix-default-rag-tool branch June 9, 2026 08:07
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.

2 participants