-
Notifications
You must be signed in to change notification settings - Fork 94
LCORE-2310: Refactor source resolution utility #1850
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tisnik
merged 1 commit into
lightspeed-core:main
from
asimurka:refator_source_resolution
Jun 4, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -861,18 +861,16 @@ def parse_referenced_documents( # pylint: disable=too-many-locals | |
| id_mapping = rag_id_mapping or {} | ||
|
|
||
| for output_item in response.output: | ||
| item_type = getattr(output_item, "type", None) | ||
| item_type = output_item.type | ||
|
|
||
| if item_type == "file_search_call": | ||
| results = getattr(output_item, "results", []) or [] | ||
| item = cast(FileSearchCall, output_item) | ||
| results = item.results or [] | ||
| for result in results: | ||
| resolved_source = _resolve_source_for_result(result, vs_ids, id_mapping) | ||
|
|
||
| # Handle both object and dict access | ||
| if isinstance(result, dict): | ||
| attributes = result.get("attributes", {}) | ||
| else: | ||
| attributes = getattr(result, "attributes", {}) | ||
| attributes = result.attributes | ||
| resolved_source = resolve_source_for_result( | ||
| attributes, vs_ids, id_mapping | ||
| ) | ||
|
|
||
| # Try to get URL from attributes | ||
| # Look for common URL fields in attributes | ||
|
|
@@ -1174,8 +1172,8 @@ def build_tool_result_from_mcp_output_item_done( | |
| ) | ||
|
|
||
|
|
||
| def _resolve_source_for_result( | ||
| result: Any, | ||
| def resolve_source_for_result( | ||
| attributes: dict[str, Any], | ||
| vector_store_ids: list[str], | ||
| rag_id_mapping: dict[str, str], | ||
| ) -> Optional[str]: | ||
|
|
@@ -1186,7 +1184,7 @@ def _resolve_source_for_result( | |
|
|
||
| Parameters: | ||
| ---------- | ||
| result: A file search result object with optional attributes. | ||
| attributes: A dictionary of attributes from a file search result. | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pass only |
||
| vector_store_ids: The vector store IDs used in this query. | ||
| rag_id_mapping: Mapping from vector_db_id to user-facing rag_id. | ||
|
|
||
|
|
@@ -1198,22 +1196,17 @@ def _resolve_source_for_result( | |
| store_id = vector_store_ids[0] | ||
| return rag_id_mapping.get(store_id, store_id) | ||
|
|
||
| if len(vector_store_ids) > 1: | ||
| attributes = getattr(result, "attributes", {}) or {} | ||
|
|
||
| # Primary: read index name embedded directly by rag-content. | ||
| # This value is already the user-facing rag_id, not a vector_db_id, | ||
| # so no mapping is needed. | ||
| attr_source: Optional[str] = attributes.get("source") | ||
| if attr_source: | ||
| return attr_source | ||
| # source is the user-facing source name, no mapping needed | ||
| if source := attributes.get("source"): | ||
| return str(source) | ||
|
|
||
| # Fallback: if llama-stack ever populates vector_store_id in results, | ||
| # use it with the rag_id_mapping. | ||
| attr_store_id: Optional[str] = attributes.get("vector_store_id") | ||
| if attr_store_id: | ||
| return rag_id_mapping.get(attr_store_id, attr_store_id) | ||
| # Fallback: if llama-stack ever populates vector_store_id in results, | ||
| # use it with the rag_id_mapping. | ||
| if vector_store_id := attributes.get("vector_store_id"): | ||
| vector_store_id = str(vector_store_id) | ||
| return rag_id_mapping.get(vector_store_id, vector_store_id) | ||
|
|
||
| # ambiguous: multiple vector stores, no source or vector store id | ||
| return None | ||
|
|
||
|
|
||
|
|
@@ -1256,8 +1249,8 @@ def extract_rag_chunks_from_file_search_item( | |
|
|
||
| rag_chunks: list[RAGChunk] = [] | ||
| for result in item.results: | ||
| source = _resolve_source_for_result( | ||
| result, vector_store_ids or [], rag_id_mapping or {} | ||
| source = resolve_source_for_result( | ||
| result.attributes, vector_store_ids or [], rag_id_mapping or {} | ||
| ) | ||
| attributes = _build_chunk_attributes(result) | ||
| rag_chunk = RAGChunk( | ||
|
|
||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resultis always an object