feat: smart search response includes start_frame/end_frame/fps, add limit param

This commit is contained in:
Accusys
2026-05-18 01:21:43 +08:00
parent 4125163f7b
commit 362c63007c
3 changed files with 25 additions and 13 deletions

View File

@@ -17,6 +17,7 @@ Semantic vector search using EmbeddingGemma-300m. Generates a query embedding vi
|-------|------|----------|---------|-------------| |-------|------|----------|---------|-------------|
| `file_uuid` | string | Yes | — | File UUID to search within | | `file_uuid` | string | Yes | — | File UUID to search within |
| `query` | string | Yes | — | Search text | | `query` | string | Yes | — | Search text |
| `limit` | integer | No | 5 | Max results to return |
| `page` | integer | No | 1 | Page number | | `page` | integer | No | 1 | Page number |
| `page_size` | integer | No | 5 | Items per page | | `page_size` | integer | No | 5 | Items per page |
@@ -36,13 +37,19 @@ curl -s -X POST "$API/api/v1/search/smart" \
"query": "Audrey Hepburn", "query": "Audrey Hepburn",
"results": [ "results": [
{ {
"parent_id": 12345, "parent_id": 1087822,
"start_time": 299.0, "scene_order": 1087822,
"end_time": 300.0, "start_frame": 104438,
"summary": "[299s-300s, 1s] Cast: Audrey Hepburn. Total: 1 lines, 5 words...", "end_frame": 104538,
"similarity": 0.72 "fps": 24.0,
"start_time": 4351.6,
"end_time": 4355.76,
"summary": "[4352s-4356s, 4s] Cast: Audrey Hepburn. Total: 2 lines, 10 words. Speakers: Audrey Hepburn (2 lines)",
"similarity": 0.67
} }
], ],
"page": 1,
"page_size": 5,
"strategy": "semantic_vector_search" "strategy": "semantic_vector_search"
} }
``` ```

View File

@@ -101,9 +101,9 @@ pub async fn smart_search(
id: 0, id: 0,
parent_id: p.scene_order, parent_id: p.scene_order,
scene_order: Some(p.scene_order), scene_order: Some(p.scene_order),
start_frame: 0, start_frame: p.start_frame,
end_frame: 0, end_frame: p.end_frame,
fps: 0.0, fps: p.fps,
start_time: p.start_time, start_time: p.start_time,
end_time: p.end_time, end_time: p.end_time,
raw_text: None, raw_text: None,

View File

@@ -759,6 +759,9 @@ pub struct PostgresCache {
pub struct SemanticSearchResult { pub struct SemanticSearchResult {
pub id: i32, pub id: i32,
pub scene_order: i32, pub scene_order: i32,
pub start_frame: i64,
pub end_frame: i64,
pub fps: f64,
pub start_time: f64, pub start_time: f64,
pub end_time: f64, pub end_time: f64,
pub summary: String, pub summary: String,
@@ -2000,11 +2003,13 @@ impl PostgresDb {
let results = sqlx::query_as::<_, SemanticSearchResult>( let results = sqlx::query_as::<_, SemanticSearchResult>(
&format!( &format!(
"SELECT \ "SELECT \
id, id as scene_order, start_time, end_time, \ id, id as scene_order, \
COALESCE(summary_text, text_content, '') as summary, \ (start_time * fps)::bigint as start_frame, (end_time * fps)::bigint as end_frame, \
metadata, \ fps, start_time, end_time, \
(1 - (embedding <=> $1::vector)) as similarity \ COALESCE(summary_text, text_content, '') as summary, \
FROM {} \ metadata, \
(1 - (embedding <=> $1::vector)) as similarity \
FROM {} \
WHERE file_uuid = $2 AND chunk_type IN ('story_parent', 'llm_parent') AND embedding IS NOT NULL \ WHERE file_uuid = $2 AND chunk_type IN ('story_parent', 'llm_parent') AND embedding IS NOT NULL \
ORDER BY embedding <=> $1::vector \ ORDER BY embedding <=> $1::vector \
LIMIT $3", LIMIT $3",