From 0695e7a7608bea5b39742062e4de58585db2c7ed Mon Sep 17 00:00:00 2001 From: Konstantin Cheremisov Date: Thu, 29 Jan 2026 00:00:31 +0200 Subject: [PATCH] fix(embedding): reduce MAX_CHARS to prevent context length errors Reduced MAX_CHARS from 8000 to 2000 characters to prevent "input length exceeds context length" errors with embedding models like nomic-embed-text. The previous limit was unsafe for Cyrillic/CJK text where char-to-token ratio is much lower than English. --- crates/opencontext-core/src/search/embedding.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/opencontext-core/src/search/embedding.rs b/crates/opencontext-core/src/search/embedding.rs index 457c3d6..cecb18c 100644 --- a/crates/opencontext-core/src/search/embedding.rs +++ b/crates/opencontext-core/src/search/embedding.rs @@ -127,9 +127,10 @@ impl EmbeddingClient { let input_count = texts.len(); // Truncate texts that are too long (most embedding APIs have ~8K token limit) - // Using char count as approximation: ~4 chars per token for English, ~1-2 for Chinese - // Set conservative limit to avoid API silently dropping texts - const MAX_CHARS: usize = 8000; + // Using char count as approximation: ~4 chars per token for English, ~1-2 for CJK/Cyrillic + // nomic-embed-text and similar models have 8192 token limit + // Conservative limit: 2000 chars (safe for all languages including Cyrillic/CJK) + const MAX_CHARS: usize = 2000; let texts: Vec = texts .into_iter() .map(|t| {