Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions crates/grpc/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::interceptors;
use crate::service::vectordb::{ContentType, Uuid};
use crate::utils::log_rpc;
use crate::{constants::SIMILARITY_PROTOBUFF_MAP, utils::ServerEndpoint};
use defs::Payload;
use tonic::{Request, Response, Status, service::InterceptorLayer, transport::Server};
use tracing::{Level, event};
use uuid::Uuid as UuidCrate;
Expand Down Expand Up @@ -57,7 +56,7 @@ impl VectorDb for VectorDBService {

let point_id = self.vector_db.insert(
dense_vector.unwrap().values,
Payload {
defs::Payload {
content_type: payload_type,
content: payload_content,
},
Expand Down Expand Up @@ -87,6 +86,14 @@ impl VectorDb for VectorDBService {
// return error if not found
let point = point_opt.ok_or(Status::not_found(format!("point not found: {}", point_id)))?;

let payload = point.payload.map(|p| vectordb::Payload {
content_type: match p.content_type {
defs::ContentType::Text => ContentType::Text as i32,
defs::ContentType::Image => ContentType::Image as i32,
},
content: p.content,
});

Ok(Response::new(Point {
id: Some(PointId {
id: Some(Uuid {
Expand All @@ -96,7 +103,7 @@ impl VectorDb for VectorDBService {
vector: Some(DenseVector {
values: point.vector.unwrap_or_default(),
}),
payload: None,
payload,
}))
}

Expand Down
14 changes: 12 additions & 2 deletions crates/grpc/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::constants::AUTHORIZATION_HEADER_KEY;
use crate::service::vectordb::vector_db_client::VectorDbClient;
use crate::service::vectordb::{DenseVector, InsertVectorRequest, Payload, PointId, SearchRequest};
use crate::service::vectordb::{
ContentType, DenseVector, InsertVectorRequest, Payload, PointId, SearchRequest,
};
use crate::service::{VectorDBService, run_server};
use crate::utils::ServerEndpoint;
use api::DbConfig;
Expand Down Expand Up @@ -95,7 +97,10 @@ async fn test_insert_vector_rpc() {
vector: Some(DenseVector {
values: test_vec.clone(),
}),
payload: Some(Payload::default()),
payload: Some(Payload {
content_type: ContentType::Text as i32,
content: "test".to_string(),
}),
});
append_test_auth_header(&mut request, TEST_AUTH_BEARER_TOKEN);

Expand All @@ -116,6 +121,11 @@ async fn test_insert_vector_rpc() {
let point = resp.unwrap().into_inner();
assert_eq!(point.vector.unwrap().values, test_vec);

// payload assertions
let payload = point.payload.unwrap();
assert_eq!(payload.content_type, ContentType::Text as i32);
assert_eq!(payload.content, "test");

// insert a new vector with mismatched dimensions
let mut request = tonic::Request::new(InsertVectorRequest {
vector: Some(DenseVector {
Expand Down
Loading