pub struct Document {
pub page_content: String,
pub metadata: HashMap<String, Value>,
}
Expand description
A document represents a piece of text with associated metadata
Fields§
§page_content: String
The text content of the document
metadata: HashMap<String, Value>
Metadata associated with the document
Implementations§
Source§impl Document
impl Document
Sourcepub fn new(page_content: impl Into<String>) -> Self
pub fn new(page_content: impl Into<String>) -> Self
Create a new document with the given content
Sourcepub fn new_with_metadata(
page_content: impl Into<String>,
metadata: HashMap<String, Value>,
) -> Self
pub fn new_with_metadata( page_content: impl Into<String>, metadata: HashMap<String, Value>, ) -> Self
Create a new document with content and metadata
Sourcepub fn add_metadata(&mut self, key: impl Into<String>, value: Value)
pub fn add_metadata(&mut self, key: impl Into<String>, value: Value)
Add metadata to the document
Sourcepub fn get_metadata(&self, key: &str) -> Option<&Value>
pub fn get_metadata(&self, key: &str) -> Option<&Value>
Get metadata value by key
Sourcepub fn get_metadata_string(&self, key: &str) -> Option<String>
pub fn get_metadata_string(&self, key: &str) -> Option<String>
Get metadata value as a string
Sourcepub fn get_metadata_number(&self, key: &str) -> Option<f64>
pub fn get_metadata_number(&self, key: &str) -> Option<f64>
Get metadata value as a number
Sourcepub fn get_metadata_bool(&self, key: &str) -> Option<bool>
pub fn get_metadata_bool(&self, key: &str) -> Option<bool>
Get metadata value as a boolean
Sourcepub fn has_metadata(&self, key: &str) -> bool
pub fn has_metadata(&self, key: &str) -> bool
Check if the document has a specific metadata key
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Document
impl<'de> Deserialize<'de> for Document
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Serializable for Document
impl Serializable for Document
Source§fn is_serializable() -> bool
fn is_serializable() -> bool
Check if this object is serializable Read more
Source§fn to_json_pretty(&self) -> Result<String>
fn to_json_pretty(&self) -> Result<String>
Serialize this object to a pretty-printed JSON string
Source§fn to_dict(&self) -> Result<HashMap<String, Value>>
fn to_dict(&self) -> Result<HashMap<String, Value>>
Serialize this object to a dictionary (HashMap)
Source§impl ToDocument for Document
impl ToDocument for Document
Source§fn to_document(&self) -> Document
fn to_document(&self) -> Document
Convert this object to a document
impl StructuralPartialEq for Document
Auto Trait Implementations§
impl Freeze for Document
impl RefUnwindSafe for Document
impl Send for Document
impl Sync for Document
impl Unpin for Document
impl UnwindSafe for Document
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more