Skip to content

LCORE-1953: Added checks for None scores#1556

Merged
tisnik merged 1 commit into
lightspeed-core:mainfrom
tisnik:lcore-1953-none-tests-added
Apr 21, 2026
Merged

LCORE-1953: Added checks for None scores#1556
tisnik merged 1 commit into
lightspeed-core:mainfrom
tisnik:lcore-1953-none-tests-added

Conversation

@tisnik
Copy link
Copy Markdown
Contributor

@tisnik tisnik commented Apr 21, 2026

Description

LCORE-1953: Added checks for None scores

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: N/A
  • Generated by: N/A

Related Tickets & Documents

  • Related Issue #LCORE-1953

Summary by CodeRabbit

  • Tests
    • Improved test coverage for BYOK RAG integration with enhanced validation of score consistency across multiple ranking and capping scenarios.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 21, 2026

Walkthrough

BYOK RAG integration tests were updated to assert that all returned rag_chunk.score values are non-None across multiple test scenarios, including cross-source ranking and chunk capping tests. Test assertions now filter out None scores and explicitly type score lists as list[float].

Changes

Cohort / File(s) Summary
Test Assertions
tests/integration/endpoints/test_query_byok_integration.py
Updated assertions to enforce non-None scores for all returned RAG chunks. Added filtering logic to exclude None scores when building verification lists, and explicitly typed score collections as list[float] in capping test scenarios.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title 'LCORE-1953: Added checks for None scores' accurately and clearly describes the main change: adding assertions to verify that returned rag_chunk scores are non-None in integration tests.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ 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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/integration/endpoints/test_query_byok_integration.py`:
- Around line 993-1000: The list comprehension that builds scores unnecessarily
filters out None even though just above you assert every chunk.score is not
None; remove the redundant "if chunk.score is not None" from the comprehension
that creates scores (use [chunk.score for chunk in response.rag_chunks]) so any
unexpected None will fail the test instead of being silently dropped; apply the
same change to the parallel block that uses response.rag_chunks around lines
1084-1090 to keep the list[float] annotation accurate and tests strict.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 1052a92e-cf38-4df5-9b71-44585b3fd63f

📥 Commits

Reviewing files that changed from the base of the PR and between 30b4e9e and adf1c2b.

📒 Files selected for processing (1)
  • tests/integration/endpoints/test_query_byok_integration.py
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (17)
  • GitHub Check: list_outdated_dependencies
  • GitHub Check: integration_tests (3.13)
  • GitHub Check: integration_tests (3.12)
  • GitHub Check: build-pr
  • GitHub Check: Pylinter
  • GitHub Check: unit_tests (3.13)
  • GitHub Check: unit_tests (3.12)
  • GitHub Check: Pyright
  • GitHub Check: mypy
  • GitHub Check: E2E Tests for Lightspeed Evaluation job
  • GitHub Check: E2E: server mode / ci / group 1
  • GitHub Check: E2E: library mode / ci / group 2
  • GitHub Check: E2E: server mode / ci / group 3
  • GitHub Check: E2E: server mode / ci / group 2
  • GitHub Check: E2E: library mode / ci / group 3
  • GitHub Check: E2E: library mode / ci / group 1
  • GitHub Check: Konflux kflux-prd-rh02 / lightspeed-stack-on-pull-request
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

**/*.py: Use absolute imports for internal modules: from authentication import get_auth_dependency
Import FastAPI dependencies with: from fastapi import APIRouter, HTTPException, Request, status, Depends
Import Llama Stack client with: from llama_stack_client import AsyncLlamaStackClient
Check constants.py for shared constants before defining new ones
All modules start with descriptive docstrings explaining purpose
Use logger = get_logger(__name__) from log.py for module logging
Type aliases defined at module level for clarity
Use Final[type] as type hint for all constants
All functions require docstrings with brief descriptions
Complete type annotations for parameters and return types in functions
Use typing_extensions.Self for model validators in Pydantic models
Use modern union type syntax str | int instead of Union[str, int]
Use Optional[Type] for optional type hints
Use snake_case with descriptive, action-oriented function names (get_, validate_, check_)
Avoid in-place parameter modification anti-patterns; return new data structures instead
Use async def for I/O operations and external API calls
Handle APIConnectionError from Llama Stack in error handling
Use standard log levels with clear purposes: debug, info, warning, error
All classes require descriptive docstrings explaining purpose
Use PascalCase for class names with standard suffixes: Configuration, Error/Exception, Resolver, Interface
Use ABC for abstract base classes with @abstractmethod decorators
Use @model_validator and @field_validator for Pydantic model validation
Complete type annotations for all class attributes; use specific types, not Any
Follow Google Python docstring conventions with Parameters, Returns, Raises, and Attributes sections

Files:

  • tests/integration/endpoints/test_query_byok_integration.py
tests/{unit,integration}/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

tests/{unit,integration}/**/*.py: Use pytest for all unit and integration tests
Do not use unittest; pytest is the standard for this project
Use pytest-mock for AsyncMock objects in tests
Use marker pytest.mark.asyncio for async tests
Unit tests require 60% coverage, integration tests 10%

Files:

  • tests/integration/endpoints/test_query_byok_integration.py
🔇 Additional comments (2)
tests/integration/endpoints/test_query_byok_integration.py (2)

1084-1090: Duplicate of the pattern above.

Same redundancy as lines 993-1000: the preceding loop already asserts non-None, so the filter in the comprehension is unnecessary. See the suggestion on the earlier block; apply the equivalent simplification here.


926-928: LGTM — None guards make the comparison type-safe.

Adding explicit is not None checks before the > comparison prevents a TypeError if either score is ever None and keeps mypy happy given RAGChunk.score: Optional[float].

Comment on lines +993 to +1000
# Check that the score is computed properly
for chunk in response.rag_chunks:
assert chunk.score is not None

# Verify chunks are sorted by score descending (highest first)
scores = [chunk.score for chunk in response.rag_chunks]
scores: list[float] = [
chunk.score for chunk in response.rag_chunks if chunk.score is not None
]
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.

🧹 Nitpick | 🔵 Trivial

Redundant None filter after asserting non-None.

Lines 994-995 already assert every chunk.score is not None, so the if chunk.score is not None filter in the list comprehension on line 999 is dead code and weakens the test: if a None slipped through the assertion loop (it can't, but hypothetically), the filter would silently drop it rather than letting sorted() comparison fail. Given the preceding assertion, the comprehension can drop the filter and keep the explicit list[float] annotation honest.

♻️ Proposed simplification
     # Check that the score is computed properly
     for chunk in response.rag_chunks:
         assert chunk.score is not None
 
     # Verify chunks are sorted by score descending (highest first)
-    scores: list[float] = [
-        chunk.score for chunk in response.rag_chunks if chunk.score is not None
-    ]
+    scores: list[float] = [chunk.score for chunk in response.rag_chunks]
     assert scores == sorted(scores, reverse=True)

The same applies to the parallel block at lines 1084-1090.

📝 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
# Check that the score is computed properly
for chunk in response.rag_chunks:
assert chunk.score is not None
# Verify chunks are sorted by score descending (highest first)
scores = [chunk.score for chunk in response.rag_chunks]
scores: list[float] = [
chunk.score for chunk in response.rag_chunks if chunk.score is not None
]
# Check that the score is computed properly
for chunk in response.rag_chunks:
assert chunk.score is not None
# Verify chunks are sorted by score descending (highest first)
scores: list[float] = [chunk.score for chunk in response.rag_chunks]
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/integration/endpoints/test_query_byok_integration.py` around lines 993
- 1000, The list comprehension that builds scores unnecessarily filters out None
even though just above you assert every chunk.score is not None; remove the
redundant "if chunk.score is not None" from the comprehension that creates
scores (use [chunk.score for chunk in response.rag_chunks]) so any unexpected
None will fail the test instead of being silently dropped; apply the same change
to the parallel block that uses response.rag_chunks around lines 1084-1090 to
keep the list[float] annotation accurate and tests strict.

@tisnik tisnik merged commit 82f9956 into lightspeed-core:main Apr 21, 2026
29 of 30 checks passed
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