Skip to content

Commit 93b6f53

Browse files
fix(grpc): return payload in get_point rpc response (#65)
1 parent 38542b9 commit 93b6f53

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

crates/grpc/src/service.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use crate::interceptors;
55
use crate::service::vectordb::{ContentType, Uuid};
66
use crate::utils::log_rpc;
77
use crate::{constants::SIMILARITY_PROTOBUFF_MAP, utils::ServerEndpoint};
8-
use defs::Payload;
98
use tonic::{Request, Response, Status, service::InterceptorLayer, transport::Server};
109
use tracing::{Level, event};
1110
use uuid::Uuid as UuidCrate;
@@ -57,7 +56,7 @@ impl VectorDb for VectorDBService {
5756

5857
let point_id = self.vector_db.insert(
5958
dense_vector.unwrap().values,
60-
Payload {
59+
defs::Payload {
6160
content_type: payload_type,
6261
content: payload_content,
6362
},
@@ -87,6 +86,14 @@ impl VectorDb for VectorDBService {
8786
// return error if not found
8887
let point = point_opt.ok_or(Status::not_found(format!("point not found: {}", point_id)))?;
8988

89+
let payload = point.payload.map(|p| vectordb::Payload {
90+
content_type: match p.content_type {
91+
defs::ContentType::Text => ContentType::Text as i32,
92+
defs::ContentType::Image => ContentType::Image as i32,
93+
},
94+
content: p.content,
95+
});
96+
9097
Ok(Response::new(Point {
9198
id: Some(PointId {
9299
id: Some(Uuid {
@@ -96,7 +103,7 @@ impl VectorDb for VectorDBService {
96103
vector: Some(DenseVector {
97104
values: point.vector.unwrap_or_default(),
98105
}),
99-
payload: None,
106+
payload,
100107
}))
101108
}
102109

crates/grpc/src/tests.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crate::constants::AUTHORIZATION_HEADER_KEY;
22
use crate::service::vectordb::vector_db_client::VectorDbClient;
3-
use crate::service::vectordb::{DenseVector, InsertVectorRequest, Payload, PointId, SearchRequest};
3+
use crate::service::vectordb::{
4+
ContentType, DenseVector, InsertVectorRequest, Payload, PointId, SearchRequest,
5+
};
46
use crate::service::{VectorDBService, run_server};
57
use crate::utils::ServerEndpoint;
68
use api::DbConfig;
@@ -95,7 +97,10 @@ async fn test_insert_vector_rpc() {
9597
vector: Some(DenseVector {
9698
values: test_vec.clone(),
9799
}),
98-
payload: Some(Payload::default()),
100+
payload: Some(Payload {
101+
content_type: ContentType::Text as i32,
102+
content: "test".to_string(),
103+
}),
99104
});
100105
append_test_auth_header(&mut request, TEST_AUTH_BEARER_TOKEN);
101106

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

124+
// payload assertions
125+
let payload = point.payload.unwrap();
126+
assert_eq!(payload.content_type, ContentType::Text as i32);
127+
assert_eq!(payload.content, "test");
128+
119129
// insert a new vector with mismatched dimensions
120130
let mut request = tonic::Request::new(InsertVectorRequest {
121131
vector: Some(DenseVector {

0 commit comments

Comments
 (0)