#![allow(unused_imports)]
use crate::config::Config;
use crate::core::{
ChunkId, Document, DocumentId, Entity, EntityId, GraphRAGError, KnowledgeGraph, Relationship,
Result, TextChunk,
};
use crate::{critic, ollama, persistence, query, retrieval};
#[cfg(feature = "parallel-processing")]
#[allow(unused_imports)]
use crate::parallel;
use super::GraphRAG;
impl GraphRAG {
pub fn add_document_from_text(&mut self, text: &str) -> Result<()> {
use crate::text::TextProcessor;
use indexmap::IndexMap;
let doc_id = DocumentId::new(format!("doc_{}", uuid::Uuid::new_v4().simple()));
let document = Document {
id: doc_id,
title: "Document".to_string(),
content: text.to_string(),
metadata: IndexMap::new(),
chunks: Vec::new(),
};
let text_processor =
TextProcessor::new(self.config.text.chunk_size, self.config.text.chunk_overlap)?;
let chunks = text_processor.chunk_text(&document)?;
let document_with_chunks = Document { chunks, ..document };
self.add_document(document_with_chunks)
}
pub fn add_document(&mut self, document: Document) -> Result<()> {
let graph = self
.knowledge_graph
.as_mut()
.ok_or_else(|| GraphRAGError::Config {
message: "Knowledge graph not initialized".to_string(),
})?;
graph.add_document(document)
}
}