M4: bug report - parent_chunks missing summary_vector/scene_order
This commit is contained in:
@@ -0,0 +1,66 @@
|
|||||||
|
# Bug: `parent_chunks` 缺少 `summary_vector` / `scene_order` 欄位
|
||||||
|
|
||||||
|
## 症狀
|
||||||
|
|
||||||
|
`POST /api/v1/search/smart` 回傳 500 error:
|
||||||
|
|
||||||
|
```
|
||||||
|
DB search failed: column "scene_order" does not exist
|
||||||
|
```
|
||||||
|
|
||||||
|
同時 `summary_vector` 欄位也不存在。
|
||||||
|
|
||||||
|
## 根因
|
||||||
|
|
||||||
|
`src/core/db/postgres_db.rs` 中的 `search_parent_chunks_semantic()` 使用了 DB 中不存在的欄位:
|
||||||
|
|
||||||
|
```sql
|
||||||
|
SELECT id, scene_order, start_time, end_time, summary_text as summary,
|
||||||
|
metadata,
|
||||||
|
(1 - (summary_vector <=> $1::vector)) as similarity
|
||||||
|
FROM parent_chunks
|
||||||
|
WHERE uuid = $2
|
||||||
|
ORDER BY summary_vector <=> $1::vector
|
||||||
|
```
|
||||||
|
|
||||||
|
但 `dev.parent_chunks` table 實際欄位:
|
||||||
|
|
||||||
|
| 欄位 | 類型 | 在 code 中使用? |
|
||||||
|
|------|------|-----------------|
|
||||||
|
| `id` | integer | ✅ |
|
||||||
|
| `uuid` | varchar | ✅ |
|
||||||
|
| `chunk_id` | varchar | ❌ 未使用 |
|
||||||
|
| `summary_text` | text | ✅ |
|
||||||
|
| `summary_tsvector` | tsvector | ❌ 未使用 |
|
||||||
|
| `metadata` | jsonb | ✅ |
|
||||||
|
| `scene_order` | ❌ 不存在 | ❌ code 使用但 DB 無 |
|
||||||
|
| `summary_vector` | ❌ 不存在 | ❌ code 使用但 DB 無 |
|
||||||
|
|
||||||
|
## 建議修正
|
||||||
|
|
||||||
|
**選項 A**:修改 `search_parent_chunks_semantic()` 中的 SQL 查詢,移除不存在的欄位
|
||||||
|
|
||||||
|
```diff
|
||||||
|
- SELECT id, scene_order, start_time, end_time, summary_text as summary, metadata,
|
||||||
|
- (1 - (summary_vector <=> $1::vector)) as similarity
|
||||||
|
- FROM parent_chunks
|
||||||
|
- WHERE uuid = $2
|
||||||
|
- ORDER BY summary_vector <=> $1::vector
|
||||||
|
+ SELECT id, summary_text as summary, metadata
|
||||||
|
+ FROM parent_chunks
|
||||||
|
+ WHERE uuid = $1
|
||||||
|
```
|
||||||
|
|
||||||
|
**選項 B**:新增 migration 建立缺少的欄位
|
||||||
|
|
||||||
|
```sql
|
||||||
|
ALTER TABLE dev.parent_chunks ADD COLUMN scene_order integer;
|
||||||
|
ALTER TABLE dev.parent_chunks ADD COLUMN summary_vector vector(768);
|
||||||
|
```
|
||||||
|
|
||||||
|
## 相關檔案
|
||||||
|
|
||||||
|
| 檔案 | 說明 |
|
||||||
|
|------|------|
|
||||||
|
| `src/core/db/postgres_db.rs` | `search_parent_chunks_semantic()` 使用不存在的欄位 |
|
||||||
|
| `src/api/search.rs` | `smart_search()` 呼叫 semantic search |
|
||||||
Reference in New Issue
Block a user