syntax = "proto3";
package nnext;

message GetCollectionInfoRequest {
  string collection_name = 1; // Name of the collection
}

message ListCollectionsRequest {
}

message CollectionDescription {
  string name = 1; // Name of the collection
}

message GetCollectionInfoResponse {
  CollectionInfo result = 1;
  double time = 2; // Time spent to process
}

message ListCollectionsResponse {
  repeated CollectionDescription collections = 1;
  double time = 2; // Time spent to process
}

enum Distance {
  UnknownDistance = 0;
  Cosine = 1;
  Euclid = 2;
  Dot = 3;
}

enum CollectionStatus {
  UnknownCollectionStatus = 0;
  Green = 1; // All segments are ready
  Yellow = 2; // Optimization in process
  Red = 3; // Something went wrong
}

enum PayloadSchemaType {
  UnknownType = 0;
  Keyword = 1;
  Integer = 2;
  Float = 3;
  Geo = 4;
}

message OptimizerStatus {
  bool ok = 1;
  string error = 2;
}

message HnswConfigDiff {
  /*
  Number of edges per node in the index graph. Larger the value - more accurate the search, more space required.
   */
  optional uint64 m = 1;
  /*
  Number of neighbours to consider during the index building. Larger the value - more accurate the search, more time required to build index.
  */
  optional uint64 ef_construct = 2;
  /*
  Minimal size (in KiloBytes) of vectors for additional payload-based indexing.
  If payload chunk is smaller than `full_scan_threshold` additional indexing won't be used -
  in this case full-scan search should be preferred by query planner and additional indexing is not required.
  Note: 1Kb = 1 vector of size 256
  */
  optional uint64 full_scan_threshold = 3;
  /*
  Number of parallel threads used for background index building. If 0 - auto selection.
   */
  optional uint64 max_indexing_threads = 4;
}

message WalConfigDiff {
  optional uint64 wal_capacity_mb = 1; // Size of a single WAL block file
  optional uint64 wal_segments_ahead = 2; // Number of segments to create in advance
}

message OptimizersConfigDiff {
  /*
  The minimal fraction of deleted vectors in a segment, required to perform segment optimization
   */
  optional double deleted_threshold = 1;
  /*
  The minimal number of vectors in a segment, required to perform segment optimization
   */
  optional uint64 vacuum_min_vector_number = 2;
  /*
  Target amount of segments optimizer will try to keep.
  Real amount of segments may vary depending on multiple parameters:

   - Amount of stored points.
   - Current write RPS.

  It is recommended to select default number of segments as a factor of the number of search threads,
  so that each segment would be handled evenly by one of the threads.
  */
  optional uint64 default_segment_number = 3;
  /*
  Do not create segments larger this size (in KiloBytes).
  Large segments might require disproportionately long indexation times,
  therefore it makes sense to limit the size of segments.

  If indexation speed have more priority for your - make this parameter lower.
  If search speed is more important - make this parameter higher.
  Note: 1Kb = 1 vector of size 256
  */
  optional uint64 max_segment_size = 4;
  /*
  Maximum size (in KiloBytes) of vectors to store in-memory per segment.
  Segments larger than this threshold will be stored as read-only memmaped file.
  To enable memmap storage, lower the threshold
  Note: 1Kb = 1 vector of size 256
  */
  optional uint64 memmap_threshold = 5;
  /*
  Maximum size (in KiloBytes) of vectors allowed for plain index.
  Default value based on https://github.com/google-research/google-research/blob/master/scann/docs/algorithms.md
  Note: 1Kb = 1 vector of size 256
  */
  optional uint64 indexing_threshold = 6;
  /*
  Interval between forced flushes.
  */
  optional uint64 flush_interval_sec = 7;
  /*
  Max number of threads, which can be used for optimization. If 0 - `NUM_CPU - 1` will be used
  */
  optional uint64 max_optimization_threads = 8;
}

message CreateCollection {
  string collection_name = 1; // Name of the collection
  uint64 vector_size = 2; // Size of the vectors
  Distance distance = 3; // Distance function used for comparing vectors
  optional HnswConfigDiff hnsw_config = 4; // Configuration of vector index
  optional WalConfigDiff wal_config = 5; // Configuration of the Write-Ahead-Log
  optional OptimizersConfigDiff optimizers_config = 6; // Configuration of the optimizers
  optional uint32 shard_number = 7; // Number of shards in the collection, default = 1
  optional bool on_disk_payload = 8; // If true - point's payload will not be stored in memory
  optional uint64 timeout = 9; // Wait timeout for operation commit in seconds, if not specified - default value will be supplied
}

message UpdateCollection {
  string collection_name = 1; // Name of the collection
  optional OptimizersConfigDiff optimizers_config = 2; // New configuration parameters for the collection
  optional uint64 timeout = 3; // Wait timeout for operation commit in seconds, if not specified - default value will be supplied
}

message DeleteCollection {
  string collection_name = 1; // Name of the collection
  optional uint64 timeout = 2; // Wait timeout for operation commit in seconds, if not specified - default value will be supplied
}

message CollectionOperationResponse {
  bool result = 1; // if operation made changes
  double time = 2; // Time spent to process
}

message CollectionParams {
  uint64 vector_size = 1; // Size of the vectors
  Distance distance = 2; // Distance function used for comparing vectors
  uint32 shard_number = 3; // Number of shards in collection
  bool on_disk_payload = 4; // If true - point's payload will not be stored in memory
}

message CollectionConfig {
  CollectionParams params = 1; // Collection parameters
  HnswConfigDiff hnsw_config = 2; // Configuration of vector index
  OptimizersConfigDiff optimizer_config = 3; // Configuration of the optimizers
  WalConfigDiff wal_config = 4; // Configuration of the Write-Ahead-Log
}

message PayloadSchemaInfo {
  PayloadSchemaType data_type = 1; // Field data type
}

message CollectionInfo {
  CollectionStatus status = 1; // operating condition of the collection
  OptimizerStatus optimizer_status = 2; // status of collection optimizers
  uint64 vectors_count = 3; // number of vectors in the collection
  uint64 segments_count = 4; // Number of independent segments
  uint64 disk_data_size = 5 [deprecated = true]; // Used disk space
  uint64 ram_data_size = 6 [deprecated = true]; // Used RAM (not implemented)
  CollectionConfig config = 7; // Configuration
  map<string, PayloadSchemaInfo> payload_schema = 8; // Collection data types
  uint64 points_count = 9; // number of points in the collection
  optional uint64 indexed_vectors_count = 10; // number of indexed vectors in the collection.
}

message ChangeAliases {
  repeated AliasOperations actions = 1; // List of actions
  optional uint64 timeout = 2; // Wait timeout for operation commit in seconds, if not specified - default value will be supplied
}

message AliasOperations {
  oneof action {
    CreateAlias create_alias = 1;
    RenameAlias rename_alias = 2;
    DeleteAlias delete_alias = 3;
  }
}

message CreateAlias {
  string collection_name = 1; // Name of the collection
  string alias_name = 2; // New name of the alias
}

message RenameAlias {
  string old_alias_name = 1; // Name of the alias to rename
  string new_alias_name = 2; // Name of the alias
}

message DeleteAlias {
  string alias_name = 1; // Name of the alias
}
