-
Notifications
You must be signed in to change notification settings - Fork 963
fix: Fix chunk naive llm classifier #173
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
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
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 |
|---|---|---|
|
|
@@ -21,7 +21,6 @@ async def chunk_naive_llm_classifier(data_chunks: list[DocumentChunk], classific | |
| for chunk_index, chunk in enumerate(data_chunks): | ||
| chunk_classification = chunk_classifications[chunk_index] | ||
| classification_data_points.append(uuid5(NAMESPACE_OID, chunk_classification.label.type)) | ||
| classification_data_points.append(uuid5(NAMESPACE_OID, chunk_classification.label.type)) | ||
|
|
||
| for classification_subclass in chunk_classification.label.subclass: | ||
| classification_data_points.append(uuid5(NAMESPACE_OID, classification_subclass.value)) | ||
|
|
@@ -39,7 +38,7 @@ class Keyword(BaseModel): | |
| if await vector_engine.has_collection(collection_name): | ||
| existing_data_points = await vector_engine.retrieve( | ||
| collection_name, | ||
| list(set(classification_data_points)), | ||
| [str(classification_data) for classification_data in list(set(classification_data_points))], | ||
|
Contributor
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. 🛠️ Refactor suggestion Consider centralizing UUID-to-string conversion logic. To improve maintainability and ensure consistent UUID handling, consider extracting the conversion logic into a utility function: def ensure_string_id(id_value: str | uuid.UUID) -> str:
"""Ensure ID is in string format for database operations."""
return str(id_value) if isinstance(id_value, uuid.UUID) else id_valueThis could be used throughout the code: -[str(classification_data) for classification_data in list(set(classification_data_points))]
+[ensure_string_id(classification_data) for classification_data in list(set(classification_data_points))] |
||
| ) if len(classification_data_points) > 0 else [] | ||
|
|
||
| existing_points_map = {point.id: True for point in existing_data_points} | ||
|
|
||
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.
Fix potential SQL injection vulnerability and add input validation.
The current implementation has several issues that need to be addressed:
data_point_idslist.data_point_idscontains only one item.Consider applying these improvements:
async def delete_data_points(self, collection_name: str, data_point_ids: list[str]): connection = await self.get_connection() collection = await connection.open_table(collection_name) + if not data_point_ids: + return None if len(data_point_ids) == 1: - results = await collection.delete(f"id = '{data_point_ids[0]}'") + results = await collection.delete("id = ?", [data_point_ids[0]]) else: - results = await collection.delete(f"id IN {tuple(data_point_ids)}") + placeholders = ','.join(['?' for _ in data_point_ids]) + results = await collection.delete(f"id IN ({placeholders})", data_point_ids) return resultsNote: If LanceDB doesn't support parameterized queries, please verify their documentation for the recommended way to safely handle user input in queries.