Make the embedding model swappable via env for A/B testing
Trialing Qwen3-Embedding-0.6B (1024-dim, instruct-prefixed queries) against nomic required code changes at every hardcoded seam; now it's a config flip plus a reembed_embeddings run. - EMBEDDING_DIM env (default 768) replaces every hardcoded dim check: daily summary / calendar / search / location DAOs, Ollama batch validation, reembed_embeddings - entities gains the dim guard it never had — a wrong-dim vector silently kills dedup/recall (cosine over mismatched lengths is 0), so store None and warn instead - embed_query / embed_document split with EMBED_QUERY_PREFIX / EMBED_DOCUMENT_PREFIX (literal \n expanded): retrieval models treat the two sides differently — nomic wants search_query:/search_document:, Qwen3 wants Instruct:...\nQuery: on queries only. All query-side call sites and all corpus writers now declare their side. - document the contract in CLAUDE.md: change the model or any of these vars → re-run reembed_embeddings or search is garbage Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b1493f5aca
commit
efd05db523
12 files changed
+159
-67
No files matched your search
+13
-10
@@ -189,10 +189,11 @@ impl SearchHistoryDao for SqliteSearchHistoryDao {
|
||||
.expect("Unable to get SearchHistoryDao");
|
||||
|
||||
// Validate embedding dimensions (REQUIRED for searches)
|
||||
if search.embedding.len() != 768 {
|
||||
if search.embedding.len() != crate::ai::embedding_dim() {
|
||||
return Err(anyhow::anyhow!(
|
||||
"Invalid embedding dimensions: {} (expected 768)",
|
||||
search.embedding.len()
|
||||
"Invalid embedding dimensions: {} (expected {})",
|
||||
search.embedding.len(),
|
||||
crate::ai::embedding_dim()
|
||||
));
|
||||
}
|
||||
|
||||
@@ -245,7 +246,7 @@ impl SearchHistoryDao for SqliteSearchHistoryDao {
|
||||
conn.transaction::<_, anyhow::Error, _>(|conn| {
|
||||
for search in searches {
|
||||
// Validate embedding (REQUIRED)
|
||||
if search.embedding.len() != 768 {
|
||||
if search.embedding.len() != crate::ai::embedding_dim() {
|
||||
log::warn!(
|
||||
"Skipping search with invalid embedding dimensions: {}",
|
||||
search.embedding.len()
|
||||
@@ -325,10 +326,11 @@ impl SearchHistoryDao for SqliteSearchHistoryDao {
|
||||
.lock()
|
||||
.expect("Unable to get SearchHistoryDao");
|
||||
|
||||
if query_embedding.len() != 768 {
|
||||
if query_embedding.len() != crate::ai::embedding_dim() {
|
||||
return Err(anyhow::anyhow!(
|
||||
"Invalid query embedding dimensions: {} (expected 768)",
|
||||
query_embedding.len()
|
||||
"Invalid query embedding dimensions: {} (expected {})",
|
||||
query_embedding.len(),
|
||||
crate::ai::embedding_dim()
|
||||
));
|
||||
}
|
||||
|
||||
@@ -406,10 +408,11 @@ impl SearchHistoryDao for SqliteSearchHistoryDao {
|
||||
|
||||
// Step 2: If query embedding provided, rank by semantic similarity
|
||||
if let Some(query_emb) = query_embedding {
|
||||
if query_emb.len() != 768 {
|
||||
if query_emb.len() != crate::ai::embedding_dim() {
|
||||
return Err(anyhow::anyhow!(
|
||||
"Invalid query embedding dimensions: {} (expected 768)",
|
||||
query_emb.len()
|
||||
"Invalid query embedding dimensions: {} (expected {})",
|
||||
query_emb.len(),
|
||||
crate::ai::embedding_dim()
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user