Skip to content

Commit

Permalink
feat: is_indexed, overrwrite collections
Browse files Browse the repository at this point in the history
  • Loading branch information
Anush008 committed Jul 21, 2023
1 parent 800e983 commit f2f415a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ pub trait RepositoryEmbeddingsDB {
) -> Result<RepositoryFilePaths>;

async fn get_file_paths(&self, repository: &Repository) -> Result<RepositoryFilePaths>;

async fn is_indexed(&self, repository: &Repository) -> Result<bool>;
}
7 changes: 7 additions & 0 deletions src/db/qdrant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ pub struct QdrantDB {
#[async_trait]
impl RepositoryEmbeddingsDB for QdrantDB {
async fn insert_repo_embeddings(&self, repo: RepositoryEmbeddings) -> Result<()> {
if self.client.has_collection(&repo.repo_id).await? {
self.client.delete_collection(&repo.repo_id).await?;
}
self.client
.create_collection(&CreateCollection {
collection_name: repo.repo_id.clone(),
Expand Down Expand Up @@ -104,6 +107,10 @@ impl RepositoryEmbeddingsDB for QdrantDB {
file_paths,
})
}

async fn is_indexed(&self, repository: &Repository) -> Result<bool> {
self.client.has_collection(repository.to_string()).await
}
}

impl QdrantDB {
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ async fn main() -> std::io::Result<()> {
.route("/", web::get().to(HttpResponse::Ok))
.service(routes::embeddings)
.service(routes::query)
.service(routes::repo)
.app_data(web::Data::new(model.clone()))
.app_data(web::Data::new(db.clone()))
})
Expand Down
18 changes: 17 additions & 1 deletion src/routes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ use crate::constants::SSE_CHANNEL_BUFFER_SIZE;
use crate::conversation::{Conversation, Query};
use crate::github::fetch_repo_files;
use crate::{db::RepositoryEmbeddingsDB, github::Repository};
use actix_web::web::Query as ActixQuery;
use actix_web::HttpResponse;
use actix_web::{
post,
get, post,
web::{self, Json},
Responder,
};
Expand Down Expand Up @@ -70,3 +72,17 @@ async fn query(

rx
}

#[get("/collection")]
async fn repo(
data: ActixQuery<Repository>,
db: web::Data<Arc<QdrantDB>>,
) -> actix_web::Result<impl Responder> {
let is_indexed = db.is_indexed(&data.into_inner()).await.unwrap_or_default();

if is_indexed {
Ok(HttpResponse::Ok())
} else {
Ok(HttpResponse::NotFound())
}
}

0 comments on commit f2f415a

Please sign in to comment.