Skip to content

Commit

Permalink
bugfix: revert rag top score inclusion
Browse files Browse the repository at this point in the history
  • Loading branch information
skeptrunedev committed Dec 16, 2024
1 parent 6483310 commit e3b9d8c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
6 changes: 3 additions & 3 deletions server/src/data/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5068,7 +5068,7 @@ impl From<String> for ClickhouseRagTypes {
}

impl RagQueryEventClickhouse {
pub async fn from_clickhouse(self, pool: web::Data<Pool>, top_score: f32) -> RagQueryEvent {
pub async fn from_clickhouse(self, pool: web::Data<Pool>) -> RagQueryEvent {
let chunk_ids = self
.results
.iter()
Expand Down 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,
top_score: 0.0,
query_rating,
dataset_id: uuid::Uuid::from_bytes(*self.dataset_id.as_bytes()),
llm_response: self.llm_response,
Expand Down Expand Up @@ -6518,7 +6518,7 @@ pub enum RAGAnalyticsResponse {
#[schema(title = "RAGUsageGraph")]
RAGUsageGraph(RAGUsageGraphResponse),
#[schema(title = "RAGQueryDetails")]
RAGQueryDetails(RagQueryEvent),
RAGQueryDetails(Box<RagQueryEvent>),
}

#[derive(Debug, Serialize, Deserialize, ToSchema)]
Expand Down
2 changes: 1 addition & 1 deletion server/src/handlers/analytics_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ pub async fn get_rag_analytics(
clickhouse_client.get_ref(),
)
.await?;
RAGAnalyticsResponse::RAGQueryDetails(rag_query)
RAGAnalyticsResponse::RAGQueryDetails(Box::new(rag_query))
}
};

Expand Down
20 changes: 6 additions & 14 deletions server/src/operators/analytics_operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -752,10 +752,8 @@ pub async fn get_rag_queries_query(
let mut query_string = String::from(
"SELECT
?fields,
top_score,
FROM
rag_queries
JOIN search_queries ON rag_queries.search_id = search_queries.id
WHERE dataset_id = ?",
);

Expand All @@ -777,7 +775,7 @@ pub async fn get_rag_queries_query(
.query(query_string.as_str())
.bind(dataset_id)
.bind((page.unwrap_or(1) - 1) * 10)
.fetch_all::<(RagQueryEventClickhouse, f32)>()
.fetch_all::<RagQueryEventClickhouse>()
.await
.map_err(|e| {
log::error!("Error fetching query: {:?}", e);
Expand All @@ -787,7 +785,7 @@ pub async fn get_rag_queries_query(
let queries: Vec<RagQueryEvent> = join_all(
clickhouse_query
.into_iter()
.map(|(q, score)| q.from_clickhouse(pool.clone(), score)),
.map(|q| q.from_clickhouse(pool.clone())),
)
.await;

Expand Down Expand Up @@ -890,24 +888,18 @@ pub async fn get_rag_query(
pool: web::Data<Pool>,
clickhouse_client: &clickhouse::Client,
) -> Result<RagQueryEvent, ServiceError> {
let (clickhouse_query, top_score) = clickhouse_client
.query(
"SELECT ?fields, top_score FROM rag_queries
JOIN search_queries ON rag_queries.search_id = search_queries.id
WHERE id = ? AND dataset_id = ?",
)
let clickhouse_query = clickhouse_client
.query("SELECT ?fields FROM rag_queries WHERE id = ? AND dataset_id = ?")
.bind(request_id)
.bind(dataset_id)
.fetch_one::<(RagQueryEventClickhouse, f32)>()
.fetch_one::<RagQueryEventClickhouse>()
.await
.map_err(|e| {
log::error!("Error fetching query: {:?}", e);
ServiceError::InternalServerError("Error fetching query".to_string())
})?;

let query: RagQueryEvent = clickhouse_query
.from_clickhouse(pool.clone(), top_score)
.await;
let query: RagQueryEvent = clickhouse_query.from_clickhouse(pool.clone()).await;

Ok(query)
}
Expand Down

0 comments on commit e3b9d8c

Please sign in to comment.