Skip to content

Commit

Permalink
fix: ignore NotReady error for IndexServer
Browse files Browse the repository at this point in the history
  • Loading branch information
wsxiaoys committed Oct 14, 2023
1 parent b3c119d commit 8a2d16f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 9 deletions.
9 changes: 5 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ tokenizers = "0.13.4-rc3"
futures = "0.3.28"
async-stream = "0.3.5"
regex = "1.10.0"
thiserror = "1.0.49"
1 change: 1 addition & 0 deletions crates/tabby/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ axum-streams = { version = "0.9.1", features = ["json"] }
minijinja = { version = "1.0.8", features = ["loader"] }
textdistance = "1.0.2"
regex.workspace = true
thiserror.workspace = true

[target.'cfg(all(target_os="macos", target_arch="aarch64"))'.dependencies]
llama-cpp-bindings = { path = "../llama-cpp-bindings" }
Expand Down
11 changes: 9 additions & 2 deletions crates/tabby/src/serve/completions/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use textdistance::Algorithm;
use tracing::warn;

use super::{Segments, Snippet};
use crate::serve::{completions::languages::get_language, search::IndexServer};
use crate::serve::{
completions::languages::get_language,
search::{IndexServer, IndexServerError},
};

static MAX_SNIPPETS_TO_FETCH: usize = 20;
static MAX_SNIPPET_CHARS_IN_PROMPT: usize = 768;
Expand Down Expand Up @@ -109,7 +112,11 @@ fn collect_snippets(index_server: &IndexServer, language: &str, text: &str) -> V

let serp = match index_server.search(&query_text, MAX_SNIPPETS_TO_FETCH, 0) {
Ok(serp) => serp,
Err(err) => {
Err(IndexServerError::NotReady) => {
// Ignore.
return vec![];
}
Err(IndexServerError::TantivyError(err)) => {
warn!("Failed to search query: {}", err);
return ret;
}
Expand Down
21 changes: 18 additions & 3 deletions crates/tabby/src/serve/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use tantivy::{
schema::Field,
DocAddress, Document, Index, IndexReader,
};
use thiserror::Error;
use tokio::{sync::OnceCell, task, time::sleep};
use tracing::{debug, instrument, log::info};
use utoipa::{IntoParams, ToSchema};
Expand Down Expand Up @@ -198,11 +199,25 @@ impl IndexServer {
}
}

pub fn search(&self, q: &str, limit: usize, offset: usize) -> tantivy::Result<SearchResponse> {
pub fn search(
&self,
q: &str,
limit: usize,
offset: usize,
) -> Result<SearchResponse, IndexServerError> {
if let Some(imp) = self.get_cell() {
imp.search(q, limit, offset)
Ok(imp.search(q, limit, offset)?)
} else {
Err(tantivy::TantivyError::InternalError("Not Ready".to_owned()))
Err(IndexServerError::NotReady)
}
}
}

#[derive(Error, Debug)]
pub enum IndexServerError {
#[error("index not ready")]
NotReady,

#[error("underlying tantivy error")]
TantivyError(#[from] tantivy::TantivyError),
}

0 comments on commit 8a2d16f

Please sign in to comment.