2025-11-26 22:54:22 -03:00
|
|
|
use anyhow::{Context, Result};
|
Fix tasks UI, WebSocket progress, memory monitoring, and app generator
Tasks UI fixes:
- Fix task list to query auto_tasks table instead of tasks table
- Fix task detail endpoint to use UUID binding for auto_tasks query
- Add proper filter handling: complete, active, awaiting, paused, blocked
- Add TaskStats fields: awaiting, paused, blocked, time_saved
- Add /api/tasks/time-saved endpoint
- Add count-all to stats HTML response
App generator improvements:
- Add AgentActivity struct for detailed terminal-style progress
- Add emit_activity method for rich progress events
- Add detailed logging for LLM calls with timing
- Track files_written, tables_synced, bytes_generated
Memory and performance:
- Add memory_monitor module for tracking RSS and thread activity
- Skip 0-byte files in drive monitor and document processor
- Change DRIVE_MONITOR checking logs from info to trace
- Remove unused profile_section macro
WebSocket progress:
- Ensure TaskProgressEvent includes activity field
- Add with_activity builder method
2025-12-30 22:42:32 -03:00
|
|
|
use log::{info, trace, warn};
|
2025-11-26 22:54:22 -03:00
|
|
|
use reqwest::Client;
|
|
|
|
|
use serde::{Deserialize, Serialize};
|
Fix tasks UI, WebSocket progress, memory monitoring, and app generator
Tasks UI fixes:
- Fix task list to query auto_tasks table instead of tasks table
- Fix task detail endpoint to use UUID binding for auto_tasks query
- Add proper filter handling: complete, active, awaiting, paused, blocked
- Add TaskStats fields: awaiting, paused, blocked, time_saved
- Add /api/tasks/time-saved endpoint
- Add count-all to stats HTML response
App generator improvements:
- Add AgentActivity struct for detailed terminal-style progress
- Add emit_activity method for rich progress events
- Add detailed logging for LLM calls with timing
- Track files_written, tables_synced, bytes_generated
Memory and performance:
- Add memory_monitor module for tracking RSS and thread activity
- Skip 0-byte files in drive monitor and document processor
- Change DRIVE_MONITOR checking logs from info to trace
- Remove unused profile_section macro
WebSocket progress:
- Ensure TaskProgressEvent includes activity field
- Add with_activity builder method
2025-12-30 22:42:32 -03:00
|
|
|
use std::sync::atomic::{AtomicBool, Ordering};
|
2025-11-26 22:54:22 -03:00
|
|
|
use std::sync::Arc;
|
Fix tasks UI, WebSocket progress, memory monitoring, and app generator
Tasks UI fixes:
- Fix task list to query auto_tasks table instead of tasks table
- Fix task detail endpoint to use UUID binding for auto_tasks query
- Add proper filter handling: complete, active, awaiting, paused, blocked
- Add TaskStats fields: awaiting, paused, blocked, time_saved
- Add /api/tasks/time-saved endpoint
- Add count-all to stats HTML response
App generator improvements:
- Add AgentActivity struct for detailed terminal-style progress
- Add emit_activity method for rich progress events
- Add detailed logging for LLM calls with timing
- Track files_written, tables_synced, bytes_generated
Memory and performance:
- Add memory_monitor module for tracking RSS and thread activity
- Skip 0-byte files in drive monitor and document processor
- Change DRIVE_MONITOR checking logs from info to trace
- Remove unused profile_section macro
WebSocket progress:
- Ensure TaskProgressEvent includes activity field
- Add with_activity builder method
2025-12-30 22:42:32 -03:00
|
|
|
use std::time::Duration;
|
2025-11-26 22:54:22 -03:00
|
|
|
use tokio::sync::Semaphore;
|
|
|
|
|
|
Fix tasks UI, WebSocket progress, memory monitoring, and app generator
Tasks UI fixes:
- Fix task list to query auto_tasks table instead of tasks table
- Fix task detail endpoint to use UUID binding for auto_tasks query
- Add proper filter handling: complete, active, awaiting, paused, blocked
- Add TaskStats fields: awaiting, paused, blocked, time_saved
- Add /api/tasks/time-saved endpoint
- Add count-all to stats HTML response
App generator improvements:
- Add AgentActivity struct for detailed terminal-style progress
- Add emit_activity method for rich progress events
- Add detailed logging for LLM calls with timing
- Track files_written, tables_synced, bytes_generated
Memory and performance:
- Add memory_monitor module for tracking RSS and thread activity
- Skip 0-byte files in drive monitor and document processor
- Change DRIVE_MONITOR checking logs from info to trace
- Remove unused profile_section macro
WebSocket progress:
- Ensure TaskProgressEvent includes activity field
- Add with_activity builder method
2025-12-30 22:42:32 -03:00
|
|
|
use crate::core::shared::memory_monitor::{log_jemalloc_stats, MemoryStats};
|
2025-11-26 22:54:22 -03:00
|
|
|
use super::document_processor::TextChunk;
|
|
|
|
|
|
Fix tasks UI, WebSocket progress, memory monitoring, and app generator
Tasks UI fixes:
- Fix task list to query auto_tasks table instead of tasks table
- Fix task detail endpoint to use UUID binding for auto_tasks query
- Add proper filter handling: complete, active, awaiting, paused, blocked
- Add TaskStats fields: awaiting, paused, blocked, time_saved
- Add /api/tasks/time-saved endpoint
- Add count-all to stats HTML response
App generator improvements:
- Add AgentActivity struct for detailed terminal-style progress
- Add emit_activity method for rich progress events
- Add detailed logging for LLM calls with timing
- Track files_written, tables_synced, bytes_generated
Memory and performance:
- Add memory_monitor module for tracking RSS and thread activity
- Skip 0-byte files in drive monitor and document processor
- Change DRIVE_MONITOR checking logs from info to trace
- Remove unused profile_section macro
WebSocket progress:
- Ensure TaskProgressEvent includes activity field
- Add with_activity builder method
2025-12-30 22:42:32 -03:00
|
|
|
static EMBEDDING_SERVER_READY: AtomicBool = AtomicBool::new(false);
|
|
|
|
|
|
|
|
|
|
pub fn is_embedding_server_ready() -> bool {
|
|
|
|
|
EMBEDDING_SERVER_READY.load(Ordering::SeqCst)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn set_embedding_server_ready(ready: bool) {
|
|
|
|
|
EMBEDDING_SERVER_READY.store(ready, Ordering::SeqCst);
|
|
|
|
|
if ready {
|
|
|
|
|
info!("[EMBEDDING] Embedding server marked as ready");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-26 22:54:22 -03:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub struct EmbeddingConfig {
|
|
|
|
|
pub embedding_url: String,
|
|
|
|
|
pub embedding_model: String,
|
|
|
|
|
pub dimensions: usize,
|
|
|
|
|
pub batch_size: usize,
|
|
|
|
|
pub timeout_seconds: u64,
|
Fix tasks UI, WebSocket progress, memory monitoring, and app generator
Tasks UI fixes:
- Fix task list to query auto_tasks table instead of tasks table
- Fix task detail endpoint to use UUID binding for auto_tasks query
- Add proper filter handling: complete, active, awaiting, paused, blocked
- Add TaskStats fields: awaiting, paused, blocked, time_saved
- Add /api/tasks/time-saved endpoint
- Add count-all to stats HTML response
App generator improvements:
- Add AgentActivity struct for detailed terminal-style progress
- Add emit_activity method for rich progress events
- Add detailed logging for LLM calls with timing
- Track files_written, tables_synced, bytes_generated
Memory and performance:
- Add memory_monitor module for tracking RSS and thread activity
- Skip 0-byte files in drive monitor and document processor
- Change DRIVE_MONITOR checking logs from info to trace
- Remove unused profile_section macro
WebSocket progress:
- Ensure TaskProgressEvent includes activity field
- Add with_activity builder method
2025-12-30 22:42:32 -03:00
|
|
|
pub max_concurrent_requests: usize,
|
|
|
|
|
pub connect_timeout_seconds: u64,
|
2025-11-26 22:54:22 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Default for EmbeddingConfig {
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
embedding_url: "http://localhost:8082".to_string(),
|
|
|
|
|
embedding_model: "bge-small-en-v1.5".to_string(),
|
2025-12-23 18:40:58 -03:00
|
|
|
dimensions: 384,
|
Fix tasks UI, WebSocket progress, memory monitoring, and app generator
Tasks UI fixes:
- Fix task list to query auto_tasks table instead of tasks table
- Fix task detail endpoint to use UUID binding for auto_tasks query
- Add proper filter handling: complete, active, awaiting, paused, blocked
- Add TaskStats fields: awaiting, paused, blocked, time_saved
- Add /api/tasks/time-saved endpoint
- Add count-all to stats HTML response
App generator improvements:
- Add AgentActivity struct for detailed terminal-style progress
- Add emit_activity method for rich progress events
- Add detailed logging for LLM calls with timing
- Track files_written, tables_synced, bytes_generated
Memory and performance:
- Add memory_monitor module for tracking RSS and thread activity
- Skip 0-byte files in drive monitor and document processor
- Change DRIVE_MONITOR checking logs from info to trace
- Remove unused profile_section macro
WebSocket progress:
- Ensure TaskProgressEvent includes activity field
- Add with_activity builder method
2025-12-30 22:42:32 -03:00
|
|
|
batch_size: 16,
|
|
|
|
|
timeout_seconds: 60,
|
2026-02-04 13:29:29 -03:00
|
|
|
max_concurrent_requests: 1,
|
Fix tasks UI, WebSocket progress, memory monitoring, and app generator
Tasks UI fixes:
- Fix task list to query auto_tasks table instead of tasks table
- Fix task detail endpoint to use UUID binding for auto_tasks query
- Add proper filter handling: complete, active, awaiting, paused, blocked
- Add TaskStats fields: awaiting, paused, blocked, time_saved
- Add /api/tasks/time-saved endpoint
- Add count-all to stats HTML response
App generator improvements:
- Add AgentActivity struct for detailed terminal-style progress
- Add emit_activity method for rich progress events
- Add detailed logging for LLM calls with timing
- Track files_written, tables_synced, bytes_generated
Memory and performance:
- Add memory_monitor module for tracking RSS and thread activity
- Skip 0-byte files in drive monitor and document processor
- Change DRIVE_MONITOR checking logs from info to trace
- Remove unused profile_section macro
WebSocket progress:
- Ensure TaskProgressEvent includes activity field
- Add with_activity builder method
2025-12-30 22:42:32 -03:00
|
|
|
connect_timeout_seconds: 10,
|
2025-11-26 22:54:22 -03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl EmbeddingConfig {
|
|
|
|
|
pub fn from_env() -> Self {
|
Add .env.example with comprehensive configuration template
The commit adds a complete example environment configuration file
documenting all available settings for BotServer, including logging,
database, server, drive, LLM, Redis, email, and feature flags.
Also removes hardcoded environment variable usage throughout the
codebase, replacing them with configuration via config.csv or
appropriate defaults. This includes:
- WhatsApp, Teams, Instagram adapter configurations
- Weather API key handling
- Email and directory service configurations
- Console feature conditionally compiles monitoring code
- Improved logging configuration with library suppression
2025-11-28 13:19:03 -03:00
|
|
|
let embedding_url = "http://localhost:8082".to_string();
|
|
|
|
|
let embedding_model = "bge-small-en-v1.5".to_string();
|
2025-11-26 22:54:22 -03:00
|
|
|
let dimensions = Self::detect_dimensions(&embedding_model);
|
|
|
|
|
|
|
|
|
|
Self {
|
|
|
|
|
embedding_url,
|
|
|
|
|
embedding_model,
|
|
|
|
|
dimensions,
|
Fix tasks UI, WebSocket progress, memory monitoring, and app generator
Tasks UI fixes:
- Fix task list to query auto_tasks table instead of tasks table
- Fix task detail endpoint to use UUID binding for auto_tasks query
- Add proper filter handling: complete, active, awaiting, paused, blocked
- Add TaskStats fields: awaiting, paused, blocked, time_saved
- Add /api/tasks/time-saved endpoint
- Add count-all to stats HTML response
App generator improvements:
- Add AgentActivity struct for detailed terminal-style progress
- Add emit_activity method for rich progress events
- Add detailed logging for LLM calls with timing
- Track files_written, tables_synced, bytes_generated
Memory and performance:
- Add memory_monitor module for tracking RSS and thread activity
- Skip 0-byte files in drive monitor and document processor
- Change DRIVE_MONITOR checking logs from info to trace
- Remove unused profile_section macro
WebSocket progress:
- Ensure TaskProgressEvent includes activity field
- Add with_activity builder method
2025-12-30 22:42:32 -03:00
|
|
|
batch_size: 16,
|
|
|
|
|
timeout_seconds: 60,
|
2026-02-04 13:29:29 -03:00
|
|
|
max_concurrent_requests: 1,
|
Fix tasks UI, WebSocket progress, memory monitoring, and app generator
Tasks UI fixes:
- Fix task list to query auto_tasks table instead of tasks table
- Fix task detail endpoint to use UUID binding for auto_tasks query
- Add proper filter handling: complete, active, awaiting, paused, blocked
- Add TaskStats fields: awaiting, paused, blocked, time_saved
- Add /api/tasks/time-saved endpoint
- Add count-all to stats HTML response
App generator improvements:
- Add AgentActivity struct for detailed terminal-style progress
- Add emit_activity method for rich progress events
- Add detailed logging for LLM calls with timing
- Track files_written, tables_synced, bytes_generated
Memory and performance:
- Add memory_monitor module for tracking RSS and thread activity
- Skip 0-byte files in drive monitor and document processor
- Change DRIVE_MONITOR checking logs from info to trace
- Remove unused profile_section macro
WebSocket progress:
- Ensure TaskProgressEvent includes activity field
- Add with_activity builder method
2025-12-30 22:42:32 -03:00
|
|
|
connect_timeout_seconds: 10,
|
2025-11-26 22:54:22 -03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn detect_dimensions(model: &str) -> usize {
|
|
|
|
|
if model.contains("small") || model.contains("MiniLM") {
|
|
|
|
|
384
|
|
|
|
|
} else if model.contains("base") || model.contains("mpnet") {
|
|
|
|
|
768
|
|
|
|
|
} else if model.contains("large") || model.contains("ada") {
|
|
|
|
|
1536
|
|
|
|
|
} else {
|
2025-12-23 18:40:58 -03:00
|
|
|
384
|
2025-11-26 22:54:22 -03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Serialize)]
|
|
|
|
|
struct EmbeddingRequest {
|
|
|
|
|
input: Vec<String>,
|
|
|
|
|
model: String,
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-04 13:29:29 -03:00
|
|
|
// OpenAI/Claude/OpenAI-compatible format
|
2025-11-26 22:54:22 -03:00
|
|
|
#[derive(Debug, Deserialize)]
|
2026-02-04 13:29:29 -03:00
|
|
|
struct OpenAIEmbeddingResponse {
|
|
|
|
|
data: Vec<OpenAIEmbeddingData>,
|
2025-11-26 22:54:22 -03:00
|
|
|
model: String,
|
|
|
|
|
usage: Option<EmbeddingUsage>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize)]
|
2026-02-04 13:29:29 -03:00
|
|
|
struct OpenAIEmbeddingData {
|
2025-11-26 22:54:22 -03:00
|
|
|
embedding: Vec<f32>,
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-04 13:29:29 -03:00
|
|
|
// llama.cpp format
|
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
|
|
|
struct LlamaCppEmbeddingItem {
|
|
|
|
|
embedding: Vec<Vec<f32>>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Hugging Face/SentenceTransformers format (simple array)
|
|
|
|
|
type HuggingFaceEmbeddingResponse = Vec<Vec<f32>>;
|
|
|
|
|
|
|
|
|
|
// Generic embedding service format (object with embeddings key)
|
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
|
|
|
struct GenericEmbeddingResponse {
|
|
|
|
|
embeddings: Vec<Vec<f32>>,
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
model: Option<String>,
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
usage: Option<EmbeddingUsage>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Universal response wrapper - tries formats in order of likelihood
|
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
|
|
|
#[serde(untagged)]
|
|
|
|
|
enum EmbeddingResponse {
|
|
|
|
|
OpenAI(OpenAIEmbeddingResponse), // Most common: OpenAI, Claude, etc.
|
|
|
|
|
LlamaCpp(Vec<LlamaCppEmbeddingItem>), // llama.cpp server
|
|
|
|
|
HuggingFace(HuggingFaceEmbeddingResponse), // Simple array format
|
|
|
|
|
Generic(GenericEmbeddingResponse), // Generic services
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-26 22:54:22 -03:00
|
|
|
#[derive(Debug, Deserialize)]
|
|
|
|
|
struct EmbeddingUsage {
|
Fix tasks UI, WebSocket progress, memory monitoring, and app generator
Tasks UI fixes:
- Fix task list to query auto_tasks table instead of tasks table
- Fix task detail endpoint to use UUID binding for auto_tasks query
- Add proper filter handling: complete, active, awaiting, paused, blocked
- Add TaskStats fields: awaiting, paused, blocked, time_saved
- Add /api/tasks/time-saved endpoint
- Add count-all to stats HTML response
App generator improvements:
- Add AgentActivity struct for detailed terminal-style progress
- Add emit_activity method for rich progress events
- Add detailed logging for LLM calls with timing
- Track files_written, tables_synced, bytes_generated
Memory and performance:
- Add memory_monitor module for tracking RSS and thread activity
- Skip 0-byte files in drive monitor and document processor
- Change DRIVE_MONITOR checking logs from info to trace
- Remove unused profile_section macro
WebSocket progress:
- Ensure TaskProgressEvent includes activity field
- Add with_activity builder method
2025-12-30 22:42:32 -03:00
|
|
|
#[serde(default)]
|
2025-11-26 22:54:22 -03:00
|
|
|
total_tokens: usize,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
|
pub struct Embedding {
|
|
|
|
|
pub vector: Vec<f32>,
|
|
|
|
|
pub dimensions: usize,
|
|
|
|
|
pub model: String,
|
|
|
|
|
pub tokens_used: Option<usize>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct KbEmbeddingGenerator {
|
|
|
|
|
config: EmbeddingConfig,
|
|
|
|
|
client: Client,
|
|
|
|
|
semaphore: Arc<Semaphore>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl std::fmt::Debug for KbEmbeddingGenerator {
|
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
|
f.debug_struct("KbEmbeddingGenerator")
|
|
|
|
|
.field("config", &self.config)
|
|
|
|
|
.field("client", &"Client")
|
|
|
|
|
.field("semaphore", &"Semaphore")
|
|
|
|
|
.finish()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl KbEmbeddingGenerator {
|
|
|
|
|
pub fn new(config: EmbeddingConfig) -> Self {
|
|
|
|
|
let client = Client::builder()
|
Fix tasks UI, WebSocket progress, memory monitoring, and app generator
Tasks UI fixes:
- Fix task list to query auto_tasks table instead of tasks table
- Fix task detail endpoint to use UUID binding for auto_tasks query
- Add proper filter handling: complete, active, awaiting, paused, blocked
- Add TaskStats fields: awaiting, paused, blocked, time_saved
- Add /api/tasks/time-saved endpoint
- Add count-all to stats HTML response
App generator improvements:
- Add AgentActivity struct for detailed terminal-style progress
- Add emit_activity method for rich progress events
- Add detailed logging for LLM calls with timing
- Track files_written, tables_synced, bytes_generated
Memory and performance:
- Add memory_monitor module for tracking RSS and thread activity
- Skip 0-byte files in drive monitor and document processor
- Change DRIVE_MONITOR checking logs from info to trace
- Remove unused profile_section macro
WebSocket progress:
- Ensure TaskProgressEvent includes activity field
- Add with_activity builder method
2025-12-30 22:42:32 -03:00
|
|
|
.timeout(Duration::from_secs(config.timeout_seconds))
|
|
|
|
|
.connect_timeout(Duration::from_secs(config.connect_timeout_seconds))
|
|
|
|
|
.pool_max_idle_per_host(2)
|
|
|
|
|
.pool_idle_timeout(Duration::from_secs(30))
|
|
|
|
|
.tcp_keepalive(Duration::from_secs(60))
|
|
|
|
|
.tcp_nodelay(true)
|
2025-11-26 22:54:22 -03:00
|
|
|
.build()
|
2025-12-28 21:26:08 -03:00
|
|
|
.unwrap_or_else(|e| {
|
Fix tasks UI, WebSocket progress, memory monitoring, and app generator
Tasks UI fixes:
- Fix task list to query auto_tasks table instead of tasks table
- Fix task detail endpoint to use UUID binding for auto_tasks query
- Add proper filter handling: complete, active, awaiting, paused, blocked
- Add TaskStats fields: awaiting, paused, blocked, time_saved
- Add /api/tasks/time-saved endpoint
- Add count-all to stats HTML response
App generator improvements:
- Add AgentActivity struct for detailed terminal-style progress
- Add emit_activity method for rich progress events
- Add detailed logging for LLM calls with timing
- Track files_written, tables_synced, bytes_generated
Memory and performance:
- Add memory_monitor module for tracking RSS and thread activity
- Skip 0-byte files in drive monitor and document processor
- Change DRIVE_MONITOR checking logs from info to trace
- Remove unused profile_section macro
WebSocket progress:
- Ensure TaskProgressEvent includes activity field
- Add with_activity builder method
2025-12-30 22:42:32 -03:00
|
|
|
warn!("Failed to create HTTP client with timeout: {}, using default", e);
|
2025-12-28 21:26:08 -03:00
|
|
|
Client::new()
|
|
|
|
|
});
|
2025-11-26 22:54:22 -03:00
|
|
|
|
Fix tasks UI, WebSocket progress, memory monitoring, and app generator
Tasks UI fixes:
- Fix task list to query auto_tasks table instead of tasks table
- Fix task detail endpoint to use UUID binding for auto_tasks query
- Add proper filter handling: complete, active, awaiting, paused, blocked
- Add TaskStats fields: awaiting, paused, blocked, time_saved
- Add /api/tasks/time-saved endpoint
- Add count-all to stats HTML response
App generator improvements:
- Add AgentActivity struct for detailed terminal-style progress
- Add emit_activity method for rich progress events
- Add detailed logging for LLM calls with timing
- Track files_written, tables_synced, bytes_generated
Memory and performance:
- Add memory_monitor module for tracking RSS and thread activity
- Skip 0-byte files in drive monitor and document processor
- Change DRIVE_MONITOR checking logs from info to trace
- Remove unused profile_section macro
WebSocket progress:
- Ensure TaskProgressEvent includes activity field
- Add with_activity builder method
2025-12-30 22:42:32 -03:00
|
|
|
let semaphore = Arc::new(Semaphore::new(config.max_concurrent_requests));
|
2025-11-26 22:54:22 -03:00
|
|
|
|
|
|
|
|
Self {
|
|
|
|
|
config,
|
|
|
|
|
client,
|
|
|
|
|
semaphore,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Fix tasks UI, WebSocket progress, memory monitoring, and app generator
Tasks UI fixes:
- Fix task list to query auto_tasks table instead of tasks table
- Fix task detail endpoint to use UUID binding for auto_tasks query
- Add proper filter handling: complete, active, awaiting, paused, blocked
- Add TaskStats fields: awaiting, paused, blocked, time_saved
- Add /api/tasks/time-saved endpoint
- Add count-all to stats HTML response
App generator improvements:
- Add AgentActivity struct for detailed terminal-style progress
- Add emit_activity method for rich progress events
- Add detailed logging for LLM calls with timing
- Track files_written, tables_synced, bytes_generated
Memory and performance:
- Add memory_monitor module for tracking RSS and thread activity
- Skip 0-byte files in drive monitor and document processor
- Change DRIVE_MONITOR checking logs from info to trace
- Remove unused profile_section macro
WebSocket progress:
- Ensure TaskProgressEvent includes activity field
- Add with_activity builder method
2025-12-30 22:42:32 -03:00
|
|
|
pub async fn check_health(&self) -> bool {
|
|
|
|
|
let health_url = format!("{}/health", self.config.embedding_url);
|
|
|
|
|
|
|
|
|
|
match tokio::time::timeout(
|
|
|
|
|
Duration::from_secs(5),
|
|
|
|
|
self.client.get(&health_url).send()
|
|
|
|
|
).await {
|
|
|
|
|
Ok(Ok(response)) => {
|
|
|
|
|
let is_healthy = response.status().is_success();
|
|
|
|
|
if is_healthy {
|
|
|
|
|
set_embedding_server_ready(true);
|
|
|
|
|
}
|
|
|
|
|
is_healthy
|
|
|
|
|
}
|
|
|
|
|
Ok(Err(e)) => {
|
|
|
|
|
let alt_url = &self.config.embedding_url;
|
|
|
|
|
match tokio::time::timeout(
|
|
|
|
|
Duration::from_secs(5),
|
|
|
|
|
self.client.get(alt_url).send()
|
|
|
|
|
).await {
|
|
|
|
|
Ok(Ok(response)) => {
|
|
|
|
|
let is_healthy = response.status().is_success();
|
|
|
|
|
if is_healthy {
|
|
|
|
|
set_embedding_server_ready(true);
|
|
|
|
|
}
|
|
|
|
|
is_healthy
|
|
|
|
|
}
|
|
|
|
|
_ => {
|
|
|
|
|
warn!("[EMBEDDING] Health check failed: {}", e);
|
|
|
|
|
false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Err(_) => {
|
|
|
|
|
warn!("[EMBEDDING] Health check timed out");
|
|
|
|
|
false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub async fn wait_for_server(&self, max_wait_secs: u64) -> bool {
|
|
|
|
|
let start = std::time::Instant::now();
|
|
|
|
|
let max_wait = Duration::from_secs(max_wait_secs);
|
|
|
|
|
|
|
|
|
|
info!("[EMBEDDING] Waiting for embedding server at {} (max {}s)...",
|
|
|
|
|
self.config.embedding_url, max_wait_secs);
|
|
|
|
|
|
|
|
|
|
while start.elapsed() < max_wait {
|
|
|
|
|
if self.check_health().await {
|
|
|
|
|
info!("[EMBEDDING] Embedding server is ready after {:?}", start.elapsed());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
tokio::time::sleep(Duration::from_secs(2)).await;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
warn!("[EMBEDDING] Embedding server not available after {}s", max_wait_secs);
|
|
|
|
|
false
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-26 22:54:22 -03:00
|
|
|
pub async fn generate_embeddings(
|
|
|
|
|
&self,
|
|
|
|
|
chunks: &[TextChunk],
|
|
|
|
|
) -> Result<Vec<(TextChunk, Embedding)>> {
|
|
|
|
|
if chunks.is_empty() {
|
|
|
|
|
return Ok(Vec::new());
|
|
|
|
|
}
|
|
|
|
|
|
Fix tasks UI, WebSocket progress, memory monitoring, and app generator
Tasks UI fixes:
- Fix task list to query auto_tasks table instead of tasks table
- Fix task detail endpoint to use UUID binding for auto_tasks query
- Add proper filter handling: complete, active, awaiting, paused, blocked
- Add TaskStats fields: awaiting, paused, blocked, time_saved
- Add /api/tasks/time-saved endpoint
- Add count-all to stats HTML response
App generator improvements:
- Add AgentActivity struct for detailed terminal-style progress
- Add emit_activity method for rich progress events
- Add detailed logging for LLM calls with timing
- Track files_written, tables_synced, bytes_generated
Memory and performance:
- Add memory_monitor module for tracking RSS and thread activity
- Skip 0-byte files in drive monitor and document processor
- Change DRIVE_MONITOR checking logs from info to trace
- Remove unused profile_section macro
WebSocket progress:
- Ensure TaskProgressEvent includes activity field
- Add with_activity builder method
2025-12-30 22:42:32 -03:00
|
|
|
if !is_embedding_server_ready() {
|
|
|
|
|
info!("[EMBEDDING] Server not marked ready, checking health...");
|
|
|
|
|
if !self.wait_for_server(30).await {
|
|
|
|
|
return Err(anyhow::anyhow!(
|
|
|
|
|
"Embedding server not available at {}. Skipping embedding generation.",
|
|
|
|
|
self.config.embedding_url
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-11-26 22:54:22 -03:00
|
|
|
|
Fix tasks UI, WebSocket progress, memory monitoring, and app generator
Tasks UI fixes:
- Fix task list to query auto_tasks table instead of tasks table
- Fix task detail endpoint to use UUID binding for auto_tasks query
- Add proper filter handling: complete, active, awaiting, paused, blocked
- Add TaskStats fields: awaiting, paused, blocked, time_saved
- Add /api/tasks/time-saved endpoint
- Add count-all to stats HTML response
App generator improvements:
- Add AgentActivity struct for detailed terminal-style progress
- Add emit_activity method for rich progress events
- Add detailed logging for LLM calls with timing
- Track files_written, tables_synced, bytes_generated
Memory and performance:
- Add memory_monitor module for tracking RSS and thread activity
- Skip 0-byte files in drive monitor and document processor
- Change DRIVE_MONITOR checking logs from info to trace
- Remove unused profile_section macro
WebSocket progress:
- Ensure TaskProgressEvent includes activity field
- Add with_activity builder method
2025-12-30 22:42:32 -03:00
|
|
|
let start_mem = MemoryStats::current();
|
|
|
|
|
trace!("[EMBEDDING] Generating embeddings for {} chunks, RSS={}",
|
|
|
|
|
chunks.len(), MemoryStats::format_bytes(start_mem.rss_bytes));
|
|
|
|
|
|
|
|
|
|
let mut results = Vec::with_capacity(chunks.len());
|
2026-02-04 13:29:29 -03:00
|
|
|
let total_batches = chunks.len().div_ceil(self.config.batch_size);
|
Fix tasks UI, WebSocket progress, memory monitoring, and app generator
Tasks UI fixes:
- Fix task list to query auto_tasks table instead of tasks table
- Fix task detail endpoint to use UUID binding for auto_tasks query
- Add proper filter handling: complete, active, awaiting, paused, blocked
- Add TaskStats fields: awaiting, paused, blocked, time_saved
- Add /api/tasks/time-saved endpoint
- Add count-all to stats HTML response
App generator improvements:
- Add AgentActivity struct for detailed terminal-style progress
- Add emit_activity method for rich progress events
- Add detailed logging for LLM calls with timing
- Track files_written, tables_synced, bytes_generated
Memory and performance:
- Add memory_monitor module for tracking RSS and thread activity
- Skip 0-byte files in drive monitor and document processor
- Change DRIVE_MONITOR checking logs from info to trace
- Remove unused profile_section macro
WebSocket progress:
- Ensure TaskProgressEvent includes activity field
- Add with_activity builder method
2025-12-30 22:42:32 -03:00
|
|
|
|
|
|
|
|
for (batch_num, batch) in chunks.chunks(self.config.batch_size).enumerate() {
|
|
|
|
|
let batch_start = MemoryStats::current();
|
|
|
|
|
trace!("[EMBEDDING] Processing batch {}/{} ({} items), RSS={}",
|
|
|
|
|
batch_num + 1,
|
|
|
|
|
total_batches,
|
|
|
|
|
batch.len(),
|
|
|
|
|
MemoryStats::format_bytes(batch_start.rss_bytes));
|
|
|
|
|
|
|
|
|
|
let batch_embeddings = match tokio::time::timeout(
|
|
|
|
|
Duration::from_secs(self.config.timeout_seconds),
|
|
|
|
|
self.generate_batch_embeddings(batch)
|
|
|
|
|
).await {
|
|
|
|
|
Ok(Ok(embeddings)) => embeddings,
|
|
|
|
|
Ok(Err(e)) => {
|
|
|
|
|
warn!("[EMBEDDING] Batch {} failed: {}", batch_num + 1, e);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
Err(_) => {
|
|
|
|
|
warn!("[EMBEDDING] Batch {} timed out after {}s",
|
|
|
|
|
batch_num + 1, self.config.timeout_seconds);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let batch_end = MemoryStats::current();
|
|
|
|
|
let delta = batch_end.rss_bytes.saturating_sub(batch_start.rss_bytes);
|
|
|
|
|
trace!("[EMBEDDING] Batch {} complete: {} embeddings, RSS={} (delta={})",
|
|
|
|
|
batch_num + 1,
|
|
|
|
|
batch_embeddings.len(),
|
|
|
|
|
MemoryStats::format_bytes(batch_end.rss_bytes),
|
|
|
|
|
MemoryStats::format_bytes(delta));
|
|
|
|
|
|
|
|
|
|
if delta > 100 * 1024 * 1024 {
|
|
|
|
|
warn!("[EMBEDDING] Excessive memory growth detected ({}), stopping early",
|
|
|
|
|
MemoryStats::format_bytes(delta));
|
|
|
|
|
for (chunk, embedding) in batch.iter().zip(batch_embeddings.iter()) {
|
|
|
|
|
results.push((chunk.clone(), embedding.clone()));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2025-11-26 22:54:22 -03:00
|
|
|
|
|
|
|
|
for (chunk, embedding) in batch.iter().zip(batch_embeddings.iter()) {
|
|
|
|
|
results.push((chunk.clone(), embedding.clone()));
|
|
|
|
|
}
|
Fix tasks UI, WebSocket progress, memory monitoring, and app generator
Tasks UI fixes:
- Fix task list to query auto_tasks table instead of tasks table
- Fix task detail endpoint to use UUID binding for auto_tasks query
- Add proper filter handling: complete, active, awaiting, paused, blocked
- Add TaskStats fields: awaiting, paused, blocked, time_saved
- Add /api/tasks/time-saved endpoint
- Add count-all to stats HTML response
App generator improvements:
- Add AgentActivity struct for detailed terminal-style progress
- Add emit_activity method for rich progress events
- Add detailed logging for LLM calls with timing
- Track files_written, tables_synced, bytes_generated
Memory and performance:
- Add memory_monitor module for tracking RSS and thread activity
- Skip 0-byte files in drive monitor and document processor
- Change DRIVE_MONITOR checking logs from info to trace
- Remove unused profile_section macro
WebSocket progress:
- Ensure TaskProgressEvent includes activity field
- Add with_activity builder method
2025-12-30 22:42:32 -03:00
|
|
|
|
|
|
|
|
if batch_num + 1 < total_batches {
|
|
|
|
|
tokio::time::sleep(Duration::from_millis(100)).await;
|
|
|
|
|
}
|
2025-11-26 22:54:22 -03:00
|
|
|
}
|
|
|
|
|
|
Fix tasks UI, WebSocket progress, memory monitoring, and app generator
Tasks UI fixes:
- Fix task list to query auto_tasks table instead of tasks table
- Fix task detail endpoint to use UUID binding for auto_tasks query
- Add proper filter handling: complete, active, awaiting, paused, blocked
- Add TaskStats fields: awaiting, paused, blocked, time_saved
- Add /api/tasks/time-saved endpoint
- Add count-all to stats HTML response
App generator improvements:
- Add AgentActivity struct for detailed terminal-style progress
- Add emit_activity method for rich progress events
- Add detailed logging for LLM calls with timing
- Track files_written, tables_synced, bytes_generated
Memory and performance:
- Add memory_monitor module for tracking RSS and thread activity
- Skip 0-byte files in drive monitor and document processor
- Change DRIVE_MONITOR checking logs from info to trace
- Remove unused profile_section macro
WebSocket progress:
- Ensure TaskProgressEvent includes activity field
- Add with_activity builder method
2025-12-30 22:42:32 -03:00
|
|
|
let end_mem = MemoryStats::current();
|
|
|
|
|
trace!("[EMBEDDING] Generated {} embeddings, RSS={} (total delta={})",
|
|
|
|
|
results.len(),
|
|
|
|
|
MemoryStats::format_bytes(end_mem.rss_bytes),
|
|
|
|
|
MemoryStats::format_bytes(end_mem.rss_bytes.saturating_sub(start_mem.rss_bytes)));
|
|
|
|
|
log_jemalloc_stats();
|
2025-11-26 22:54:22 -03:00
|
|
|
|
|
|
|
|
Ok(results)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn generate_batch_embeddings(&self, chunks: &[TextChunk]) -> Result<Vec<Embedding>> {
|
Fix tasks UI, WebSocket progress, memory monitoring, and app generator
Tasks UI fixes:
- Fix task list to query auto_tasks table instead of tasks table
- Fix task detail endpoint to use UUID binding for auto_tasks query
- Add proper filter handling: complete, active, awaiting, paused, blocked
- Add TaskStats fields: awaiting, paused, blocked, time_saved
- Add /api/tasks/time-saved endpoint
- Add count-all to stats HTML response
App generator improvements:
- Add AgentActivity struct for detailed terminal-style progress
- Add emit_activity method for rich progress events
- Add detailed logging for LLM calls with timing
- Track files_written, tables_synced, bytes_generated
Memory and performance:
- Add memory_monitor module for tracking RSS and thread activity
- Skip 0-byte files in drive monitor and document processor
- Change DRIVE_MONITOR checking logs from info to trace
- Remove unused profile_section macro
WebSocket progress:
- Ensure TaskProgressEvent includes activity field
- Add with_activity builder method
2025-12-30 22:42:32 -03:00
|
|
|
let _permit = self.semaphore.acquire().await
|
|
|
|
|
.map_err(|e| anyhow::anyhow!("Failed to acquire semaphore: {}", e))?;
|
2025-11-26 22:54:22 -03:00
|
|
|
|
|
|
|
|
let texts: Vec<String> = chunks.iter().map(|c| c.content.clone()).collect();
|
Fix tasks UI, WebSocket progress, memory monitoring, and app generator
Tasks UI fixes:
- Fix task list to query auto_tasks table instead of tasks table
- Fix task detail endpoint to use UUID binding for auto_tasks query
- Add proper filter handling: complete, active, awaiting, paused, blocked
- Add TaskStats fields: awaiting, paused, blocked, time_saved
- Add /api/tasks/time-saved endpoint
- Add count-all to stats HTML response
App generator improvements:
- Add AgentActivity struct for detailed terminal-style progress
- Add emit_activity method for rich progress events
- Add detailed logging for LLM calls with timing
- Track files_written, tables_synced, bytes_generated
Memory and performance:
- Add memory_monitor module for tracking RSS and thread activity
- Skip 0-byte files in drive monitor and document processor
- Change DRIVE_MONITOR checking logs from info to trace
- Remove unused profile_section macro
WebSocket progress:
- Ensure TaskProgressEvent includes activity field
- Add with_activity builder method
2025-12-30 22:42:32 -03:00
|
|
|
let total_chars: usize = texts.iter().map(|t| t.len()).sum();
|
|
|
|
|
|
|
|
|
|
info!("[EMBEDDING] generate_batch_embeddings: {} texts, {} total chars",
|
|
|
|
|
texts.len(), total_chars);
|
2025-11-26 22:54:22 -03:00
|
|
|
|
2026-02-04 13:29:29 -03:00
|
|
|
match self.generate_local_embeddings(&texts).await {
|
Fix tasks UI, WebSocket progress, memory monitoring, and app generator
Tasks UI fixes:
- Fix task list to query auto_tasks table instead of tasks table
- Fix task detail endpoint to use UUID binding for auto_tasks query
- Add proper filter handling: complete, active, awaiting, paused, blocked
- Add TaskStats fields: awaiting, paused, blocked, time_saved
- Add /api/tasks/time-saved endpoint
- Add count-all to stats HTML response
App generator improvements:
- Add AgentActivity struct for detailed terminal-style progress
- Add emit_activity method for rich progress events
- Add detailed logging for LLM calls with timing
- Track files_written, tables_synced, bytes_generated
Memory and performance:
- Add memory_monitor module for tracking RSS and thread activity
- Skip 0-byte files in drive monitor and document processor
- Change DRIVE_MONITOR checking logs from info to trace
- Remove unused profile_section macro
WebSocket progress:
- Ensure TaskProgressEvent includes activity field
- Add with_activity builder method
2025-12-30 22:42:32 -03:00
|
|
|
Ok(embeddings) => {
|
|
|
|
|
info!("[EMBEDDING] Local embeddings succeeded: {} vectors", embeddings.len());
|
|
|
|
|
Ok(embeddings)
|
|
|
|
|
}
|
2025-11-26 22:54:22 -03:00
|
|
|
Err(e) => {
|
Fix tasks UI, WebSocket progress, memory monitoring, and app generator
Tasks UI fixes:
- Fix task list to query auto_tasks table instead of tasks table
- Fix task detail endpoint to use UUID binding for auto_tasks query
- Add proper filter handling: complete, active, awaiting, paused, blocked
- Add TaskStats fields: awaiting, paused, blocked, time_saved
- Add /api/tasks/time-saved endpoint
- Add count-all to stats HTML response
App generator improvements:
- Add AgentActivity struct for detailed terminal-style progress
- Add emit_activity method for rich progress events
- Add detailed logging for LLM calls with timing
- Track files_written, tables_synced, bytes_generated
Memory and performance:
- Add memory_monitor module for tracking RSS and thread activity
- Skip 0-byte files in drive monitor and document processor
- Change DRIVE_MONITOR checking logs from info to trace
- Remove unused profile_section macro
WebSocket progress:
- Ensure TaskProgressEvent includes activity field
- Add with_activity builder method
2025-12-30 22:42:32 -03:00
|
|
|
warn!("[EMBEDDING] Local embedding service failed: {}", e);
|
|
|
|
|
Err(e)
|
2025-11-26 22:54:22 -03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn generate_local_embeddings(&self, texts: &[String]) -> Result<Vec<Embedding>> {
|
2026-02-04 13:29:29 -03:00
|
|
|
// Apply token-aware truncation to each text before creating request
|
|
|
|
|
let truncated_texts: Vec<String> = texts.iter()
|
|
|
|
|
.map(|text| crate::core::shared::utils::truncate_text_for_model(text, &self.config.embedding_model, 600))
|
|
|
|
|
.collect();
|
|
|
|
|
|
2025-11-26 22:54:22 -03:00
|
|
|
let request = EmbeddingRequest {
|
2026-02-04 13:29:29 -03:00
|
|
|
input: truncated_texts,
|
2025-11-26 22:54:22 -03:00
|
|
|
model: self.config.embedding_model.clone(),
|
|
|
|
|
};
|
|
|
|
|
|
Fix tasks UI, WebSocket progress, memory monitoring, and app generator
Tasks UI fixes:
- Fix task list to query auto_tasks table instead of tasks table
- Fix task detail endpoint to use UUID binding for auto_tasks query
- Add proper filter handling: complete, active, awaiting, paused, blocked
- Add TaskStats fields: awaiting, paused, blocked, time_saved
- Add /api/tasks/time-saved endpoint
- Add count-all to stats HTML response
App generator improvements:
- Add AgentActivity struct for detailed terminal-style progress
- Add emit_activity method for rich progress events
- Add detailed logging for LLM calls with timing
- Track files_written, tables_synced, bytes_generated
Memory and performance:
- Add memory_monitor module for tracking RSS and thread activity
- Skip 0-byte files in drive monitor and document processor
- Change DRIVE_MONITOR checking logs from info to trace
- Remove unused profile_section macro
WebSocket progress:
- Ensure TaskProgressEvent includes activity field
- Add with_activity builder method
2025-12-30 22:42:32 -03:00
|
|
|
let request_size = serde_json::to_string(&request)
|
|
|
|
|
.map(|s| s.len())
|
|
|
|
|
.unwrap_or(0);
|
|
|
|
|
info!("[EMBEDDING] Sending request to {} (size: {} bytes)",
|
|
|
|
|
self.config.embedding_url, request_size);
|
|
|
|
|
|
2025-11-26 22:54:22 -03:00
|
|
|
let response = self
|
|
|
|
|
.client
|
2026-02-04 13:29:29 -03:00
|
|
|
.post(format!("{}/embedding", self.config.embedding_url))
|
2025-11-26 22:54:22 -03:00
|
|
|
.json(&request)
|
|
|
|
|
.send()
|
|
|
|
|
.await
|
|
|
|
|
.context("Failed to send request to embedding service")?;
|
|
|
|
|
|
Fix tasks UI, WebSocket progress, memory monitoring, and app generator
Tasks UI fixes:
- Fix task list to query auto_tasks table instead of tasks table
- Fix task detail endpoint to use UUID binding for auto_tasks query
- Add proper filter handling: complete, active, awaiting, paused, blocked
- Add TaskStats fields: awaiting, paused, blocked, time_saved
- Add /api/tasks/time-saved endpoint
- Add count-all to stats HTML response
App generator improvements:
- Add AgentActivity struct for detailed terminal-style progress
- Add emit_activity method for rich progress events
- Add detailed logging for LLM calls with timing
- Track files_written, tables_synced, bytes_generated
Memory and performance:
- Add memory_monitor module for tracking RSS and thread activity
- Skip 0-byte files in drive monitor and document processor
- Change DRIVE_MONITOR checking logs from info to trace
- Remove unused profile_section macro
WebSocket progress:
- Ensure TaskProgressEvent includes activity field
- Add with_activity builder method
2025-12-30 22:42:32 -03:00
|
|
|
let status = response.status();
|
|
|
|
|
if !status.is_success() {
|
|
|
|
|
let error_bytes = response.bytes().await.unwrap_or_default();
|
|
|
|
|
let error_text = String::from_utf8_lossy(&error_bytes[..error_bytes.len().min(1024)]);
|
2025-11-26 22:54:22 -03:00
|
|
|
return Err(anyhow::anyhow!(
|
|
|
|
|
"Embedding service error {}: {}",
|
|
|
|
|
status,
|
|
|
|
|
error_text
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
Fix tasks UI, WebSocket progress, memory monitoring, and app generator
Tasks UI fixes:
- Fix task list to query auto_tasks table instead of tasks table
- Fix task detail endpoint to use UUID binding for auto_tasks query
- Add proper filter handling: complete, active, awaiting, paused, blocked
- Add TaskStats fields: awaiting, paused, blocked, time_saved
- Add /api/tasks/time-saved endpoint
- Add count-all to stats HTML response
App generator improvements:
- Add AgentActivity struct for detailed terminal-style progress
- Add emit_activity method for rich progress events
- Add detailed logging for LLM calls with timing
- Track files_written, tables_synced, bytes_generated
Memory and performance:
- Add memory_monitor module for tracking RSS and thread activity
- Skip 0-byte files in drive monitor and document processor
- Change DRIVE_MONITOR checking logs from info to trace
- Remove unused profile_section macro
WebSocket progress:
- Ensure TaskProgressEvent includes activity field
- Add with_activity builder method
2025-12-30 22:42:32 -03:00
|
|
|
let response_bytes = response.bytes().await
|
|
|
|
|
.context("Failed to read embedding response bytes")?;
|
|
|
|
|
|
|
|
|
|
info!("[EMBEDDING] Received response: {} bytes", response_bytes.len());
|
|
|
|
|
|
|
|
|
|
if response_bytes.len() > 50 * 1024 * 1024 {
|
|
|
|
|
return Err(anyhow::anyhow!(
|
|
|
|
|
"Embedding response too large: {} bytes (max 50MB)",
|
|
|
|
|
response_bytes.len()
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let embedding_response: EmbeddingResponse = serde_json::from_slice(&response_bytes)
|
2026-02-04 13:29:29 -03:00
|
|
|
.with_context(|| {
|
|
|
|
|
let preview = std::str::from_utf8(&response_bytes)
|
|
|
|
|
.map(|s| if s.len() > 200 { &s[..200] } else { s })
|
|
|
|
|
.unwrap_or("<invalid utf8>");
|
|
|
|
|
format!("Failed to parse embedding response. Preview: {}", preview)
|
|
|
|
|
})?;
|
2025-11-26 22:54:22 -03:00
|
|
|
|
Fix tasks UI, WebSocket progress, memory monitoring, and app generator
Tasks UI fixes:
- Fix task list to query auto_tasks table instead of tasks table
- Fix task detail endpoint to use UUID binding for auto_tasks query
- Add proper filter handling: complete, active, awaiting, paused, blocked
- Add TaskStats fields: awaiting, paused, blocked, time_saved
- Add /api/tasks/time-saved endpoint
- Add count-all to stats HTML response
App generator improvements:
- Add AgentActivity struct for detailed terminal-style progress
- Add emit_activity method for rich progress events
- Add detailed logging for LLM calls with timing
- Track files_written, tables_synced, bytes_generated
Memory and performance:
- Add memory_monitor module for tracking RSS and thread activity
- Skip 0-byte files in drive monitor and document processor
- Change DRIVE_MONITOR checking logs from info to trace
- Remove unused profile_section macro
WebSocket progress:
- Ensure TaskProgressEvent includes activity field
- Add with_activity builder method
2025-12-30 22:42:32 -03:00
|
|
|
drop(response_bytes);
|
|
|
|
|
|
2026-02-04 13:29:29 -03:00
|
|
|
let embeddings = match embedding_response {
|
|
|
|
|
EmbeddingResponse::OpenAI(openai_response) => {
|
|
|
|
|
let mut embeddings = Vec::with_capacity(openai_response.data.len());
|
|
|
|
|
for data in openai_response.data {
|
|
|
|
|
embeddings.push(Embedding {
|
|
|
|
|
vector: data.embedding,
|
|
|
|
|
dimensions: self.config.dimensions,
|
|
|
|
|
model: openai_response.model.clone(),
|
|
|
|
|
tokens_used: openai_response.usage.as_ref().map(|u| u.total_tokens),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
embeddings
|
|
|
|
|
}
|
|
|
|
|
EmbeddingResponse::LlamaCpp(llama_response) => {
|
|
|
|
|
let mut embeddings = Vec::new();
|
|
|
|
|
for item in llama_response {
|
|
|
|
|
for embedding_vec in item.embedding {
|
|
|
|
|
embeddings.push(Embedding {
|
|
|
|
|
vector: embedding_vec,
|
|
|
|
|
dimensions: self.config.dimensions,
|
|
|
|
|
model: self.config.embedding_model.clone(),
|
|
|
|
|
tokens_used: None,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
embeddings
|
|
|
|
|
}
|
|
|
|
|
EmbeddingResponse::HuggingFace(hf_response) => {
|
|
|
|
|
let mut embeddings = Vec::with_capacity(hf_response.len());
|
|
|
|
|
for embedding_vec in hf_response {
|
|
|
|
|
embeddings.push(Embedding {
|
|
|
|
|
vector: embedding_vec,
|
|
|
|
|
dimensions: self.config.dimensions,
|
|
|
|
|
model: self.config.embedding_model.clone(),
|
|
|
|
|
tokens_used: None,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
embeddings
|
|
|
|
|
}
|
|
|
|
|
EmbeddingResponse::Generic(generic_response) => {
|
|
|
|
|
let mut embeddings = Vec::with_capacity(generic_response.embeddings.len());
|
|
|
|
|
for embedding_vec in generic_response.embeddings {
|
|
|
|
|
embeddings.push(Embedding {
|
|
|
|
|
vector: embedding_vec,
|
|
|
|
|
dimensions: self.config.dimensions,
|
|
|
|
|
model: generic_response.model.clone().unwrap_or_else(|| self.config.embedding_model.clone()),
|
|
|
|
|
tokens_used: generic_response.usage.as_ref().map(|u| u.total_tokens),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
embeddings
|
|
|
|
|
}
|
|
|
|
|
};
|
2025-11-26 22:54:22 -03:00
|
|
|
|
|
|
|
|
Ok(embeddings)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub async fn generate_single_embedding(&self, text: &str) -> Result<Embedding> {
|
Fix tasks UI, WebSocket progress, memory monitoring, and app generator
Tasks UI fixes:
- Fix task list to query auto_tasks table instead of tasks table
- Fix task detail endpoint to use UUID binding for auto_tasks query
- Add proper filter handling: complete, active, awaiting, paused, blocked
- Add TaskStats fields: awaiting, paused, blocked, time_saved
- Add /api/tasks/time-saved endpoint
- Add count-all to stats HTML response
App generator improvements:
- Add AgentActivity struct for detailed terminal-style progress
- Add emit_activity method for rich progress events
- Add detailed logging for LLM calls with timing
- Track files_written, tables_synced, bytes_generated
Memory and performance:
- Add memory_monitor module for tracking RSS and thread activity
- Skip 0-byte files in drive monitor and document processor
- Change DRIVE_MONITOR checking logs from info to trace
- Remove unused profile_section macro
WebSocket progress:
- Ensure TaskProgressEvent includes activity field
- Add with_activity builder method
2025-12-30 22:42:32 -03:00
|
|
|
if !is_embedding_server_ready() && !self.check_health().await {
|
|
|
|
|
return Err(anyhow::anyhow!(
|
|
|
|
|
"Embedding server not available at {}",
|
|
|
|
|
self.config.embedding_url
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-26 22:54:22 -03:00
|
|
|
let embeddings = self
|
|
|
|
|
.generate_batch_embeddings(&[TextChunk {
|
|
|
|
|
content: text.to_string(),
|
|
|
|
|
metadata: super::document_processor::ChunkMetadata {
|
|
|
|
|
document_path: "query".to_string(),
|
|
|
|
|
document_title: None,
|
|
|
|
|
chunk_index: 0,
|
|
|
|
|
total_chunks: 1,
|
|
|
|
|
start_char: 0,
|
|
|
|
|
end_char: text.len(),
|
|
|
|
|
page_number: None,
|
|
|
|
|
},
|
|
|
|
|
}])
|
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
|
|
embeddings
|
|
|
|
|
.into_iter()
|
|
|
|
|
.next()
|
|
|
|
|
.ok_or_else(|| anyhow::anyhow!("No embedding generated"))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct EmbeddingGenerator {
|
|
|
|
|
kb_generator: KbEmbeddingGenerator,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl std::fmt::Debug for EmbeddingGenerator {
|
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
|
f.debug_struct("EmbeddingGenerator")
|
|
|
|
|
.field("kb_generator", &self.kb_generator)
|
|
|
|
|
.finish()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl EmbeddingGenerator {
|
|
|
|
|
pub fn new(llm_endpoint: String) -> Self {
|
|
|
|
|
let config = EmbeddingConfig {
|
|
|
|
|
embedding_url: llm_endpoint,
|
|
|
|
|
..Default::default()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Self {
|
|
|
|
|
kb_generator: KbEmbeddingGenerator::new(config),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub async fn generate_text_embedding(&self, text: &str) -> Result<Vec<f32>> {
|
|
|
|
|
let embedding = self.kb_generator.generate_single_embedding(text).await?;
|
|
|
|
|
Ok(embedding.vector)
|
|
|
|
|
}
|
Fix tasks UI, WebSocket progress, memory monitoring, and app generator
Tasks UI fixes:
- Fix task list to query auto_tasks table instead of tasks table
- Fix task detail endpoint to use UUID binding for auto_tasks query
- Add proper filter handling: complete, active, awaiting, paused, blocked
- Add TaskStats fields: awaiting, paused, blocked, time_saved
- Add /api/tasks/time-saved endpoint
- Add count-all to stats HTML response
App generator improvements:
- Add AgentActivity struct for detailed terminal-style progress
- Add emit_activity method for rich progress events
- Add detailed logging for LLM calls with timing
- Track files_written, tables_synced, bytes_generated
Memory and performance:
- Add memory_monitor module for tracking RSS and thread activity
- Skip 0-byte files in drive monitor and document processor
- Change DRIVE_MONITOR checking logs from info to trace
- Remove unused profile_section macro
WebSocket progress:
- Ensure TaskProgressEvent includes activity field
- Add with_activity builder method
2025-12-30 22:42:32 -03:00
|
|
|
|
|
|
|
|
/// Check if the embedding server is healthy
|
|
|
|
|
pub async fn check_health(&self) -> bool {
|
|
|
|
|
self.kb_generator.check_health().await
|
|
|
|
|
}
|
2025-11-26 22:54:22 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct EmailEmbeddingGenerator {
|
|
|
|
|
generator: EmbeddingGenerator,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl std::fmt::Debug for EmailEmbeddingGenerator {
|
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
|
f.debug_struct("EmailEmbeddingGenerator")
|
|
|
|
|
.field("generator", &self.generator)
|
|
|
|
|
.finish()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl EmailEmbeddingGenerator {
|
|
|
|
|
pub fn new(llm_endpoint: String) -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
generator: EmbeddingGenerator::new(llm_endpoint),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub async fn generate_embedding(&self, email: &impl EmailLike) -> Result<Vec<f32>> {
|
|
|
|
|
let text = format!(
|
|
|
|
|
"Subject: {}\nFrom: {}\nTo: {}\n\n{}",
|
|
|
|
|
email.subject(),
|
|
|
|
|
email.from(),
|
|
|
|
|
email.to(),
|
|
|
|
|
email.body()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
self.generator.generate_text_embedding(&text).await
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub async fn generate_text_embedding(&self, text: &str) -> Result<Vec<f32>> {
|
|
|
|
|
self.generator.generate_text_embedding(text).await
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub trait EmailLike {
|
|
|
|
|
fn subject(&self) -> &str;
|
|
|
|
|
fn from(&self) -> &str;
|
|
|
|
|
fn to(&self) -> &str;
|
|
|
|
|
fn body(&self) -> &str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
pub struct SimpleEmail {
|
|
|
|
|
pub id: String,
|
|
|
|
|
pub subject: String,
|
|
|
|
|
pub from: String,
|
|
|
|
|
pub to: String,
|
|
|
|
|
pub body: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl EmailLike for SimpleEmail {
|
|
|
|
|
fn subject(&self) -> &str {
|
|
|
|
|
&self.subject
|
|
|
|
|
}
|
|
|
|
|
fn from(&self) -> &str {
|
|
|
|
|
&self.from
|
|
|
|
|
}
|
|
|
|
|
fn to(&self) -> &str {
|
|
|
|
|
&self.to
|
|
|
|
|
}
|
|
|
|
|
fn body(&self) -> &str {
|
|
|
|
|
&self.body
|
|
|
|
|
}
|
|
|
|
|
}
|