pub struct Document {
pub page_content: String,
pub id: Option<String>,
pub metadata: HashMap<String, Value>,
pub type_: String,
}Expand description
Class for storing a piece of text and associated metadata.
Document is for retrieval workflows, not chat I/O. For sending text
to an LLM in a conversation, use message types from the messages module.
§Example
use agent_chain_core::documents::Document;
use std::collections::HashMap;
let document = Document::new("Hello, world!")
.with_metadata(HashMap::from([
("source".to_string(), serde_json::json!("https://example.com"))
]));Fields§
§page_content: StringString text content of the document.
id: Option<String>An optional identifier for the document.
Ideally this should be unique across the document collection and formatted as a UUID, but this will not be enforced.
metadata: HashMap<String, Value>Arbitrary metadata associated with the content.
type_: StringType identifier, always “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 page content.
Sourcepub fn with_metadata(self, metadata: HashMap<String, Value>) -> Self
pub fn with_metadata(self, metadata: HashMap<String, Value>) -> Self
Set the metadata.
Sourcepub fn with_metadata_entry(self, key: impl Into<String>, value: Value) -> Self
pub fn with_metadata_entry(self, key: impl Into<String>, value: Value) -> Self
Add a single metadata entry.
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 get_lc_namespace() -> Vec<String>where
Self: Sized,
fn get_lc_namespace() -> Vec<String>where
Self: Sized,
Get the namespace of the LangChain object. Read more
Source§fn lc_secrets(&self) -> HashMap<String, String>
fn lc_secrets(&self) -> HashMap<String, String>
A map of constructor argument names to secret ids. Read more
Source§fn lc_attributes(&self) -> HashMap<String, Value>
fn lc_attributes(&self) -> HashMap<String, Value>
List of attribute names that should be included in the serialized kwargs. Read more
Source§fn lc_id() -> Vec<String>where
Self: Sized,
fn lc_id() -> Vec<String>where
Self: Sized,
Return a unique identifier for this class for serialization purposes. Read more
Source§fn lc_type_name(&self) -> &'static str
fn lc_type_name(&self) -> &'static str
Get the type name of this object.
Source§fn to_json(&self) -> Serialized
fn to_json(&self) -> Serialized
Serialize this object to JSON. Read more
Source§fn to_json_not_implemented(&self) -> Serialized
fn to_json_not_implemented(&self) -> Serialized
Serialize a “not implemented” object.
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
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> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.