refactor: enhance logging context handling

This commit is contained in:
Han Xiao 2025-06-10 11:56:59 -07:00
parent 9edf122a8c
commit 4180460585
4 changed files with 17 additions and 4 deletions

View File

@ -9,12 +9,26 @@ interface LogEntry {
}
function createLogEntry(severity: string, message: string, context: Record<string, any> = {}): LogEntry {
// Handle error objects specially
const processedContext = Object.entries(context).reduce((acc, [key, value]) => {
if (value instanceof Error) {
acc[key] = {
message: value.message,
stack: value.stack,
name: value.name
};
} else {
acc[key] = value;
}
return acc;
}, {} as Record<string, any>);
const entry: LogEntry = {
severity,
message,
component: 'deepsearch',
timestamp: new Date().toISOString(),
...context
...processedContext
};
// Add trace context if available

View File

@ -230,7 +230,6 @@ export async function buildReferences(
} catch (error) {
logError('Embedding failed, falling back to Jaccard similarity', { error });
logDebug(`[buildReferences] Fallback: Using Jaccard similarity instead of embeddings`);
// Process all chunks with Jaccard fallback
const allMatches = [];

View File

@ -23,7 +23,7 @@ export function cosineSimilarity(vecA: number[], vecB: number[]): number {
// Fallback similarity ranking using Jaccard
export async function jaccardRank(query: string, documents: string[]): Promise<{ results: { index: number, relevance_score: number }[] }> {
logInfo(`[fallback] Using Jaccard similarity for ${documents.length} documents`);
logWarning(`[fallback] Using Jaccard similarity for ${documents.length} documents`);
// Convert texts to lowercase and tokenize by splitting on non-alphanumeric characters
const queryTokens = new Set(query.toLowerCase().split(/\W+/).filter(t => t.length > 0));

View File

@ -1,7 +1,7 @@
import { JINA_API_KEY } from "../config";
import { JinaEmbeddingRequest, JinaEmbeddingResponse } from "../types";
import axiosClient from "../utils/axios-client";
import { logInfo, logError, logDebug, logWarning } from '../logging';
import { logError, logDebug, logWarning } from '../logging';
const BATCH_SIZE = 128;
const API_URL = "https://api.jina.ai/v1/embeddings";