Skip to content

Commit c97eefe

Browse files
committed
refactor: canonicalize vector index path via KinLayout
- Add kindb_vector_index_path() to KinLayout (.kin/kindb/graph.kvec) - Use canonical path in backend, daemon, and snapshot loading - Simplify offline/fallback graph opening
1 parent 5f4abc6 commit c97eefe

3 files changed

Lines changed: 13 additions & 14 deletions

File tree

crates/kin-cli/src/backend.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub fn open_kindb_snapshot(
5555

5656
/// Path where the HNSW vector index is stored alongside the graph snapshot.
5757
pub fn vector_index_path(layout: &kin_core::KinLayout) -> PathBuf {
58-
layout.kindb_dir().join("vector.hnsw")
58+
layout.kindb_vector_index_path()
5959
}
6060

6161
/// Daemon-first graph open: tries the daemon's `/graph/bootstrap` endpoint
@@ -74,9 +74,7 @@ pub async fn open_snapshot_daemon_first(
7474
) -> std::result::Result<kin_db::SnapshotManager, kin_db::KinDbError> {
7575
// Respect explicit offline mode
7676
if std::env::var("KIN_OFFLINE").is_ok() {
77-
let snap = open_kindb_snapshot(layout)?;
78-
load_vector_index_if_exists(&snap, layout);
79-
return Ok(snap);
77+
return open_kindb_snapshot(layout);
8078
}
8179

8280
// Try daemon bootstrap
@@ -87,25 +85,21 @@ pub async fn open_snapshot_daemon_first(
8785
load_vector_index_if_exists(&snap, layout);
8886
Ok(snap)
8987
}
90-
None => {
91-
let snap = open_kindb_snapshot(layout)?;
92-
load_vector_index_if_exists(&snap, layout);
93-
Ok(snap)
94-
}
88+
None => open_kindb_snapshot(layout),
9589
}
9690
}
9791

9892
/// Load the persisted HNSW vector index into the graph if available.
9993
/// Non-fatal: if the file doesn't exist or fails to load, semantic search
10094
/// gracefully returns empty results.
10195
fn load_vector_index_if_exists(snap: &kin_db::SnapshotManager, layout: &kin_core::KinLayout) {
102-
let vi_path = vector_index_path(layout);
103-
if vi_path.exists() {
96+
let path = vector_index_path(layout);
97+
if path.exists() {
10498
let graph = snap.graph();
105-
match graph.load_vector_index(&vi_path) {
99+
match graph.load_vector_index(&path) {
106100
Ok(count) => {
107101
if count > 0 {
108-
tracing::debug!(count, "loaded vector index from disk");
102+
tracing::debug!(count, path = %path.display(), "loaded vector index from disk");
109103
}
110104
}
111105
Err(e) => {

crates/kin-core/src/layout.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ impl KinLayout {
7272
self.kindb_dir().join("graph.kndb")
7373
}
7474

75+
/// `.kin/kindb/graph.kvec` — persisted vector index aligned with the snapshot.
76+
pub fn kindb_vector_index_path(&self) -> PathBuf {
77+
self.kindb_snapshot_path().with_extension("kvec")
78+
}
79+
7580
/// `.kin/kindb/text-index/` — Persistent tantivy text index directory.
7681
pub fn text_index_dir(&self) -> PathBuf {
7782
self.kindb_dir().join("text-index")

crates/kin-daemon/src/daemon.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ pub async fn run(state: DaemonState, config: DaemonConfig) -> Result<()> {
139139
Ok(Ok(count)) if count > 0 => {
140140
info!(count, remaining = pending.saturating_sub(count), "embedded entities");
141141
// Persist vector index after each batch so progress survives restarts.
142-
let vi_path = embed_state.layout.kindb_dir().join("vector.hnsw");
142+
let vi_path = embed_state.layout.kindb_vector_index_path();
143143
if let Err(e) = embed_state.graph.save_vector_index(&vi_path) {
144144
error!(error = %e, "failed to persist vector index");
145145
}

0 commit comments

Comments
 (0)