cognis_rag/loaders/
mod.rs1use async_trait::async_trait;
12use futures::Stream;
13
14use cognis_core::Result;
15
16use crate::document::Document;
17
18#[cfg(feature = "csv-loader")]
19pub mod csv_loader;
20pub mod directory;
21#[cfg(feature = "html-loader")]
22pub mod html;
23pub mod json;
24pub mod markdown;
25#[cfg(feature = "pdf-loader")]
26pub mod pdf;
27pub mod text;
28#[cfg(feature = "toml-loader")]
29pub mod toml_loader;
30#[cfg(feature = "web-loader")]
31pub mod web;
32#[cfg(feature = "yaml-loader")]
33pub mod yaml;
34
35#[cfg(feature = "csv-loader")]
36pub use csv_loader::CsvLoader;
37pub use directory::DirectoryLoader;
38#[cfg(feature = "html-loader")]
39pub use html::HtmlLoader;
40pub use json::JsonLoader;
41pub use markdown::MarkdownLoader;
42#[cfg(feature = "pdf-loader")]
43pub use pdf::PdfLoader;
44pub use text::TextLoader;
45#[cfg(feature = "toml-loader")]
46pub use toml_loader::TomlLoader;
47#[cfg(feature = "web-loader")]
48pub use web::WebLoader;
49#[cfg(feature = "yaml-loader")]
50pub use yaml::YamlLoader;
51
52#[async_trait]
57pub trait DocumentLoader: Send + Sync {
58 async fn load(&self) -> Result<DocumentStream>;
61
62 async fn load_all(&self) -> Result<Vec<Document>> {
64 use futures::StreamExt;
65 let mut s = self.load().await?;
66 let mut out = Vec::new();
67 while let Some(doc) = s.next().await {
68 out.push(doc?);
69 }
70 Ok(out)
71 }
72}
73
74pub type DocumentStream = std::pin::Pin<Box<dyn Stream<Item = Result<Document>> + Send>>;