feat: score-based search, LLM re-ranking endpoint, video title search, pipeline module

Core search changes:
- Replace RRF with score-based merge (max of semantic/keyword/identity)
- Add video title ILIKE search for brand/name queries (score 0.9)
- Add /api/v1/search/llm-smart endpoint with Gemma 4 re-ranking
- Fix LLM JSON parsing (markdown fences, empty responses)

Infrastructure:
- Rebuild Qdrant collection (clear 347K contaminated points)
- Add dotenv loading to main.rs for config parity
- Implement store_pre_chunk in postgres_db.rs

Pipeline module (WordPress):
- store-asrx, rule1, vectorize, phase1, complete endpoints
- CLI commands for pipeline operations

Docs:
- SEARCH_SCORE_IMPROVEMENT.md (score-based merge proposal)
This commit is contained in:
Accusys
2026-06-04 07:40:41 +08:00
parent e1572907ae
commit 834b0d4865
14 changed files with 835 additions and 31 deletions
+85
View File
@@ -0,0 +1,85 @@
use axum::extract::Path;
use axum::routing::post;
use axum::{Json, Router};
use serde_json::{json, Value};
use crate::core::db::postgres_db::PostgresDb;
use crate::core::pipeline as pipeline_core;
use crate::core::config;
async fn handle_store_asrx(Path(uuid): Path<String>) -> Result<Json<Value>, (axum::http::StatusCode, Json<Value>)> {
let db = PostgresDb::new(&config::DATABASE_URL).await
.map_err(|e| {
tracing::error!("DB error: {}", e);
(axum::http::StatusCode::INTERNAL_SERVER_ERROR, Json(json!({"error": "DB connection failed"})))
})?;
pipeline_core::store_asrx_chunks(&db, &uuid).await
.map_err(|e| {
tracing::error!("store_asrx error: {}", e);
(axum::http::StatusCode::INTERNAL_SERVER_ERROR, Json(json!({"error": e.to_string()})))
})?;
Ok(Json(json!({"success": true, "message": "ASRX chunks stored", "file_uuid": uuid})))
}
async fn handle_rule1(Path(uuid): Path<String>) -> Result<Json<Value>, (axum::http::StatusCode, Json<Value>)> {
let db = PostgresDb::new(&config::DATABASE_URL).await
.map_err(|e| {
tracing::error!("DB error: {}", e);
(axum::http::StatusCode::INTERNAL_SERVER_ERROR, Json(json!({"error": "DB connection failed"})))
})?;
let count = pipeline_core::execute_rule1(&db, &uuid).await
.map_err(|e| {
tracing::error!("rule1 error: {}", e);
(axum::http::StatusCode::INTERNAL_SERVER_ERROR, Json(json!({"error": e.to_string()})))
})?;
Ok(Json(json!({"success": true, "message": format!("Rule 1 complete: {} chunks", count), "file_uuid": uuid, "chunks": count})))
}
async fn handle_vectorize(Path(uuid): Path<String>) -> Result<Json<Value>, (axum::http::StatusCode, Json<Value>)> {
pipeline_core::vectorize_chunks(&uuid).await
.map_err(|e| {
tracing::error!("vectorize error: {}", e);
(axum::http::StatusCode::INTERNAL_SERVER_ERROR, Json(json!({"error": e.to_string()})))
})?;
Ok(Json(json!({"success": true, "message": "Vectorization complete", "file_uuid": uuid})))
}
async fn handle_phase1(Path(uuid): Path<String>) -> Result<Json<Value>, (axum::http::StatusCode, Json<Value>)> {
pipeline_core::run_phase1(&uuid).await
.map_err(|e| {
tracing::error!("phase1 error: {}", e);
(axum::http::StatusCode::INTERNAL_SERVER_ERROR, Json(json!({"error": e.to_string()})))
})?;
Ok(Json(json!({"success": true, "message": "Phase 1 complete", "file_uuid": uuid})))
}
async fn handle_complete(Path(uuid): Path<String>) -> Result<Json<Value>, (axum::http::StatusCode, Json<Value>)> {
let db = PostgresDb::new(&config::DATABASE_URL).await
.map_err(|e| {
tracing::error!("DB error: {}", e);
(axum::http::StatusCode::INTERNAL_SERVER_ERROR, Json(json!({"error": "DB connection failed"})))
})?;
pipeline_core::mark_complete(&db, &uuid).await
.map_err(|e| {
tracing::error!("complete error: {}", e);
(axum::http::StatusCode::INTERNAL_SERVER_ERROR, Json(json!({"error": e.to_string()})))
})?;
Ok(Json(json!({"success": true, "message": "Video marked as completed", "file_uuid": uuid})))
}
pub fn pipeline_routes() -> Router<crate::api::types::AppState> {
Router::new()
.route("/api/v1/file/:file_uuid/store-asrx", post(handle_store_asrx))
.route("/api/v1/file/:file_uuid/rule1", post(handle_rule1))
.route("/api/v1/file/:file_uuid/vectorize", post(handle_vectorize))
.route("/api/v1/file/:file_uuid/phase1", post(handle_phase1))
.route("/api/v1/file/:file_uuid/complete", post(handle_complete))
}