fix: M4 Phase 1 bugs - dev.chunks refs, search_path, uuid column
Bug fixes from M4 report: - 4 remaining dev.chunks → dev.chunk in SQL queries - search_path includes public for pgvector extension - get_chunk_by_chunk_id_and_uuid: uuid → file_uuid - New endpoint: GET /api/v1/file/:uuid/chunk/:chunk_id
This commit is contained in:
@@ -776,7 +776,7 @@ pub async fn run_5w1h_agent(db: &PostgresDb, file_uuid: &str) -> anyhow::Result<
|
||||
match embedder.embed_document(text).await {
|
||||
Ok(vector) => {
|
||||
if let Err(e) = sqlx::query(
|
||||
"UPDATE dev.chunks SET embedding = $1::vector WHERE chunk_id = $2 AND file_uuid = $3"
|
||||
"UPDATE dev.chunk SET embedding = $1::vector WHERE chunk_id = $2 AND file_uuid = $3"
|
||||
)
|
||||
.bind(&vector as &[f32])
|
||||
.bind(chunk_id)
|
||||
|
||||
@@ -1306,6 +1306,25 @@ async fn trigger_processing(
|
||||
})))
|
||||
}
|
||||
|
||||
async fn get_chunk_by_path(
|
||||
Path((file_uuid, chunk_id)): Path<(String, String)>,
|
||||
State(state): State<AppState>,
|
||||
) -> Result<Json<Chunk>, StatusCode> {
|
||||
let chunk = state
|
||||
.db
|
||||
.get_chunk_by_chunk_id_and_uuid(&chunk_id, &file_uuid)
|
||||
.await
|
||||
.map_err(|_| {
|
||||
tracing::error!("[get_chunk_by_path] DB error: {}:{}", file_uuid, chunk_id);
|
||||
StatusCode::INTERNAL_SERVER_ERROR
|
||||
})?
|
||||
.ok_or_else(|| {
|
||||
tracing::warn!("[get_chunk_by_path] Not found: {}:{}", file_uuid, chunk_id);
|
||||
StatusCode::NOT_FOUND
|
||||
})?;
|
||||
Ok(Json(chunk))
|
||||
}
|
||||
|
||||
async fn get_asset_status(
|
||||
State(state): State<AppState>,
|
||||
Path(uuid): Path<String>,
|
||||
@@ -2508,6 +2527,7 @@ pub async fn start_server(host: &str, port: u16) -> anyhow::Result<()> {
|
||||
.route("/api/v1/files/scan", get(scan_files))
|
||||
.route("/api/v1/file/:file_uuid/probe", get(probe_by_uuid))
|
||||
.route("/api/v1/file/:file_uuid/process", post(trigger_processing))
|
||||
.route("/api/v1/file/:file_uuid/chunk/:chunk_id", get(get_chunk_by_path))
|
||||
|
||||
.route("/api/v1/progress/:uuid", get(get_progress))
|
||||
.route("/api/v1/jobs", get(list_jobs))
|
||||
|
||||
@@ -741,8 +741,8 @@ impl PostgresDb {
|
||||
let schema = schema.to_string();
|
||||
tracing::debug!("after_connect: setting search_path to {}", schema);
|
||||
Box::pin(async move {
|
||||
// Always set search_path explicitly to avoid using default "dev, public"
|
||||
sqlx::query(&format!("SET search_path TO {}", schema))
|
||||
// Include public schema for pgvector extension
|
||||
sqlx::query(&format!("SET search_path TO {}, public", schema))
|
||||
.execute(conn)
|
||||
.await?;
|
||||
Ok(())
|
||||
@@ -2774,7 +2774,7 @@ impl PostgresDb {
|
||||
) -> Result<Option<Chunk>> {
|
||||
let table = "dev.chunk";
|
||||
let row = sqlx::query(&format!(
|
||||
"SELECT COALESCE(file_id, 0) as file_id, uuid, chunk_id, chunk_type, COALESCE(fps, 24.0) as fps, COALESCE(start_frame, 0) as start_frame, COALESCE(end_frame, 0) as end_frame, text_content, content, metadata, vector_id, COALESCE(frame_count, 0) as frame_count, pre_chunk_ids, parent_chunk_id, child_chunk_ids, visual_stats FROM {} WHERE chunk_id = $1 AND uuid = $2",
|
||||
"SELECT COALESCE(file_id, 0) as file_id, file_uuid, chunk_id, chunk_type, COALESCE(fps, 24.0) as fps, COALESCE(start_frame, 0) as start_frame, COALESCE(end_frame, 0) as end_frame, text_content, content, metadata, vector_id, COALESCE(frame_count, 0) as frame_count, pre_chunk_ids, parent_chunk_id, child_chunk_ids, visual_stats FROM {} WHERE chunk_id = $1 AND file_uuid = $2",
|
||||
table
|
||||
))
|
||||
.bind(chunk_id)
|
||||
@@ -2821,7 +2821,7 @@ impl PostgresDb {
|
||||
|
||||
Ok(Some(Chunk {
|
||||
file_id,
|
||||
uuid: r.get("uuid"),
|
||||
uuid: r.get("file_uuid"),
|
||||
chunk_id: r.get("chunk_id"),
|
||||
|
||||
chunk_type,
|
||||
@@ -4623,7 +4623,7 @@ impl PostgresDb {
|
||||
COALESCE(summary_text, text_content, '') as summary,
|
||||
metadata,
|
||||
(1 - (embedding <=> $1::vector)) as similarity
|
||||
FROM dev.chunks
|
||||
FROM dev.chunk
|
||||
WHERE file_uuid = $2 AND chunk_type = 'cut' AND embedding IS NOT NULL
|
||||
ORDER BY embedding <=> $1::vector
|
||||
LIMIT $3
|
||||
|
||||
@@ -1002,7 +1002,7 @@ impl JobWorker {
|
||||
let pool = db.pool();
|
||||
|
||||
let rows = sqlx::query_as::<_, (String, String, String, f64, f64, String)>(
|
||||
"SELECT chunk_id, chunk_type, text_content, start_time, end_time, content::text FROM dev.chunks WHERE file_uuid = $1 AND chunk_type = 'sentence' AND embedding IS NULL AND (text_content IS NOT NULL AND text_content != '') ORDER BY chunk_index",
|
||||
"SELECT chunk_id, chunk_type, text_content, start_time, end_time, content::text FROM dev.chunk WHERE file_uuid = $1 AND chunk_type = 'sentence' AND embedding IS NULL AND (text_content IS NOT NULL AND text_content != '') ORDER BY id",
|
||||
)
|
||||
.bind(uuid)
|
||||
.fetch_all(pool)
|
||||
|
||||
@@ -1080,7 +1080,7 @@ impl ProcessorPool {
|
||||
"top_5": scene.top_5,
|
||||
});
|
||||
let _ = sqlx::query(
|
||||
"UPDATE dev.chunks SET metadata = metadata || $1::jsonb WHERE file_uuid=$2 AND chunk_id=$3"
|
||||
"UPDATE dev.chunk SET metadata = metadata || $1::jsonb WHERE file_uuid=$2 AND chunk_id=$3"
|
||||
)
|
||||
.bind(&meta)
|
||||
.bind(uuid)
|
||||
|
||||
Reference in New Issue
Block a user