pub struct Document {
pub id: Uuid,
pub doc_type: DocumentType,
pub source: Source,
pub content: DocumentContent,
pub metadata: Metadata,
pub processing: ProcessingStatus,
pub chunks: Vec<Chunk>,
pub created_at: DateTime<Utc>,
pub updated_at: Option<DateTime<Utc>>,
}Expand description
A document in the knowledge base.
The primary data structure for storing and managing documents. Contains content, metadata, processing status, and chunks.
§Example
use reasonkit::{Document, DocumentType, Source, SourceType};
use chrono::Utc;
let source = Source {
source_type: SourceType::Local,
url: None,
path: Some("/path/to/doc.md".to_string()),
arxiv_id: None,
github_repo: None,
retrieved_at: Utc::now(),
version: None,
};
let doc = Document::new(DocumentType::Documentation, source)
.with_content("# My Document\n\nContent here...".to_string());
assert_eq!(doc.doc_type, DocumentType::Documentation);
assert!(doc.content.word_count > 0);Fields§
§id: UuidUnique document identifier
doc_type: DocumentTypeDocument type categorization
source: SourceSource information for provenance
content: DocumentContentDocument content
metadata: MetadataDocument metadata
processing: ProcessingStatusProcessing status
chunks: Vec<Chunk>Text chunks for retrieval
created_at: DateTime<Utc>Creation timestamp
updated_at: Option<DateTime<Utc>>Last update timestamp
Implementations§
Source§impl Document
impl Document
Sourcepub fn new(doc_type: DocumentType, source: Source) -> Self
pub fn new(doc_type: DocumentType, source: Source) -> Self
Create a new document with the given type and source.
§Arguments
doc_type- The type of documentsource- Source information for provenance
§Example
use reasonkit::{Document, DocumentType, Source, SourceType};
use chrono::Utc;
let source = Source {
source_type: SourceType::Local,
url: None,
path: Some("/path/to/file.txt".to_string()),
arxiv_id: None,
github_repo: None,
retrieved_at: Utc::now(),
version: None,
};
let doc = Document::new(DocumentType::Note, source);
assert_eq!(doc.doc_type, DocumentType::Note);Sourcepub fn with_content(self, raw: String) -> Self
pub fn with_content(self, raw: String) -> Self
Set the document content and compute statistics.
§Arguments
raw- The raw content string
§Example
use reasonkit::{Document, DocumentType, Source, SourceType};
use chrono::Utc;
let source = Source {
source_type: SourceType::Local,
url: None,
path: None,
arxiv_id: None,
github_repo: None,
retrieved_at: Utc::now(),
version: None,
};
let doc = Document::new(DocumentType::Note, source)
.with_content("Hello world".to_string());
assert_eq!(doc.content.word_count, 2);
assert_eq!(doc.content.char_count, 11);Sourcepub fn with_metadata(self, metadata: Metadata) -> Self
pub fn with_metadata(self, metadata: Metadata) -> Self
Set the document metadata.
§Arguments
metadata- The metadata to set
§Example
use reasonkit::{Document, DocumentType, Source, SourceType, Metadata};
use chrono::Utc;
let source = Source {
source_type: SourceType::Local,
url: None,
path: None,
arxiv_id: None,
github_repo: None,
retrieved_at: Utc::now(),
version: None,
};
let metadata = Metadata {
title: Some("My Document".to_string()),
..Default::default()
};
let doc = Document::new(DocumentType::Note, source)
.with_metadata(metadata);
assert_eq!(doc.metadata.title, Some("My Document".to_string()));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