use crate::{GraphRAG, Result};
use std::path::Path;
pub struct SimpleGraphRAG {
inner: GraphRAG,
}
impl SimpleGraphRAG {
pub fn from_text(text: &str) -> Result<Self> {
let inner = GraphRAG::from_text(text)?;
Ok(Self { inner })
}
pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self> {
let inner = GraphRAG::from_file(path)?;
Ok(Self { inner })
}
pub fn ask(&mut self, question: &str) -> Result<String> {
self.inner.ask(question)
}
pub fn add_text(&mut self, text: &str) -> Result<()> {
self.inner.add_document_from_text(text)
}
pub fn add_file<P: AsRef<Path>>(&mut self, path: P) -> Result<()> {
let text = std::fs::read_to_string(path)?;
self.add_text(&text)
}
pub fn is_ready(&self) -> bool {
self.inner.is_initialized() && self.inner.has_documents()
}
}