synapse_core/ingest/
mod.rs1use crate::store::SynapseStore;
2use anyhow::{Context, Result};
3use std::fs;
4use std::path::Path;
5use std::sync::Arc;
6
7pub mod extractor;
8pub mod processor;
9
10use extractor::{CsvExtractor, Extractor, 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 =
23 fs::read_to_string(path).with_context(|| format!("Failed to read file: {:?}", path))?;
24
25 let extension = path.extension().and_then(|s| s.to_str()).unwrap_or("");
26
27 let result = match extension {
28 "csv" => CsvExtractor::new().extract(&content)?,
29 "md" | "markdown" => MarkdownExtractor.extract(&content)?,
30 _ => anyhow::bail!("Unsupported file type: {}", extension),
31 };
32
33 let (added, _) = self.store.ingest_triples(result.triples).await?;
34 Ok(added)
35 }
36}