syntax = "proto3";

package weaviate.v1;

import "v1/base.proto";
import "v1/base_search.proto";
import "v1/generative.proto";
import "v1/properties.proto";

option go_package = "github.com/weaviate/weaviate/grpc/generated;protocol";
option java_package = "io.weaviate.client.grpc.protocol.v1";
option java_outer_classname = "WeaviateProtoSearchGet";

message SearchRequest {
  //required
  string collection = 1;

  // parameters
  string tenant = 10;
  optional ConsistencyLevel consistency_level = 11;

  // what is returned
  optional PropertiesRequest properties = 20;
  optional MetadataRequest metadata = 21;
  optional GroupBy group_by = 22;

  // affects order and length of results. 0/empty (default value) means disabled
  uint32 limit = 30;
  uint32 offset = 31;
  uint32 autocut = 32;
  string after = 33;
  // protolint:disable:next REPEATED_FIELD_NAMES_PLURALIZED
  repeated SortBy sort_by = 34;

  // matches/searches for objects
  optional Filters filters = 40;
  optional Hybrid hybrid_search = 41;
  optional BM25 bm25_search = 42;
  optional NearVector near_vector = 43;
  optional NearObject near_object = 44;
  optional NearTextSearch near_text = 45;
  optional NearImageSearch near_image = 46;
  optional NearAudioSearch near_audio = 47;
  optional NearVideoSearch near_video = 48;
  optional NearDepthSearch near_depth = 49;
  optional NearThermalSearch near_thermal = 50;
  optional NearIMUSearch near_imu = 51;

  optional GenerativeSearch generative = 60;
  optional Rerank rerank = 61;

  bool uses_123_api = 100 [deprecated = true];
  bool uses_125_api = 101 [deprecated = true];
  bool uses_127_api = 102; 
}

message GroupBy {
  // currently only supports one entry (eg just properties, no refs). But might
  // be extended in the future.
  // protolint:disable:next REPEATED_FIELD_NAMES_PLURALIZED
  repeated string path = 1;
  int32 number_of_groups = 2;
  int32 objects_per_group = 3;
}

message SortBy {
  bool ascending = 1;
  // currently only supports one entry (eg just properties, no refs). But the
  // weaviate datastructure already has paths in it and this makes it easily
  // extendable in the future
  // protolint:disable:next REPEATED_FIELD_NAMES_PLURALIZED
  repeated string path = 2;
}

message MetadataRequest {
  bool uuid = 1;
  bool vector = 2;
  bool creation_time_unix = 3;
  bool last_update_time_unix = 4;
  bool distance = 5;
  bool certainty = 6;
  bool score = 7;
  bool explain_score = 8;
  bool is_consistent = 9;
  repeated string vectors = 10;
}

message PropertiesRequest {
  repeated string non_ref_properties = 1;
  repeated RefPropertiesRequest ref_properties = 2;
  repeated ObjectPropertiesRequest object_properties = 3;
  bool return_all_nonref_properties = 11;
}

message ObjectPropertiesRequest {
  string prop_name = 1;
  repeated string primitive_properties = 2;
  repeated ObjectPropertiesRequest object_properties = 3;
}

message RefPropertiesRequest {
  string reference_property = 1;
  PropertiesRequest properties = 2;
  MetadataRequest metadata = 3;
  string target_collection = 4;
}

message Rerank {
  string property = 1;
  optional string query = 2;
}

message SearchReply {
  float took = 1;
  repeated SearchResult results = 2;
  optional string generative_grouped_result = 3 [deprecated = true];
  repeated GroupByResult group_by_results = 4;
  optional GenerativeResult generative_grouped_results = 5;
}

message RerankReply {
  double score = 1;
}

message GroupByResult {
  string name = 1;
  float min_distance = 2;
  float max_distance = 3;
  int64 number_of_objects = 4;
  repeated SearchResult objects = 5;
  optional RerankReply rerank = 6;
  optional GenerativeReply generative = 7 [deprecated = true];
  optional GenerativeResult generative_result = 8;
}

message SearchResult {
  PropertiesResult properties = 1;
  MetadataResult metadata = 2;
  optional GenerativeResult generative = 3;
}


message MetadataResult {
  string id = 1;
  // protolint:disable:next REPEATED_FIELD_NAMES_PLURALIZED
  repeated float vector = 2 [deprecated = true];
  int64 creation_time_unix = 3;
  bool creation_time_unix_present = 4;
  int64 last_update_time_unix = 5;
  bool last_update_time_unix_present = 6;
  float distance = 7;
  bool distance_present = 8;
  float certainty = 9;
  bool certainty_present = 10;
  float score = 11;
  bool score_present = 12;
  string explain_score = 13;
  bool explain_score_present = 14;
  optional bool is_consistent = 15;
  string generative = 16 [deprecated = true];
  bool generative_present = 17 [deprecated = true];
  bool is_consistent_present = 18;
  bytes vector_bytes = 19;
  bytes id_as_bytes = 20;
  double rerank_score = 21;
  bool rerank_score_present = 22;
  repeated Vectors vectors = 23;
}

message PropertiesResult {
  reserved 1;  // was non_ref_properties
  repeated RefPropertiesResult ref_props = 2;
  string target_collection = 3;
  MetadataResult metadata = 4;
  reserved 5;  // was number_array_properties
  reserved 6;  // was int_array_properties
  reserved 7;  // was text_array_properties
  reserved 8;  // was boolean_array_properties
  reserved 9;  // was object_properties
  reserved 10;  // was object_array_properties
  Properties non_ref_props = 11;
  bool ref_props_requested = 12;
}

message RefPropertiesResult {
  repeated PropertiesResult properties = 1;
  string prop_name = 2;
}
