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