diff --git a/shinkai-bin/shinkai-node/src/llm_provider/execution/job_vector_search.rs b/shinkai-bin/shinkai-node/src/llm_provider/execution/job_vector_search.rs index 39b171fc2..fe3018ce8 100644 --- a/shinkai-bin/shinkai-node/src/llm_provider/execution/job_vector_search.rs +++ b/shinkai-bin/shinkai-node/src/llm_provider/execution/job_vector_search.rs @@ -1,6 +1,6 @@ -use crate::llm_provider::job_manager::JobManager; use crate::db::db_errors::ShinkaiDBError; use crate::db::ShinkaiDB; +use crate::llm_provider::job_manager::JobManager; use crate::vector_fs::vector_fs::VectorFS; use keyphrases::KeyPhraseExtractor; use shinkai_message_primitives::schemas::shinkai_name::ShinkaiName; @@ -16,7 +16,6 @@ use std::collections::HashMap; use std::result::Result::Ok; use std::sync::Arc; - impl JobManager { /// Performs multiple proximity vector searches within the job scope based on extracting keywords from the query text. /// Attempts to take at least 1 proximity group per keyword that is from a VR different than the highest scored node, to encourage wider diversity in results. @@ -181,6 +180,24 @@ impl JobManager { // eprintln!("{:?} - {:?}\n", node.score as f32, node.format_for_prompt(3500)); // } + shinkai_log( + ShinkaiLogOption::JobExecution, + ShinkaiLogLevel::Debug, + &format!( + "Top 5 search results:\n{}", + final_nodes + .iter() + .take(5) + .map(|node| format!( + "score: {}, text: {}\n", + node.score, + node.node.get_text_content().unwrap_or("") + )) + .collect::>() + .join("\n") + ), + ); + Ok((final_nodes, first_intro_text)) } @@ -375,11 +392,7 @@ impl JobManager { ret_node.score = deep_search_scores_average_out( None, resource_score, - resource - .as_trait_object() - .description() - .unwrap_or("") - .to_string(), + resource.as_trait_object().description().unwrap_or("").to_string(), ret_node.score, ret_node.node.get_text_content().unwrap_or("").to_string(), ); diff --git a/shinkai-bin/shinkai-node/src/llm_provider/parsing_helper.rs b/shinkai-bin/shinkai-node/src/llm_provider/parsing_helper.rs index d48bdce1c..cd4940d31 100644 --- a/shinkai-bin/shinkai-node/src/llm_provider/parsing_helper.rs +++ b/shinkai-bin/shinkai-node/src/llm_provider/parsing_helper.rs @@ -1,12 +1,8 @@ -use crate::network::ws_manager::WSUpdateHandler; - use super::error::LLMProviderError; -use super::execution::chains::inference_chain_trait::LLMInferenceResponse; use super::execution::prompts::prompts::JobPromptGenerator; use super::execution::user_message_parser::{JobTaskElement, ParsedUserMessage}; use super::job_manager::JobManager; use regex::Regex; -use serde_json::Value as JsonValue; use shinkai_message_primitives::schemas::llm_providers::serialized_llm_provider::SerializedLLMProvider; use shinkai_message_primitives::shinkai_utils::shinkai_logging::{shinkai_log, ShinkaiLogLevel, ShinkaiLogOption}; use shinkai_vector_resources::embedding_generator::EmbeddingGenerator; @@ -16,9 +12,7 @@ use shinkai_vector_resources::file_parser::unstructured_api::UnstructuredAPI; use shinkai_vector_resources::source::{DistributionInfo, SourceFile, SourceFileMap, TextChunkingStrategy}; use shinkai_vector_resources::vector_resource::{BaseVectorResource, SourceFileType, VRKai, VRPath}; use shinkai_vector_resources::{data_tags::DataTag, source::VRSourceReference}; -use tokio::sync::Mutex; use std::collections::HashMap; -use std::sync::Arc; pub struct ParsingHelper {} @@ -34,12 +28,13 @@ impl ParsingHelper { let mut extracted_answer: Option = None; for _ in 0..5 { - let response_json = match JobManager::inference_with_llm_provider(agent.clone(), prompt.clone(), None, None).await { - Ok(json) => json, - Err(_e) => { - continue; // Continue to the next iteration on error - } - }; + let response_json = + match JobManager::inference_with_llm_provider(agent.clone(), prompt.clone(), None, None).await { + Ok(json) => json, + Err(_e) => { + continue; // Continue to the next iteration on error + } + }; extracted_answer = Some(response_json.response_string); break; // Exit the loop if successful } diff --git a/shinkai-bin/shinkai-node/src/network/node_api_vecfs_commands.rs b/shinkai-bin/shinkai-node/src/network/node_api_vecfs_commands.rs index b1154f068..97eb8b4f9 100644 --- a/shinkai-bin/shinkai-node/src/network/node_api_vecfs_commands.rs +++ b/shinkai-bin/shinkai-node/src/network/node_api_vecfs_commands.rs @@ -5,7 +5,7 @@ use super::{ subscription_manager::external_subscriber_manager::ExternalSubscriberManager, Node, }; use crate::{ - llm_provider::parsing_helper::ParsingHelper, db::ShinkaiDB, managers::IdentityManager, + db::ShinkaiDB, llm_provider::parsing_helper::ParsingHelper, managers::IdentityManager, network::subscription_manager::external_subscriber_manager::SharedFolderInfo, schemas::identity::Identity, vector_fs::vector_fs::VectorFS, }; @@ -24,6 +24,7 @@ use shinkai_message_primitives::{ APIVecFsRetrieveVectorSearchSimplifiedJson, APIVecFsSearchItems, MessageSchemaType, }, }, + shinkai_utils::shinkai_logging::{shinkai_log, ShinkaiLogLevel, ShinkaiLogOption}, }; use shinkai_vector_resources::{ embedding_generator::EmbeddingGenerator, @@ -435,6 +436,20 @@ impl Node { }) .collect(); + shinkai_log( + ShinkaiLogOption::JobExecution, + ShinkaiLogLevel::Debug, + &format!( + "Top 5 search results:\n{}", + results + .iter() + .take(5) + .map(|(text, _, score)| format!("score: {}, text: {}\n", score, text)) + .collect::>() + .join("\n") + ), + ); + let _ = res.send(Ok(results)).await.map_err(|_| ()); Ok(()) }