Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion src/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::chunker::{chunk_markdown, split_oversized_chunks};
use crate::config::Config;
use crate::docid::generate_docid;
use crate::graph::extract_wikilink_targets;
use crate::llm::EmbedModel;
use crate::llm::{EmbedModel, ModelDefaults};
use crate::profile::VaultProfile;
use crate::store::{FileRecord, Store};

Expand Down Expand Up @@ -545,6 +545,15 @@ fn run_index_inner(
) -> Result<IndexResult> {
let start = Instant::now();

let defaults = ModelDefaults::default();
let embedding_uri = config
.models
.embed
.as_deref()
.unwrap_or(&defaults.embed_uri);
store.set_meta("embedding_model_uri", embedding_uri)?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Rebuild when the embedding URI changes

When a user changes models.embed to another model with the same output dimension, engraph index can take the non-rebuild path and diff_vault will skip unchanged files, but this line still overwrites embedding_model_uri. engraph status then reports the new model even though existing vectors were produced by the old model, and searches embed queries with the new model against stale embeddings; the CLI also tells users the next index will re-embed the vault at src/main.rs:700. Compare the stored URI before writing it and force a rebuild/reset when it changes.

Useful? React with 👍 / 👎.

store.set_meta("embedding_dim", &embedder.dim().to_string())?;

let cleaned = crate::writer::cleanup_temp_files(vault_path)?;
if cleaned > 0 {
info!(cleaned, "cleaned up incomplete writes from previous run");
Expand Down Expand Up @@ -1159,4 +1168,25 @@ mod tests {
assert_eq!(mentions.len(), 1);
assert_eq!(mentions[0].0, person);
}

#[test]
fn test_index_records_embedding_metadata() {
let vault = TempDir::new().unwrap();
write_file(vault.path(), "note.md", "# Metadata fixture\n");

let store = Store::open_memory().unwrap();
let mut embedder = crate::llm::MockLlm::new(256);
let config = Config::default();

run_index_shared(vault.path(), &config, &store, &mut embedder, false, None).unwrap();

assert_eq!(
store.get_meta("embedding_model_uri").unwrap(),
Some(ModelDefaults::default().embed_uri)
);
assert_eq!(
store.get_meta("embedding_dim").unwrap().as_deref(),
Some("256")
);
}
}
10 changes: 8 additions & 2 deletions src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,13 @@ pub fn run_status(json: bool, data_dir: &Path) -> Result<()> {
// Compute index size on disk (sqlite db file).
let index_size = std::fs::metadata(&db_path).map(|m| m.len()).unwrap_or(0);

let model_name = "all-MiniLM-L6-v2";
let model_uri = store
.get_meta("embedding_model_uri")?
.unwrap_or_else(|| "<unknown>".to_string());
let model_dim = store
.get_meta("embedding_dim")?
.unwrap_or_else(|| "unknown".to_string());
let model_name = format!("{model_uri} (dim {model_dim})");

let config = crate::config::Config::load().unwrap_or_default();
let intelligence = if config.intelligence_enabled() {
Expand All @@ -509,7 +515,7 @@ pub fn run_status(json: bool, data_dir: &Path) -> Result<()> {
let output = format_status(
&stats,
index_size,
model_name,
&model_name,
intelligence,
date_count,
json,
Expand Down