synapse_core/ingest/
mod.rs1use anyhow::{Result, Context};
2use std::path::Path;
3use std::fs;
4use crate::store::SynapseStore;
5use std::sync::Arc;
6
7pub mod processor;
8pub mod extractor;
9
10use extractor::{Extractor, CsvExtractor, MarkdownExtractor};
11
12pub struct IngestionEngine {
13 store: Arc<SynapseStore>,
14}
15
16impl IngestionEngine {
17 pub fn new(store: Arc<SynapseStore>) -> Self {
18 Self { store }
19 }
20
21 pub async fn ingest_file(&self, path: &Path, _namespace: &str) -> Result<u32> {
22 let content = fs::read_to_string(path)
23 .with_context(|| format!("Failed to read file: {:?}", path))?;
24
25 let extension = path.extension()
26 .and_then(|s| s.to_str())
27 .unwrap_or("");
28
29 let result = match extension {
30 "csv" => CsvExtractor::new().extract(&content)?,
31 "md" | "markdown" => MarkdownExtractor.extract(&content)?,
32 _ => anyhow::bail!("Unsupported file type: {}", extension),
33 };
34
35 let (added, _) = self.store.ingest_triples(result.triples).await?;
36 Ok(added)
37 }
38}