-
Notifications
You must be signed in to change notification settings - Fork 73
LCORE-1350: Refactor of vector_search utilities #1233
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
Draft
asimurka
wants to merge
1
commit into
lightspeed-core:main
Choose a base branch
from
asimurka:vector_search_refactor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
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
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 |
|---|---|---|
|
|
@@ -55,7 +55,7 @@ | |
| UnauthorizedResponse, | ||
| UnprocessableEntityResponse, | ||
| ) | ||
| from utils.types import RAGChunk, ReferencedDocument | ||
| from utils.types import ReferencedDocument | ||
| from utils.endpoints import ( | ||
| check_configuration_loaded, | ||
| validate_and_retrieve_conversation, | ||
|
|
@@ -75,6 +75,7 @@ | |
| build_mcp_tool_call_from_arguments_done, | ||
| build_tool_call_summary, | ||
| build_tool_result_from_mcp_output_item_done, | ||
| deduplicate_referenced_documents, | ||
| extract_token_usage, | ||
| extract_vector_store_ids_from_tools, | ||
| get_topic_summary, | ||
|
|
@@ -184,11 +185,8 @@ async def streaming_query_endpoint_handler( # pylint: disable=too-many-locals | |
|
|
||
| client = AsyncLlamaStackClientHolder().get_client() | ||
|
|
||
| pre_rag_chunks: list[RAGChunk] = [] | ||
| doc_ids_from_chunks: list[ReferencedDocument] = [] | ||
|
|
||
|
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. Not necessary to initialize |
||
| _, _, doc_ids_from_chunks, pre_rag_chunks = await perform_vector_search( | ||
| client, query_request, configuration | ||
| client, query_request.query, query_request.solr | ||
| ) | ||
|
|
||
| rag_context = format_rag_context_for_injection(pre_rag_chunks) | ||
|
|
@@ -277,6 +275,7 @@ async def retrieve_response_generator( | |
| Args: | ||
| responses_params: The Responses API parameters | ||
| context: The response generator context | ||
| doc_ids_from_chunks: List of ReferencedDocument objects extracted from static RAG | ||
|
|
||
| Returns: | ||
| tuple[AsyncIterator[str], TurnSummary]: The response generator and turn summary | ||
|
|
@@ -748,19 +747,9 @@ async def response_generator( # pylint: disable=too-many-branches,too-many-stat | |
| rag_id_mapping=context.rag_id_mapping, | ||
| ) | ||
|
|
||
| # Merge pre-RAG documents with tool-based documents (similar to query.py) | ||
|
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. Utility function for this purpose already exists |
||
| if turn_summary.pre_rag_documents: | ||
| all_documents = turn_summary.pre_rag_documents + tool_based_documents | ||
| seen = set() | ||
| deduplicated_documents = [] | ||
| for doc in all_documents: | ||
| key = (doc.doc_url, doc.doc_title) | ||
| if key not in seen: | ||
| seen.add(key) | ||
| deduplicated_documents.append(doc) | ||
| turn_summary.referenced_documents = deduplicated_documents | ||
| else: | ||
| turn_summary.referenced_documents = tool_based_documents | ||
| turn_summary.referenced_documents = deduplicate_referenced_documents( | ||
| tool_based_documents + turn_summary.pre_rag_documents | ||
| ) | ||
|
|
||
|
|
||
| def stream_http_error_event( | ||
|
|
||
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.
Not necessary, attribute is never None