diff --git "a/journals/20260223-0013-\343\203\206\343\203\274\343\203\226\343\203\253\346\247\213\351\200\240\343\201\256\346\255\243\350\246\217\345\214\226\343\201\250\343\203\211\343\202\255\343\203\245\343\203\241\343\203\263\343\203\210\343\203\273\343\203\201\343\203\243\343\203\263\343\202\257\343\201\256\345\210\206\351\233\242.md" "b/journals/20260223-0013-\343\203\206\343\203\274\343\203\226\343\203\253\346\247\213\351\200\240\343\201\256\346\255\243\350\246\217\345\214\226\343\201\250\343\203\211\343\202\255\343\203\245\343\203\241\343\203\263\343\203\210\343\203\273\343\203\201\343\203\243\343\203\263\343\202\257\343\201\256\345\210\206\351\233\242.md" index 5149a7e..c72f120 100644 --- "a/journals/20260223-0013-\343\203\206\343\203\274\343\203\226\343\203\253\346\247\213\351\200\240\343\201\256\346\255\243\350\246\217\345\214\226\343\201\250\343\203\211\343\202\255\343\203\245\343\203\241\343\203\263\343\203\210\343\203\273\343\203\201\343\203\243\343\203\263\343\202\257\343\201\256\345\210\206\351\233\242.md" +++ "b/journals/20260223-0013-\343\203\206\343\203\274\343\203\226\343\203\253\346\247\213\351\200\240\343\201\256\346\255\243\350\246\217\345\214\226\343\201\250\343\203\211\343\202\255\343\203\245\343\203\241\343\203\263\343\203\210\343\203\273\343\203\201\343\203\243\343\203\263\343\202\257\343\201\256\345\210\206\351\233\242.md" @@ -1,25 +1,23 @@ -# Journal: 20260223-0013-テーブル構造の正規化とドキュメント・チャンクの分離 (Table Structure Normalization and Document-Chunk Separation) +# Journal: 20260223-0013-テーブル構造の正規化とドキュメント・チャンクの分離 -## 日本語 (Japanese) - -### 1. 作業実施の理由 +## 1. 作業実施の理由 Issue-2に基づき、データベースの正規化を行うため。従来の設計では、1つのドキュメントを複数チャンクに分割した際、`items`テーブルにチャンクごとに同じ`path`情報が保持され、データの冗長性と管理上の不都合が生じていた。 -### 2. 指示(背景、観点、意図を含む) +## 2. 指示(背景、観点、意図を含む) - **背景**: 意味検索の精度向上のためチャンク分割を導入したが、メタデータとデータが混在していた。 - **観点**: 1ドキュメント対Nチャンクの関係をデータベース上で明示的に管理する。 - **意図**: 削除時にドキュメント単位で一括操作を可能にし、かつ検索結果で正しいソースを表示できるようにする。 -### 3. 指示事項とその対応 +## 3. 指示事項とその対応 - **ドキュメントテーブルの作成**: `documents`テーブルを新設し、`path`を一意に管理。 - **アイテムテーブルの変更**: `document_id`と`chunk_index`を追加し、冗長な`path`を削除。 - **MCPツールの修正**: `add_item_text`や`search_text`を新スキーマに合わせてリファクタリング。 - **型不整合の修正 (AI自律修正)**: `axum::response::Response`と`Option`の不整合を、`JsonRpcResponse`の活用により解決。 -### 4. 作業詳細 +## 4. 作業詳細 AIエージェントは以下の手順で作業を実施した。 @@ -28,44 +26,10 @@ 3. 開発中に遭遇した型不整合エラー(Axumの戻り型とMCP内部ロジックの不一致)を検知し、適切なレスポンス変換ロジックを組み込むことで自律的に解決した。 4. 仕様書(`03_database_specification.md`)のER図と解説を更新した。 -### 5. AI視点での結果 +## 5. AI視点での結果 リファクタリングにより、データベース構造がクリーンになり、将来的なドキュメント管理(一括削除や管理画面での表示など)が容易になった。また、コンパイルエラーの修正過程で、AxumハンドラとMCPツールロジックの境界をより正確に把握し、堅牢なエラーレスポンスの実装が行えた。 ---- - -## English - -### 1. Reason for Work - -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. - -### 2. Instructions (Background, Perspective, Intent) - -- **Background**: Chunking was introduced to improve the accuracy of semantic search, but metadata and data were mixed. -- **Perspective**: Explicitly manage the 1-document-to-N-chunks relationship in the database. -- **Intent**: Enable batch operations on a per-document basis during deletion and ensure that the correct source is displayed in search results. - -### 3. Points and Responses - -- **Document Table Creation**: Created a new `documents` table to manage `path` uniquely. -- **Item Table Modification**: Added `document_id` and `chunk_index`, and removed the redundant `path`. -- **MCP Tool Refactoring**: Refactored `add_item_text` and `search_text` to fit the new schema. -- **Type Mismatch Fix (AI Autonomous Fix)**: Resolved the mismatch between `axum::response::Response` and `Option` by utilizing `JsonRpcResponse`. - -### 4. Work Details - -The AI agent carried out the work in the following steps: - -1. Updated the schema definition in `src/backend/src/db.rs`, adding the `documents` table and normalizing the `items` table. -2. Refactored the tool logic in `src/backend/src/mcp.rs`. Specifically, `add_item_text` was re-implemented to include document existence checks and cleanup of existing chunks. -3. Detected type mismatch errors (discrepancy between Axum return types and MCP internal logic) encountered during development and resolved them autonomously by incorporating appropriate response conversion logic. -4. Updated the ER diagram and explanations in the specification document (`03_database_specification.md`). - -### 5. Results from AI Perspective - -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. - ```mermaid graph TD A[Add Item Request] --> B{Find Document?} diff --git "a/journals/20260223-0015-MIME\343\202\277\343\202\244\343\203\227\345\257\276\345\277\234\343\201\256\350\277\275\345\212\240.md" "b/journals/20260223-0015-MIME\343\202\277\343\202\244\343\203\227\345\257\276\345\277\234\343\201\256\350\277\275\345\212\240.md" index f6016ed..1fbe626 100644 --- "a/journals/20260223-0015-MIME\343\202\277\343\202\244\343\203\227\345\257\276\345\277\234\343\201\256\350\277\275\345\212\240.md" +++ "b/journals/20260223-0015-MIME\343\202\277\343\202\244\343\203\227\345\257\276\345\277\234\343\201\256\350\277\275\345\212\240.md" @@ -1,25 +1,23 @@ -# Journal: 20260223-0015-MIMEタイプ対応の追加 (Adding MIME Type Support) +# Journal: 20260223-0015-MIMEタイプ対応の追加 -## 日本語 (Japanese) - -### 1. 作業実施の理由 +## 1. 作業実施の理由 ユーザーの提案に基づき、`documents` テーブルに MIME タイプを保持することで、将来的なファイル形式の拡張(PDF, 画像, 各種コード等)に対応しやすくするため。 -### 2. 指示(背景、観点、意図を含む) +## 2. 指示(背景、観点、意図を含む) - **背景**: 現状はテキストチャンクのみだが、ソースファイルの形式をメタデータとして保持したい。 - **観点**: スキーマの正規化を維持しつつ、自動検知と明示的指定の両方をサポートする。 - **意図**: フロントエンドでの表示切り替えや、バックエンドでの適切なパース処理の布石とする。 -### 3. 指示事項とその対応 +## 3. 指示事項とその対応 - **スキーマ更新**: `documents` テーブルに `mime TEXT` カラムを追加。 - **自動検知の実装**: `mcp.rs` 内で、`path` の拡張子から主要な MIME タイプ(markdown, rust, javascript 等)を自動判別するロジックを追加。 - **ツール更新**: `add_item_text` に `mime` 引数を追加。また、検索結果に `mime` 情報を返すように変更。 - **ドキュメント更新**: データベース仕様書(`03_database_specification.md`)に新設カラムを反映。 -### 4. 作業詳細 +## 4. 作業詳細 AIエージェントは以下の手順で作業を実施した。 @@ -31,47 +29,10 @@ 3. `docs/specification/03_database_specification.md` を更新。 4. `cargo check` により、バックエンドの整合性とビルド可能性を確認。 -### 5. AI視点での結果 +## 5. AI視点での結果 今回の変更により、TelosDB は単なるテキスト断片の集まりではなく、「型(MIME)を持ったドキュメントの集合」としての性質が強まりました。自動検知ロジックにより、ユーザーが意識せずとも適切なメタデータが蓄積されるようになり、将来的な UI 改善やマルチモーダル対応への強力な基盤となりました。 ---- - -## English - -### 1. Reason for Work - -Based on the user's suggestion, adding MIME types to the `documents` table to facilitate future support for various file formats (PDF, images, various code types, etc.). - -### 2. Instructions (Background, Perspective, Intent) - -- **Background**: Currently only text chunks are handled, but we want to retain the source file format as metadata. -- **Perspective**: Maintain schema normalization while supporting both automatic detection and explicit specification. -- **Intent**: Lay the groundwork for UI display logic and appropriate backend parsing processes. - -### 3. Points and Responses - -- **Schema Update**: Added a `mime TEXT` column to the `documents` table. -- **Automatic Detection Implementation**: Added logic in `mcp.rs` to automatically determine common MIME types (markdown, rust, javascript, etc.) based on file extensions. -- **Tool Updates**: Added a `mime` argument to `add_item_text` and updated search results to include `mime` information. -- **Documentation Update**: Reflected the new column in the database specification (`03_database_specification.md`). - -### 4. Work Details - -The AI agent carried out the work in the following steps: - -1. Modified `src/backend/src/db.rs` to add the `mime` column to the table creation SQL. -2. Refactored `src/backend/src/mcp.rs`: - - Implemented argument processing and extension-based MIME inference logic for `add_item_text`. - - Added logic to update the MIME type if the document already exists. - - Added the `mime` column to SQL queries and JSON responses for `search_text` and `get_item_by_id`. -3. Updated `docs/specification/03_database_specification.md`. -4. Verified backend consistency and buildability with `cargo check`. - -### 5. Results from AI Perspective - -With this change, TelosDB has evolved from a collection of text fragments into a "collection of typed (MIME) documents." The automatic detection logic ensures that appropriate metadata is accumulated without extra user effort, providing a strong foundation for future UI improvements and multimodal support. - ```mermaid graph LR A[File Path] --> B{Extension?}