Skip to content

Conversation

@are-ces
Copy link
Contributor

@are-ces are-ces commented Dec 9, 2025

Description

Added parsing of rag_chunks, then added them to TurnSummary to store the rag chunks in the transcript.

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

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-1094
  • Closes # LCORE-1094

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

  • Set up LCS with a rag db, called the rag and checked that the transcript stores the rag chunks.

Summary by CodeRabbit

  • New Features
    • RAG chunk extraction from API responses now properly captures source information and relevance scores, enabling accurate source attribution and content tracking in conversations.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 9, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

A new function parse_rag_chunks_from_responses_api() was introduced to extract RAG chunks from the Responses API output. The retrieve_response function was modified to use this function to populate TurnSummary.rag_chunks instead of leaving it empty. Minor import reordering was also performed.

Changes

Cohort / File(s) Summary
RAG chunk extraction from Responses API
src/app/endpoints/query_v2.py
Added parse_rag_chunks_from_responses_api() function to extract RAG chunks by scanning for file_search_call items in API responses. Modified retrieve_response() to invoke this function and populate TurnSummary.rag_chunks. Minor import reordering of utility functions.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • New function logic is straightforward—iterating through response items and aggregating structured data
  • Integration point is minimal (single function call assignment)
  • No complex state management or error handling paths introduced

Pre-merge checks and finishing touches

✅ 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 clearly references the main change: parsing of rag chunks from the Responses API output and storing them in TurnSummary.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

♻️ Duplicate comments (1)
src/app/endpoints/query_v2.py (1)

422-429: Fix the parser function to return RAGChunk objects.

The integration of RAG chunk parsing is correct, but the parse_rag_chunks_from_responses_api function returns a list of dicts instead of list[RAGChunk] objects, causing the TurnSummary validation to fail.

See the detailed fix in the review comment for lines 455-482.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4269f0b and ad277ff.

📒 Files selected for processing (1)
  • src/app/endpoints/query_v2.py (3 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
src/**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

src/**/*.py: Use absolute imports for internal modules in LCS project (e.g., from auth import get_auth_dependency)
All modules must start with descriptive docstrings explaining their purpose
Use logger = logging.getLogger(__name__) pattern for module logging
All functions must include complete type annotations for parameters and return types, using modern syntax (str | int) and Optional[Type] or Type | None
All functions must have docstrings with brief descriptions following Google Python docstring conventions
Function names must use snake_case with descriptive, action-oriented names (get_, validate_, check_)
Avoid in-place parameter modification anti-patterns; return new data structures instead of modifying input parameters
Use async def for I/O operations and external API calls
All classes must include descriptive docstrings explaining their purpose following Google Python docstring conventions
Class names must use PascalCase with descriptive names and standard suffixes: Configuration for config classes, Error/Exception for exceptions, Resolver for strategy patterns, Interface for abstract base classes
Abstract classes must use ABC with @abstractmethod decorators
Include complete type annotations for all class attributes in Python classes
Use import logging and module logger pattern with standard log levels: debug, info, warning, error

Files:

  • src/app/endpoints/query_v2.py
src/app/endpoints/**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

Use FastAPI HTTPException with appropriate status codes for API endpoint error handling

Files:

  • src/app/endpoints/query_v2.py
src/**/{client,app/endpoints/**}.py

📄 CodeRabbit inference engine (CLAUDE.md)

Handle APIConnectionError from Llama Stack in integration code

Files:

  • src/app/endpoints/query_v2.py
🧬 Code graph analysis (1)
src/app/endpoints/query_v2.py (2)
src/utils/suid.py (2)
  • normalize_conversation_id (101-122)
  • to_llama_stack_conversation_id (125-145)
src/utils/types.py (1)
  • TurnSummary (135-220)
🪛 GitHub Actions: Integration tests
src/app/endpoints/query_v2.py

[error] 425-425: TurnSummary validation failed: rag_chunks[0].content must be a string. Received MagicMock during test_query_v2_endpoint_with_tool_calls. Traceback points to query_v2.py:425.

🪛 GitHub Actions: Unit tests
src/app/endpoints/query_v2.py

[error] 476-476: AttributeError: 'dict' object has no attribute 'text' while parsing rag chunks from responses API in parse_rag_chunks_from_responses_api. Expected items to have 'text' and 'score' attributes (triggered during tests/unit/app/endpoints/test_query_v2.py::test_retrieve_response_parses_referenced_documents).

⏰ 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). (6)
  • GitHub Check: build-pr
  • GitHub Check: Konflux kflux-prd-rh02 / lightspeed-stack-on-pull-request
  • GitHub Check: E2E: server mode / azure
  • GitHub Check: E2E: server mode / ci
  • GitHub Check: E2E: library mode / ci
  • GitHub Check: E2E: library mode / azure
🔇 Additional comments (1)
src/app/endpoints/query_v2.py (1)

46-46: LGTM! Import consolidation improves organization.

The import reorganization properly consolidates related utility functions into a single import statement.

Comment on lines 455 to 482
def parse_rag_chunks_from_responses_api(response_obj: Any) -> list:
"""
Extract rag_chunks from the llama-stack OpenAI response.
Args:
response_obj: The ResponseObject from OpenAI compatible response API in llama-stack.
Returns:
List of rag chunk dicts with content, source, score
"""
rag_chunks = []

for output_item in response_obj.output:
if (
hasattr(output_item, "type")
and output_item.type == "file_search_call"
and hasattr(output_item, "results")
):

for result in output_item.results:
rag_chunk = {
"content": result.text,
"source": "file_search",
"score": result.score,
}
rag_chunks.append(rag_chunk)

return rag_chunks
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Fix AttributeError and type mismatch issues in RAG chunk parsing.

The function has critical issues confirmed by pipeline failures:

  1. Line 476: result.text causes AttributeError: 'dict' object has no attribute 'text' when result is a dict.
  2. Return type: Returns list[dict] but TurnSummary.rag_chunks expects list[RAGChunk] objects, causing validation failures.
  3. Type annotation: Incomplete return type -> list violates coding guidelines requiring complete type annotations.

The function must handle both dict and object access patterns like other functions in this file (e.g., _build_tool_call_summary and parse_referenced_documents_from_responses_api).

Apply this diff to fix all issues:

+from utils.types import RAGChunk
+
 # ... (in the imports section)

-def parse_rag_chunks_from_responses_api(response_obj: Any) -> list:
+def parse_rag_chunks_from_responses_api(response_obj: Any) -> list[RAGChunk]:
     """
     Extract rag_chunks from the llama-stack OpenAI response.
 
     Args:
         response_obj: The ResponseObject from OpenAI compatible response API in llama-stack.
 
     Returns:
-        List of rag chunk dicts with content, source, score
+        List of RAGChunk objects with content, source, and score
     """
-    rag_chunks = []
+    rag_chunks: list[RAGChunk] = []
 
     for output_item in response_obj.output:
         if (
             hasattr(output_item, "type")
             and output_item.type == "file_search_call"
             and hasattr(output_item, "results")
         ):
-
             for result in output_item.results:
-                rag_chunk = {
-                    "content": result.text,
-                    "source": "file_search",
-                    "score": result.score,
-                }
-                rag_chunks.append(rag_chunk)
+                # Handle both dict and object access patterns
+                if isinstance(result, dict):
+                    content = result.get("text", "")
+                    score = result.get("score")
+                else:
+                    content = getattr(result, "text", "")
+                    score = getattr(result, "score", None)
+                
+                if content:  # Only add if content exists
+                    rag_chunks.append(
+                        RAGChunk(
+                            content=content,
+                            source="file_search",
+                            score=score,
+                        )
+                    )
 
     return rag_chunks
🧰 Tools
🪛 GitHub Actions: Unit tests

[error] 476-476: AttributeError: 'dict' object has no attribute 'text' while parsing rag chunks from responses API in parse_rag_chunks_from_responses_api. Expected items to have 'text' and 'score' attributes (triggered during tests/unit/app/endpoints/test_query_v2.py::test_retrieve_response_parses_referenced_documents).

@are-ces are-ces marked this pull request as draft December 9, 2025 13:08
@are-ces are-ces force-pushed the rag-chunks-fix branch 3 times, most recently from 0411286 to 5eae3bf Compare December 9, 2025 13:48
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