Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
Signed-off-by: Kosuke Morimoto <[email protected]>
  • Loading branch information
kmrmt committed Sep 12, 2024
1 parent 7a36411 commit 07d07ba
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
4 changes: 2 additions & 2 deletions rust/bin/agent/src/handler/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ impl search_server::Search for super::Agent {
&self,
request: tonic::Request<search::Request>,
) -> Result<tonic::Response<search::Response>, Status> {
println!("Recieved a request from {:?}", request.remote_addr());
let req = request.get_ref();
let config = req.config.clone().unwrap();
let hostname = cargo::util::hostname()?;
Expand All @@ -37,7 +36,8 @@ impl search_server::Search for super::Agent {
let err = Error::IncompatibleDimensionSize{ got: req.vector.len(), want: self.s.get_dimension_size()};
let mut err_details = ErrorDetails::new();
err_details.set_error_info(err.to_string(), domain, HashMap::new());
err_details.set_request_info(config.request_id, String::from_utf8(req.encode_to_vec()).unwrap());
let serving_data = "";
err_details.set_request_info(config.request_id, serving_data.to_string());
err_details.set_bad_request(vec![FieldViolation::new("vector dimension size", err.to_string())]);
err_details.set_resource_info(self.resource_type.clone() + "/ngt.Search", "", "", "");
let status = Status::with_error_details(Code::InvalidArgument, "Search API Incombatible Dimension Size detedted", err_details);
Expand Down
28 changes: 22 additions & 6 deletions rust/bin/agent/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
use std::{thread::sleep, time::Duration};

use algorithm::Error;
use anyhow::Result;
use proto::payload::v1::search;
use proto::{payload::v1::search, vald::v1::{search_client::SearchClient, search_server::SearchServer}};
use tonic::transport::Server;

mod handler;

Expand All @@ -37,14 +39,28 @@ impl algorithm::ANN for MockService {

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let addr = "0.0.0.0:8081".parse()?;
let addr = "[::1]:8081".parse().unwrap();

let service = MockService{ dim: 42 };
let agent = handler::Agent::new(service, "agent-ngt", "127.0.0.1", "vald/internal/core/algorithm", "vald-agent");

tonic::transport::Server::builder()
.add_service(proto::core::v1::agent_server::AgentServer::new(agent))
.serve(addr)
.await?;
tokio::spawn(async move {
Server::builder()
.add_service(SearchServer::new(agent))
.serve(addr)
.await
});

sleep(Duration::from_secs(3));

let mut client = SearchClient::connect("http://[::1]:8081").await?;

let cfg = search::Config::default();
let request = tonic::Request::new(search::Request { vector: vec![0.0], config: Some(cfg) });

let response = client.search(request).await?;

println!("RESPONSE={:?}", response);

Ok(())
}

0 comments on commit 07d07ba

Please sign in to comment.