Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log top vector search results #461

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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::<Vec<_>>()
.join("\n")
),
);

Ok((final_nodes, first_intro_text))
}

Expand Down Expand Up @@ -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(),
);
Expand Down
19 changes: 7 additions & 12 deletions shinkai-bin/shinkai-node/src/llm_provider/parsing_helper.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {}

Expand All @@ -34,12 +28,13 @@ impl ParsingHelper {

let mut extracted_answer: Option<String> = 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
}
Expand Down
17 changes: 16 additions & 1 deletion shinkai-bin/shinkai-node/src/network/node_api_vecfs_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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,
Expand Down Expand Up @@ -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::<Vec<_>>()
.join("\n")
),
);

let _ = res.send(Ok(results)).await.map_err(|_| ());
Ok(())
}
Expand Down