MCPcopy Create free account
hub / github.com/InfinitiBit/graphbit / load_document

Method load_document

core/src/document_loader.rs:78–110  ·  view source on GitHub ↗

Load and extract content from a document

(
        &self,
        source_path: &str,
        document_type: &str,
    )

Source from the content-addressed store, hash-verified

76
77 /// Load and extract content from a document
78 pub async fn load_document(
79 &self,
80 source_path: &str,
81 document_type: &str,
82 ) -> GraphBitResult<DocumentContent> {
83 // Validate document type
84 let supported_types = [
85 "pdf", "txt", "docx", "json", "csv", "xml", "html", "xlsb", "xlsx", "xls",
86 ];
87 if !supported_types.contains(&document_type.to_lowercase().as_str()) {
88 return Err(GraphBitError::validation(
89 "document_loader",
90 format!("Unsupported document type: {document_type}"),
91 ));
92 }
93
94 // Check if source is a URL or file path
95 let content = if source_path.starts_with("http://") || source_path.starts_with("https://") {
96 self.load_from_url(source_path, document_type).await?
97 } else if source_path.contains("://") {
98 // This looks like a URL but not HTTP/HTTPS
99 return Err(GraphBitError::validation(
100 "document_loader",
101 format!(
102 "Invalid URL format: {source_path}. Only HTTP and HTTPS URLs are supported"
103 ),
104 ));
105 } else {
106 self.load_from_file(source_path, document_type).await?
107 };
108
109 Ok(content)
110 }
111
112 /// Load document from file path
113 async fn load_from_file(

Calls 2

load_from_urlMethod · 0.80
load_from_fileMethod · 0.80