Skip to content

Commit

Permalink
feat(ingestion_node): improved human readable Debug
Browse files Browse the repository at this point in the history
  • Loading branch information
timonv committed Jun 23, 2024
1 parent 2228d84 commit 4d5c68e
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion swiftide/src/ingestion/ingestion_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
//! need to be processed together.
use std::{
collections::HashMap,
fmt::Debug,
hash::{Hash, Hasher},
path::PathBuf,
};
Expand All @@ -30,7 +31,7 @@ use serde::{Deserialize, Serialize};
/// `IngestionNode` encapsulates all necessary information for a single unit of data being processed
/// in the ingestion pipeline. It includes fields for an identifier, file path, data chunk, optional
/// vector representation, and metadata.
#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq)]
#[derive(Default, Clone, Serialize, Deserialize, PartialEq)]
pub struct IngestionNode {
/// Optional identifier for the node.
pub id: Option<u64>,
Expand All @@ -44,6 +45,25 @@ pub struct IngestionNode {
pub metadata: HashMap<String, String>,
}

impl Debug for IngestionNode {
/// Formats the node for debugging purposes.
///
/// This method is used to provide a human-readable representation of the node when debugging.
/// The vector field is displayed as the number of elements in the vector if present.
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("IngestionNode")
.field("id", &self.id)
.field("path", &self.path)
.field("chunk", &self.chunk)
.field("metadata", &self.metadata)
.field(
"vector",
&self.vector.as_ref().map(|v| format!("[{}]", v.len())),
)
.finish()
}
}

impl IngestionNode {
/// Creates a new instance of `IngestionNode` with the specified data chunk.
///
Expand Down

0 comments on commit 4d5c68e

Please sign in to comment.