Skip to content

feat: implement rebuild indexes functionality for documents#979

Merged
iziang merged 6 commits into
mainfrom
support/rebuild-index
Jun 23, 2025
Merged

feat: implement rebuild indexes functionality for documents#979
iziang merged 6 commits into
mainfrom
support/rebuild-index

Conversation

@iziang
Copy link
Copy Markdown
Contributor

@iziang iziang commented Jun 23, 2025

No description provided.

iziang added 2 commits June 23, 2025 15:50
- Implemented a new API endpoint to rebuild specified types of indexes for a document.
- Added corresponding request and response models for the rebuild indexes functionality.
- Updated the frontend to include a modal for selecting index types to rebuild.
- Enhanced the document management UI with a rebuild index option in the dropdown menu.
- Added localization support for rebuild index messages in both English and Chinese.
- Added a new API endpoint to rebuild specified types of indexes for a document.
- Introduced request and response models for the rebuild indexes feature.
- Updated the document service to handle index rebuilding logic.
- Enhanced the main view with a new endpoint for triggering index rebuilds.
- Included logging for index rebuild operations and success responses.
@apecloud-bot apecloud-bot added the size/XL Denotes a PR that changes 500-999 lines. label Jun 23, 2025
@cursor
Copy link
Copy Markdown

cursor Bot commented Jun 23, 2025

🚨 BugBot couldn't run

Something went wrong. Try again by commenting "bugbot run", or contact support (requestId: serverGenReqId_46150768-d3f6-4e9d-9f82-d06d2cdbc205).

@iziang
Copy link
Copy Markdown
Contributor Author

iziang commented Jun 23, 2025

bugbot run

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@iziang iziang merged commit c500ec7 into main Jun 23, 2025
6 of 7 checks passed
@iziang iziang deleted the support/rebuild-index branch June 23, 2025 09:52
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Bug: API Contract Violation: Incorrect Response Code

The rebuild_indexes endpoint's OpenAPI specification defines a 204 No Content response, but the document_service.py implementation returns a 200 OK with a JSON body {"code": "200", "message": "..."}. This mismatch between the API contract and implementation can cause client issues.

aperag/api/paths/collections.yaml#L321-L324

$ref: '../components/schemas/document.yaml#/rebuildIndexesRequest'
responses:
'204':
description: Index rebuild initiated successfully

aperag/service/document_service.py#L457-L461

return {
"code": "200",
"message": f"Index rebuild initiated for types: {', '.join(index_types)}"
}

Fix in Cursor


Bug: Verification Queries Execute Outside Transaction

The rebuild_document_indexes method's transaction function (_rebuild_document_indexes_atomically) performs verification queries (self.db_ops.query_document, self.db_ops.query_collection) using a global db_ops instance instead of the transaction's session parameter. This causes these queries to execute outside the transaction, breaking isolation and potentially leading to race conditions or inconsistent reads. These verification queries should either be moved outside the transaction or rewritten to use the provided session.

aperag/service/document_service.py#L440-L451

# Verify document exists and user has access
document = await self.db_ops.query_document(user_id, collection_id, document_id)
if not document:
raise DocumentNotFoundException(f"Document {document_id} not found")
if document.collection_id != collection_id:
raise ResourceNotFoundException(f"Document {document_id} not found in collection {collection_id}")
# Verify user has access to the collection
collection = await self.db_ops.query_collection(user_id, collection_id)
if not collection or collection.user != user_id:
raise ResourceNotFoundException(f"Collection {collection_id} not found or access denied")

Fix in Cursor


Was this report helpful? Give feedback by reacting with 👍 or 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XL Denotes a PR that changes 500-999 lines.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants