Encode a `GraphRagResponse` from RRF-fused results. Shared by both 2-source (`execute_graph_rag_fusion`) and 3-source (`execute_graph_rag_fusion_triple`) fusion pipelines.
(
&self,
task: &ExecutionTask,
p: RagResponseParams<'_>,
)
| 182 | /// Shared by both 2-source (`execute_graph_rag_fusion`) and 3-source |
| 183 | /// (`execute_graph_rag_fusion_triple`) fusion pipelines. |
| 184 | pub(in crate::data::executor) fn build_rag_response( |
| 185 | &self, |
| 186 | task: &ExecutionTask, |
| 187 | p: RagResponseParams<'_>, |
| 188 | ) -> Response { |
| 189 | let results: Vec<GraphRagResult> = p |
| 190 | .fused |
| 191 | .iter() |
| 192 | .map(|f| { |
| 193 | let (vector_rank, vector_distance) = p |
| 194 | .vector_scores |
| 195 | .get(f.document_id.as_str()) |
| 196 | .map(|(rank, dist)| (Some(*rank), Some(*dist))) |
| 197 | .unwrap_or((None, None)); |
| 198 | let hop_distance = p.hop_distances.get(f.document_id.as_str()).copied(); |
| 199 | GraphRagResult { |
| 200 | node_id: f.document_id.clone(), |
| 201 | rrf_score: f.rrf_score, |
| 202 | vector_rank, |
| 203 | vector_distance, |
| 204 | hop_distance, |
| 205 | } |
| 206 | }) |
| 207 | .collect(); |
| 208 | |
| 209 | let response_body = GraphRagResponse { |
| 210 | results, |
| 211 | metadata: GraphRagMetadata { |
| 212 | vector_candidates: p.vector_candidate_count, |
| 213 | graph_expanded: p.graph_expanded_count, |
| 214 | truncated: p.bfs_truncated, |
| 215 | watermark_lsn: self.watermark.as_u64(), |
| 216 | }, |
| 217 | }; |
| 218 | |
| 219 | match encode(&response_body) { |
| 220 | Ok(payload) => self.response_with_payload(task, payload), |
| 221 | Err(e) => { |
| 222 | warn!(core = self.core_id, error = %e, "{} serialization failed", p.op_name); |
| 223 | self.response_error( |
| 224 | task, |
| 225 | ErrorCode::Internal { |
| 226 | detail: e.to_string(), |
| 227 | }, |
| 228 | ) |
| 229 | } |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | /// BFS traversal that also tracks hop distances from start nodes. |
| 234 | pub(in crate::data::executor) fn bfs_with_distances( |
no test coverage detected