syntax = "proto3";

package chroma;
option go_package = "github.com/chroma-core/chroma/go/pkg/proto/coordinatorpb";

import "chromadb/proto/chroma.proto";
import "google/protobuf/empty.proto";

message CreateDatabaseRequest {
  string id = 1;
  string name = 2;
  string tenant = 3;
}

message CreateDatabaseResponse {
  reserved 1;
  reserved "status";
}

message GetDatabaseRequest {
  string name = 1;
  string tenant = 2;
}

message GetDatabaseResponse {
  Database database = 1;
  reserved 2;
  reserved "status";
}

message CreateTenantRequest {
  string name = 2; // Names are globally unique
}

message CreateTenantResponse {
  reserved 1;
  reserved "status";
}

message GetTenantRequest {
  string name = 1;
}

message GetTenantResponse {
  Tenant tenant = 1;
  reserved 2;
  reserved "status";
}


message CreateSegmentRequest {
  Segment segment = 1;
}

message CreateSegmentResponse {
  reserved 1;
  reserved "status";
}

message DeleteSegmentRequest {
  string id = 1;
  string collection = 2;
}

message DeleteSegmentResponse {
  reserved 1;
  reserved "status";
}

message GetSegmentsRequest {
  optional string id = 1;
  optional string type = 2;
  optional SegmentScope scope = 3;
  string collection = 4; // Collection ID
}

message GetSegmentsResponse {
  repeated Segment segments = 1;
  reserved 2;
  reserved "status";
}


message UpdateSegmentRequest {
  string id = 1;
  string collection = 4;
  oneof metadata_update {
    UpdateMetadata metadata = 6;
    bool reset_metadata = 7;
  }
}

message UpdateSegmentResponse {
  reserved 1;
  reserved "status";
}

message CreateCollectionRequest {
  string id = 1;
  string name = 2;
  string configuration_json_str = 3;
  optional UpdateMetadata metadata = 4;
  optional int32 dimension = 5;
  optional bool get_or_create = 6;
  string tenant = 7;
  string database = 8;
  // When segments are set, then the collection and segments will be created as
  // a single atomic operation.
  repeated Segment segments = 9;  // Optional.
}

message CreateCollectionResponse {
  Collection collection = 1;
  bool created = 2;
  reserved 3;
  reserved "status";
}

message DeleteCollectionRequest {
  string id = 1;
  string tenant = 2;
  string database = 3;
  repeated string segment_ids = 4;
}

message DeleteCollectionResponse {
  reserved 1;
  reserved "status";
}

message GetCollectionsRequest {
  optional string id = 1;
  optional string name = 2;
  string tenant = 4;
  string database = 5;
  optional int32 limit = 6;
  optional int32 offset = 7;
}

message GetCollectionsResponse {
  repeated Collection collections = 1;
  reserved 2;
  reserved "status";
}

message GetCollectionWithSegmentsRequest {
  string id = 1;
}

message GetCollectionWithSegmentsResponse {
  Collection collection = 1;
  repeated Segment segments = 2;
}

message CheckCollectionsRequest {
  repeated string collection_ids = 1;
}

message CheckCollectionsResponse {
  repeated bool deleted = 1;
}

message UpdateCollectionRequest {
  string id = 1;
  optional string name = 3;
  optional int32 dimension = 4;
  oneof metadata_update {
    UpdateMetadata metadata = 5;
    bool reset_metadata = 6;
  }
}

message UpdateCollectionResponse {
  reserved 1;
  reserved "status";
}

message ResetStateResponse {
  reserved 1;
  reserved "status";
}

message GetLastCompactionTimeForTenantRequest {
  repeated string tenant_id = 1;
}

message TenantLastCompactionTime {
  string tenant_id = 1;
  int64 last_compaction_time = 2;
}

message GetLastCompactionTimeForTenantResponse {
  repeated TenantLastCompactionTime tenant_last_compaction_time = 1;
}

message SetLastCompactionTimeForTenantRequest {
  TenantLastCompactionTime tenant_last_compaction_time = 1;
}

message FlushSegmentCompactionInfo {
  string segment_id = 1;
  map<string,FilePaths> file_paths = 2;
}

message FlushCollectionCompactionRequest {
  string tenant_id = 1;
  string collection_id = 2;
  int64 log_position = 3;
  int32 collection_version = 4;
  repeated FlushSegmentCompactionInfo segment_compaction_info = 5;
}

message FlushCollectionCompactionResponse {
  string collection_id = 1;
  int32 collection_version = 2;
  int64 last_compaction_time = 3;
}

service SysDB {
  rpc CreateDatabase(CreateDatabaseRequest) returns (CreateDatabaseResponse) {}
  rpc GetDatabase(GetDatabaseRequest) returns (GetDatabaseResponse) {}
  rpc CreateTenant(CreateTenantRequest) returns (CreateTenantResponse) {}
  rpc GetTenant(GetTenantRequest) returns (GetTenantResponse) {}
  rpc CreateSegment(CreateSegmentRequest) returns (CreateSegmentResponse) {}
  rpc DeleteSegment(DeleteSegmentRequest) returns (DeleteSegmentResponse) {}
  rpc GetSegments(GetSegmentsRequest) returns (GetSegmentsResponse) {}
  rpc UpdateSegment(UpdateSegmentRequest) returns (UpdateSegmentResponse) {}
  rpc CreateCollection(CreateCollectionRequest) returns (CreateCollectionResponse) {}
  rpc DeleteCollection(DeleteCollectionRequest) returns (DeleteCollectionResponse) {}
  rpc GetCollections(GetCollectionsRequest) returns (GetCollectionsResponse) {}
  rpc GetCollectionWithSegments(GetCollectionWithSegmentsRequest) returns (GetCollectionWithSegmentsResponse) {}
  rpc CheckCollections(CheckCollectionsRequest) returns (CheckCollectionsResponse) {}
  rpc UpdateCollection(UpdateCollectionRequest) returns (UpdateCollectionResponse) {}
  rpc ResetState(google.protobuf.Empty) returns (ResetStateResponse) {}
  rpc GetLastCompactionTimeForTenant(GetLastCompactionTimeForTenantRequest) returns (GetLastCompactionTimeForTenantResponse) {}
  rpc SetLastCompactionTimeForTenant(SetLastCompactionTimeForTenantRequest) returns (google.protobuf.Empty) {}
  rpc FlushCollectionCompaction(FlushCollectionCompactionRequest) returns (FlushCollectionCompactionResponse) {}
}
