wip: node relationships and improved prompt

This commit is contained in:
Per Stark
2025-02-01 17:56:32 +01:00
parent 76e52f0fff
commit 593e98e1e2
10 changed files with 121 additions and 35 deletions

View File

@@ -1,7 +1,7 @@
use serde_json::{json, Value};
pub static INGRESS_ANALYSIS_SYSTEM_MESSAGE: &str = r#"
You are an expert document analyzer. You will receive a document's text content, along with user instructions and a category. Your task is to provide a structured JSON object representing the content in a graph format suitable for a graph database. You will also be presented with some existing knowledge_entities from the database, do not replicate these!
You are an AI assistant. You will receive a text content, along with user instructions and a category. Your task is to provide a structured JSON object representing the content in a graph format suitable for a graph database. You will also be presented with some existing knowledge_entities from the database, do not replicate these! Your task is to create meaningful knowledge entities from the submitted content. Try and infer as much as possible from the users instructions and category when creating these. If the user submits a large content, create more general entities. If the user submits a narrow and precise content, try and create precise knowledge entities.
The JSON should have the following structure:

View File

@@ -66,7 +66,7 @@ impl LLMGraphAnalysisResult {
.await?;
// Process relationships
let relationships = self.process_relationships(source_id, Arc::clone(&mapper))?;
let relationships = self.process_relationships(source_id, user_id, Arc::clone(&mapper))?;
Ok((entities, relationships))
}
@@ -117,6 +117,7 @@ impl LLMGraphAnalysisResult {
fn process_relationships(
&self,
source_id: &str,
user_id: &str,
mapper: Arc<Mutex<GraphMapper>>,
) -> Result<Vec<KnowledgeRelationship>, AppError> {
let mut mapper_guard = mapper
@@ -131,9 +132,9 @@ impl LLMGraphAnalysisResult {
Ok(KnowledgeRelationship::new(
source_db_id.to_string(),
target_db_id.to_string(),
user_id.to_string(),
source_id.to_string(),
rel.type_.clone(),
None,
))
})
.collect()