pub struct Document {
pub page_content: String,
pub metadata: HashMap<String, Value>,
pub score: f64,
}
Expand description
The Document
struct represents a document with content, metadata, and a score.
The page_content
field is a string that contains the content of the document.
The metadata
field is a HashMap
where the keys represent metadata properties and the values represent property values.
The score
field represents a relevance score for the document and is a floating point number.
§Usage
ⓘ
let my_doc = Document::new("This is the document content.".to_string())
.with_metadata({
let mut metadata = HashMap::new();
metadata.insert("author".to_string(), json!("John Doe"));
metadata
})
.with_score(0.75);
Fields§
§page_content: String
§metadata: HashMap<String, Value>
§score: f64
Implementations§
Source§impl Document
impl Document
Sourcepub fn new<S: Into<String>>(page_content: S) -> Self
pub fn new<S: Into<String>>(page_content: S) -> Self
Constructs a new Document
with provided page_content
, an empty metadata
map and a score
of 0.
Sourcepub fn with_metadata(self, metadata: HashMap<String, Value>) -> Self
pub fn with_metadata(self, metadata: HashMap<String, Value>) -> Self
Sets the metadata
Map of the Document
to the provided HashMap.
Sourcepub fn with_score(self, score: f64) -> Self
pub fn with_score(self, score: f64) -> Self
Sets the score
of the Document
to the provided float.
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
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more