diff --git a/swiftide/src/integrations/qdrant/ingestion_node.rs b/swiftide/src/integrations/qdrant/ingestion_node.rs index 3cf67a5a..840c8c48 100644 --- a/swiftide/src/integrations/qdrant/ingestion_node.rs +++ b/swiftide/src/integrations/qdrant/ingestion_node.rs @@ -1,3 +1,8 @@ +//! This module provides functionality to convert an `IngestionNode` into a `qdrant::PointStruct`. +//! The conversion is essential for storing data in the Qdrant vector database, which is used +//! for efficient vector similarity search. The module handles metadata augmentation and ensures +//! data compatibility with Qdrant's required format. + use anyhow::{Context as _, Result}; use std::collections::HashMap; @@ -7,12 +12,26 @@ use qdrant_client::{ qdrant::{self, Value}, }; +/// Implements the `TryInto` trait to convert an `IngestionNode` into a `qdrant::PointStruct`. +/// This conversion is necessary for storing the node in the Qdrant vector database. impl TryInto for IngestionNode { type Error = anyhow::Error; + /// Converts the `IngestionNode` into a `qdrant::PointStruct`. + /// + /// # Errors + /// + /// Returns an error if the vector is not set in the `IngestionNode`. + /// + /// # Returns + /// + /// A `Result` which is `Ok` if the conversion is successful, containing the `qdrant::PointStruct`. + /// If the conversion fails, it returns an `anyhow::Error`. fn try_into(mut self) -> Result { + // Calculate a unique identifier for the node. let id = self.calculate_hash(); + // Extend the metadata with additional information. self.metadata.extend([ ("path".to_string(), self.path.to_string_lossy().to_string()), ("content".to_string(), self.chunk), @@ -22,7 +41,7 @@ impl TryInto for IngestionNode { ), ]); - // Damn who build this api + // Create a payload compatible with Qdrant's API. let payload: Payload = self .metadata .iter() @@ -30,6 +49,7 @@ impl TryInto for IngestionNode { .collect::>() .into(); + // Construct the `qdrant::PointStruct` and return it. Ok(qdrant::PointStruct::new( id, self.vector.context("Vector is not set")?,