Skip to content

Commit f99744d

Browse files
Add API key for vetcor provider
1 parent c637f71 commit f99744d

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

src/indexer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ pub async fn operations_to_point_operations(
9393
structs: Vec<Result<Operation, std::io::Error>>,
9494
key: &str,
9595
) -> Vec<PointOperation> {
96+
// Should not unwrap here -
9697
let ops: Vec<Operation> = structs.into_iter().map(|ro| ro.unwrap()).collect();
9798
let tuples: Vec<(Op, String, String)> = ops
9899
.iter()

src/server.rs

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ impl Service {
376376
commit: String,
377377
previous: Option<String>,
378378
task_id: String,
379+
api_key: String,
379380
) -> Result<(), StartIndexError> {
380381
let content_endpoint = self.content_endpoint.clone();
381382
if let Some(content_endpoint) = content_endpoint {
@@ -393,7 +394,7 @@ impl Service {
393394
.chunks(100);
394395
let (id, hnsw) = self
395396
.process_operation_chunks(
396-
opstream, domain, commit, previous, &index_id, &task_id,
397+
opstream, domain, commit, previous, &index_id, &task_id, &api_key,
397398
)
398399
.await;
399400
self.set_index(id, hnsw.into()).await;
@@ -445,6 +446,7 @@ impl Service {
445446
previous: Option<String>,
446447
index_id: &str,
447448
task_id: &str,
449+
api_key: &str,
448450
) -> (String, HnswIndex) {
449451
let id = create_index_name(&domain, &commit);
450452
let mut hnsw = self
@@ -461,7 +463,7 @@ impl Service {
461463
&domain.clone(),
462464
&self.vector_store,
463465
structs,
464-
&self.api_key,
466+
api_key,
465467
)
466468
.await;
467469
hnsw = start_indexing_from_operations(hnsw, new_ops).unwrap();
@@ -482,13 +484,34 @@ impl Service {
482484
previous,
483485
}) => {
484486
let task_id = Service::generate_task();
485-
self.set_task_status(task_id.clone(), TaskStatus::Pending(0.0))
486-
.await;
487-
match self.start_indexing(domain, commit, previous, task_id.clone()) {
488-
Ok(()) => Ok(Response::builder().body(task_id.into()).unwrap()),
489-
Err(e) => Ok(Response::builder()
487+
let headers = req.headers();
488+
let openai_key = headers.get("TERMINUSDB_VECTOR_API_KEY");
489+
match openai_key {
490+
Some(openai_key) => {
491+
let openai_key = String::from_utf8(openai_key.as_bytes().to_vec()).unwrap();
492+
self.set_task_status(task_id.clone(), TaskStatus::Pending(0.0))
493+
.await;
494+
match self.start_indexing(
495+
domain,
496+
commit,
497+
previous,
498+
task_id.clone(),
499+
openai_key,
500+
) {
501+
Ok(()) => Ok(Response::builder().body(task_id.into()).unwrap()),
502+
Err(e) => Ok(Response::builder()
503+
.status(400)
504+
.body(e.to_string().into())
505+
.unwrap()),
506+
}
507+
}
508+
None => Ok(Response::builder()
490509
.status(400)
491-
.body(e.to_string().into())
510+
.body(
511+
"No API key supplied in header (TERMINUSDB_VECTOR_API_KEY)"
512+
.to_string()
513+
.into(),
514+
)
492515
.unwrap()),
493516
}
494517
}

0 commit comments

Comments
 (0)