Issue-2に基づき、データベースの正規化を行うため。従来の設計では、1つのドキュメントを複数チャンクに分割した際、itemsテーブルにチャンクごとに同じpath情報が保持され、データの冗長性と管理上の不都合が生じていた。
documentsテーブルを新設し、pathを一意に管理。document_idとchunk_indexを追加し、冗長なpathを削除。add_item_textやsearch_textを新スキーマに合わせてリファクタリング。axum::response::ResponseとOption<Value>の不整合を、JsonRpcResponseの活用により解決。AIエージェントは以下の手順で作業を実施した。
src/backend/src/db.rs のスキーマ定義を更新し、documentsテーブルの追加とitemsテーブルの正規化を行った。src/backend/src/mcp.rs の各ツールロジックをリファクタリングした。特に add_item_text では、ドキュメントの存在確認と既存チャンクのクリーンアップを含めて再実装した。03_database_specification.md)のER図と解説を更新した。リファクタリングにより、データベース構造がクリーンになり、将来的なドキュメント管理(一括削除や管理画面での表示など)が容易になった。また、コンパイルエラーの修正過程で、AxumハンドラとMCPツールロジックの境界をより正確に把握し、堅牢なエラーレスポンスの実装が行えた。
To perform database normalization based on Issue-2. In the previous design, when a single document was split into multiple chunks, the same path information was held for each chunk in the items table, resulting in data redundancy and management inconveniences.
documents table to manage path uniquely.document_id and chunk_index, and removed the redundant path.add_item_text and search_text to fit the new schema.axum::response::Response and Option<Value> by utilizing JsonRpcResponse.The AI agent carried out the work in the following steps:
src/backend/src/db.rs, adding the documents table and normalizing the items table.src/backend/src/mcp.rs. Specifically, add_item_text was re-implemented to include document existence checks and cleanup of existing chunks.03_database_specification.md).The refactoring cleaned up the database structure and simplified future document management (such as bulk deletion or display in a management screen). Additionally, during the process of fixing compilation errors, the boundaries between Axum handlers and MCP tool logic were grasped more accurately, enabling the implementation of robust error responses.
graph TD
A[Add Item Request] --> B{Find Document?}
B -- No --> C[Create Document Record]
B -- Yes --> D[Wipe Old Chunks]
C --> E[Loop: Split Content]
D --> E
E --> F[Generate LSA Vector]
F --> G[Save Chunk to items]
G --> H[Update HNSW Index]