mirror of
https://github.com/jina-ai/node-DeepResearch.git
synced 2025-12-26 06:28:56 +08:00
refactor: enhance logging context handling
This commit is contained in:
parent
9edf122a8c
commit
4180460585
@ -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
|
||||
|
||||
@ -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 = [];
|
||||
|
||||
@ -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));
|
||||
|
||||
|
||||
@ -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";
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user