docling_rag/source/
mod.rs1pub mod folder;
5
6#[cfg(feature = "remote-sources")]
7pub mod ftp;
8#[cfg(feature = "remote-sources")]
9pub mod sftp;
10
11use crate::config::SourceKind;
12#[cfg(not(feature = "remote-sources"))]
14use crate::RagError;
15use crate::{RagConfig, Result};
16use async_trait::async_trait;
17use std::sync::Arc;
18
19#[derive(Debug, Clone)]
21pub struct SourceRef {
22 pub uri: String,
24 pub name: String,
26 pub rel_path: String,
29}
30
31#[async_trait]
33pub trait DocumentSource: Send + Sync {
34 async fn list(&self) -> Result<Vec<SourceRef>>;
36
37 async fn fetch(&self, r: &SourceRef) -> Result<Vec<u8>>;
39}
40
41pub fn from_config(cfg: &RagConfig) -> Result<Arc<dyn DocumentSource>> {
43 match cfg.source {
44 SourceKind::Folder => Ok(Arc::new(folder::FolderSource::new(&cfg.source_path))),
45 SourceKind::Ftp => {
46 #[cfg(feature = "remote-sources")]
47 {
48 Ok(Arc::new(ftp::FtpSource::from_config(cfg)?))
49 }
50 #[cfg(not(feature = "remote-sources"))]
51 {
52 Err(RagError::FeatureDisabled(
53 "ftp".into(),
54 "remote-sources".into(),
55 ))
56 }
57 }
58 SourceKind::Sftp => {
59 #[cfg(feature = "remote-sources")]
60 {
61 Ok(Arc::new(sftp::SftpSource::from_config(cfg)?))
62 }
63 #[cfg(not(feature = "remote-sources"))]
64 {
65 Err(RagError::FeatureDisabled(
66 "sftp".into(),
67 "remote-sources".into(),
68 ))
69 }
70 }
71 }
72}