Skip to content

Commit 36dd853

Browse files
author
Matthijs van Otterdijk
committed
ensure domain exists before writing out hsnw index
1 parent 3a9aa07 commit 36dd853

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

src/indexer.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{
33
openai::{embeddings_for, EmbeddingError},
44
server::Operation,
55
vecmath::{self, Embedding},
6-
vectors::{LoadedVec, VectorStore},
6+
vectors::{Domain, LoadedVec, VectorStore},
77
};
88
use hnsw::{Hnsw, Searcher};
99
use rand_pcg::Lcg128Xsl64;
@@ -89,7 +89,7 @@ enum Op {
8989
}
9090

9191
pub async fn operations_to_point_operations(
92-
domain: &str,
92+
domain: &Domain,
9393
vector_store: &VectorStore,
9494
structs: Vec<Result<Operation, std::io::Error>>,
9595
key: &str,
@@ -114,7 +114,6 @@ pub async fn operations_to_point_operations(
114114
} else {
115115
embeddings_for(key, &strings).await?
116116
};
117-
let domain = vector_store.get_domain(domain)?;
118117
let loaded_vecs = vector_store.add_and_load_vecs(&domain, vecs.iter())?;
119118
let mut new_ops: Vec<PointOperation> = zip(tuples, loaded_vecs)
120119
.map(|((op, _, id), vec)| match op {

src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
200200
let dirpath = Path::new(&directory);
201201
let mut hnsw: HnswIndex = Hnsw::new(OpenAI);
202202
let store = VectorStore::new(dirpath, size);
203+
let resolved_domain = store.get_domain(&domain)?;
203204

204205
let f = File::options().read(true).open(path)?;
205206

@@ -216,7 +217,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
216217
for structs in opstream {
217218
let structs: Vec<_> = structs.collect();
218219
let new_ops =
219-
operations_to_point_operations(&domain.clone(), &store, structs, &key).await?;
220+
operations_to_point_operations(&resolved_domain, &store, structs, &key).await?;
220221
hnsw = start_indexing_from_operations(hnsw, new_ops).unwrap();
221222
}
222223
let index_id = create_index_name(&domain, &commit);

src/server.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -505,16 +505,13 @@ impl Service {
505505
previous,
506506
})
507507
.await;
508+
let domain = self.vector_store.get_domain(&domain)?;
508509
self.set_task_status(task_id.to_string(), TaskStatus::Pending(0.3))
509510
.await;
510511
while let Some(structs) = opstream.next().await {
511-
let new_ops = operations_to_point_operations(
512-
&domain.clone(),
513-
&self.vector_store,
514-
structs,
515-
api_key,
516-
)
517-
.await?;
512+
let new_ops =
513+
operations_to_point_operations(&domain, &self.vector_store, structs, api_key)
514+
.await?;
518515
hnsw = start_indexing_from_operations(hnsw, new_ops)?;
519516
}
520517
self.set_task_status(task_id.to_string(), TaskStatus::Pending(0.8))

0 commit comments

Comments
 (0)