-
Notifications
You must be signed in to change notification settings - Fork 2k
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
refactor: Multi channel recall, adding display of knowledge base titles and other information #2309
Conversation
…es and other information
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
apps/application/flow/step_node/reranker_node/impl/base_reranker_node.py
Show resolved
Hide resolved
:data="paragraph.metadata" | ||
:content="paragraph.page_content" | ||
:index="paragraphIndex" | ||
/> | ||
</template> | ||
</template> | ||
<template v-else> -</template> |
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.
The provided code does not contain errors, but you might want to make the following improvements:
Improvements:
-
Use
v-bind
for Inline Attributes:- Using
v-bind:content="paragraph.content"
and similarly for other attributes can help avoid issues with syntax highlighting.
- Using
-
Consistent Attribute Usage:
- Ensure that all necessary attributes are consistently passed in the
<ParagraphCard>
component. In this case, you're passing bothmetadata
andpage_content
, but if only one is needed per card (metadata
), it's better to pass just that.
- Ensure that all necessary attributes are consistently passed in the
-
Remove Duplicates and Simplify Conditionals:
- The conditional checks for truthy values at lines 147, 423, and 449 look similar. It might be more efficient and clearer to use a single condition or handle them programmatically based on your requirements.
Here's a simplified version of the changes:
<!-- Line 147 -->
<div v-for="(paragraph, paragraphIndex) in paragraphs" :key="paragraphIndex" class="mb-8">
<ParagraphCard :data="paragraph.metadata" :index="paragraphIndex" />
</div>
<!-- Lines 423 and 449 (simplified version) -->
<template v-if="item">
<div class="paragraph-source-card cursor" @click="onParagraphClick(item)">
<ParagraphCard :data="item.metadata" :content="item.page_content"/>
<!-- Add more cards here as needed... -->
</div>
</template>
<template v-else> -
In the above improved versions:
- We've used
paragraphs
instead of accessingitem.document_list
directly to simplify the logic. - We've removed duplicate
card-boxes
and replaced them with reusable components like<ParagraphCard>
. This makes the code cleaner and easier to maintain.
question) | ||
similarity = reranker_setting.get('similarity', 0.6) | ||
max_paragraph_char_number = reranker_setting.get('max_paragraph_char_number', 5000) | ||
result = reset_result_list(result, documents) | ||
r = filter_result(result, max_paragraph_char_number, top_n, similarity) | ||
return NodeResult({'result_list': r, 'result': ''.join([item.get('page_content') for item in r])}, {}) | ||
|
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.
The provided code has several improvements that can enhance its readability, maintainability, and efficiency:
-
Use of
copy
Method: The linedocument_list = document_list.copy()
in thereset_result_list
function is unnecessary as it creates an extra copy ofdocument_list
. This should be removed. -
Inline Dictionary Comprehension: In the same function, consider inlining the dictionary comprehension to make it more readable.
-
Consistent Use of F-Strings: For string formatting consistency, you can use f-strings instead of concatenating strings with '+'. This can improve code readability.
Here's the revised version:
from typing import List
class Document:
def __init__(self, page_content="", metadata={}):
self.page_content = page_content
self.metadata = metadata
def merge_reranker_list(reranker_list, result=None):
if result is None:
result = []
for document in reranker_list:
if isinstance(document, list):
merge_reranker_list(document, result)
elif isinstance(document, dict):
content = document.get('title', '') + document.get('content', '')
result.append(Document(str(document) if len(content) == 0 else content,
{'title': document.get("title"),
'dataset_name': document.get("dataset_name"),
'document_name': document.get('document_name')})
else:
result.append(Document(str(document), {}))
return result
def filter_result(document_list: List[Document], max_paragraph_char_number, top_n, similarity):
return [doc for doc in document_list if len(doc.page_content) <= max_paragraph_char_number][:top_n]
def reset_result_list(result_list: List[Document], document_list: List[Document]):
r = []
for result in result_list:
filtered_docs = [d for d in document_list if d.page_content == result.page_content]
if filtered_docs:
item = filtered_docs[0]
document_list.remove(item)
r.append(Document(item.page_content, {**item.metadata, 'relevance_score': result.metadata.get('relevance_score')})
else:
r.append(result)
return r
# Assuming BaseRerankerNode class definition here...
Summary Changes:
- Removed redundant copying of
document_list
. - Used inline dictionary comprehensions where applicable.
- Simplified the logic for filtering results without making copies.
- Ensured consistent use of formatted strings using f-strings.
These changes should help improve the clarity and performance of the code while maintaining functionality.
content: { | ||
type: String, | ||
default: '' | ||
}, | ||
index: { | ||
type: Number, | ||
default: 0 |
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.
This code appears to be part of a Vue component using Element Plus and TypeScript. The changes made are focused on updating an existing MDPreview instance with new props and removing an unnecessary prop.
Potential Issues/Improvements:
-
Prop Naming Collision: While the
content
prop is removed from theel-scrollbar
, it's worth noting that there may be other places where this prop might still be required. It would be good to ensure consistency across all components when referencing properties. -
No Image Zoom In Option Removal: Since
noImgZoomIn
is removed, make sure that this functionality is handled elsewhere in your application if needed. -
Typo in Variable Name: There seems to be a typo in the comment regarding the variable name
$props.data.similarity.toFixed(3)
. This should likely be corrected to avoid runtime errors. -
Default Props Value Consistency: Although not immediately apparent here, consider maintaining consistent default values across all components related to previews or similar text content.
-
Code Readability: Ensure that any additional features added or modifications made do not significantly impact readability or maintainability.
Overall, the provided code looks clean and functional as intended for rendering markdown-like content within a scrollable view in a Vue.js application using Element Plus. Adjustments can be made based on specific requirements and additional functionalities you plan to add later.
refactor: Multi channel recall, adding display of knowledge base titles and other information