Skip to content

bugfix: fix rag top score scoring #2963

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ export const RAGAnalyticsPage = () => {
accessorKey: "top_score",
header: "Top Score",
sortable: true,
cell(props) {
const val = props.getValue() as unknown as RagQueryEvent["top_score"];
return <Show when={val}>{(score) => <div>{score()}</div>}</Show>;
},
},
{
accessorKey: "hallucination_score",
Expand Down
1 change: 1 addition & 0 deletions frontends/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ export interface RagQueryEvent {
note?: string;
rating: number;
};
top_score: number;
hallucination_score?: number;
detected_hallucinations?: string[];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE rag_queries DROP COLUMN IF EXISTS top_score;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE rag_queries ADD COLUMN IF NOT EXISTS top_score INT DEFAULT 0;
4 changes: 3 additions & 1 deletion server/src/data/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5106,7 +5106,7 @@ impl RagQueryEventClickhouse {
user_message: self.user_message,
search_id: uuid::Uuid::from_bytes(*self.search_id.as_bytes()),
results,
top_score: 0.0,
top_score: self.top_score,
query_rating,
dataset_id: uuid::Uuid::from_bytes(*self.dataset_id.as_bytes()),
llm_response: self.llm_response,
Expand All @@ -5128,6 +5128,7 @@ pub struct RagQueryEventClickhouse {
pub search_id: uuid::Uuid,
pub results: Vec<String>,
pub json_results: Vec<String>,
pub top_score: f32,
pub query_rating: String,
pub llm_response: String,
#[serde(with = "clickhouse::serde::uuid")]
Expand Down Expand Up @@ -5932,6 +5933,7 @@ impl EventTypes {
.collect(),
query_rating: serde_json::to_string(&query_rating).unwrap_or("".to_string()),
llm_response: llm_response.unwrap_or_default(),
top_score: 0.0,
dataset_id,
created_at: OffsetDateTime::now_utc(),
user_id: user_id.unwrap_or_default(),
Expand Down
2 changes: 2 additions & 0 deletions server/src/handlers/chunk_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2727,6 +2727,7 @@ pub async fn generate_off_chunks(
json.to_string()
})
.collect(),
top_score: 0.0,
user_message: format!("{} {}", rag_prompt, last_prev_message.content.clone()),
query_rating: String::new(),
rag_type: "chosen_chunks".to_string(),
Expand Down Expand Up @@ -2797,6 +2798,7 @@ pub async fn generate_off_chunks(
json.to_string()
})
.collect(),
top_score: 0.0,
user_message: format!("{} {}", rag_prompt, last_prev_message.content.clone()),
rag_type: "chosen_chunks".to_string(),
query_rating: String::new(),
Expand Down
16 changes: 9 additions & 7 deletions server/src/operators/message_operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ pub async fn get_rag_chunks_query(
pool: web::Data<Pool>,
redis_pool: web::Data<RedisPool>,
event_queue: web::Data<EventQueue>,
) -> Result<(uuid::Uuid, Vec<ChunkMetadataStringTagSet>), actix_web::Error> {
) -> Result<(SearchQueryEventClickhouse, Vec<ChunkMetadataStringTagSet>), actix_web::Error> {
let mut query =
if let Some(create_message_query) = create_message_req_payload.search_query.clone() {
create_message_query
Expand Down Expand Up @@ -440,7 +440,7 @@ pub async fn get_rag_chunks_query(
.await;
}
Ok((
clickhouse_search_event.id,
clickhouse_search_event,
result_groups
.group_chunks
.into_iter()
Expand Down Expand Up @@ -548,7 +548,7 @@ pub async fn get_rag_chunks_query(
.await;
}
Ok((
clickhouse_search_event.id,
clickhouse_search_event,
result_chunks
.score_chunks
.iter()
Expand Down Expand Up @@ -679,7 +679,7 @@ pub async fn stream_response(
let rag_prompt = dataset_config.RAG_PROMPT.clone();
let chosen_model = dataset_config.LLM_DEFAULT_MODEL.clone();

let (search_id, chunk_metadatas) = get_rag_chunks_query(
let (search_event, chunk_metadatas) = get_rag_chunks_query(
create_message_req_payload.clone(),
dataset_config.clone(),
dataset.clone(),
Expand All @@ -697,7 +697,7 @@ pub async fn stream_response(
Bytes::from(create_message_req_payload.no_result_message.unwrap()),
)]);
return Ok(HttpResponse::Ok()
.insert_header(("TR-QueryID", search_id.to_string()))
.insert_header(("TR-QueryID", search_event.id.to_string()))
.streaming(response_stream));
}

Expand Down Expand Up @@ -953,7 +953,8 @@ pub async fn stream_response(
id: query_id,
created_at: time::OffsetDateTime::now_utc(),
dataset_id: dataset.id,
search_id,
search_id: search_event.id,
top_score: search_event.top_score,
results: vec![],
json_results: chunk_data,
user_message: user_message_query.clone(),
Expand Down Expand Up @@ -1049,8 +1050,9 @@ pub async fn stream_response(
let clickhouse_rag_event = RagQueryEventClickhouse {
id: query_id_arb,
created_at: time::OffsetDateTime::now_utc(),
search_id: search_event.id,
top_score: search_event.top_score,
dataset_id: dataset.id,
search_id,
results: vec![],
json_results: chunk_data,
user_message: user_message_query.clone(),
Expand Down