From 722ae37a44435d702a5242d7249fca30cad28bbd Mon Sep 17 00:00:00 2001 From: sandikodev Date: Sat, 4 Apr 2026 23:27:29 +0700 Subject: [PATCH] fix(knowledge): show platform-accurate valid options in embedding type error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On Linux ARM64, EmbeddingType::Best is not available (candle is excluded via cfg). When a user passes --index-type best on that platform, from_str returns None and the error message was: Invalid embedding type 'best'. Valid options are: fast, best This is misleading — 'best' is listed as valid but is not accepted. Use cfg to build the valid options string at compile time so Linux ARM64 shows only 'fast', while other platforms show 'fast, best'. Fixes #3139 --- crates/chat-cli/src/util/knowledge_store.rs | 36 ++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/crates/chat-cli/src/util/knowledge_store.rs b/crates/chat-cli/src/util/knowledge_store.rs index 064b8b8b40..ed6c0e2500 100644 --- a/crates/chat-cli/src/util/knowledge_store.rs +++ b/crates/chat-cli/src/util/knowledge_store.rs @@ -328,7 +328,14 @@ impl KnowledgeStore { Some(s) => match EmbeddingType::from_str(s) { Some(et) => Some(et), None => { - return Err(format!("Invalid embedding type '{}'. Valid options are: fast, best", s)); + #[cfg(all(target_os = "linux", target_arch = "aarch64"))] + let valid = "fast"; + #[cfg(not(all(target_os = "linux", target_arch = "aarch64")))] + let valid = "fast, best"; + return Err(format!( + "Invalid embedding type '{}'. Valid options are: {}", + s, valid + )); }, }, None => None, @@ -624,4 +631,31 @@ mod tests { // Verify directory structure assert!(base_dir.to_string_lossy().contains("knowledge_bases")); } + + /// Regression test for #3139: on Linux ARM64, the error message for an invalid + /// embedding type must not list "best" as a valid option since it is unavailable. + #[test] + fn invalid_embedding_type_error_does_not_mention_best_on_linux_arm() { + use semantic_search_client::embedding::EmbeddingType; + + // Simulate what knowledge_store does when from_str returns None + let invalid = "best"; + let result = EmbeddingType::from_str(invalid); + + #[cfg(all(target_os = "linux", target_arch = "aarch64"))] + { + // On Linux ARM64, "best" must not be accepted + assert!(result.is_none(), "'best' should not be valid on Linux ARM64"); + // And the error message must only list "fast" + let valid = "fast"; + let msg = format!("Invalid embedding type '{}'. Valid options are: {}", invalid, valid); + assert!(!msg.contains("best"), "error message must not mention 'best' on Linux ARM64"); + } + + #[cfg(not(all(target_os = "linux", target_arch = "aarch64")))] + { + // On other platforms, "best" is valid + assert!(result.is_some(), "'best' should be valid on this platform"); + } + } }