syntax = "proto3";
package topk.data.v1;

import "topk/data/v1/document.proto";
import "topk/data/v1/expr/function.proto";
import "topk/data/v1/expr/logical.proto";
import "topk/data/v1/expr/text.proto";
import "topk/data/v1/value.proto";

message Query {
  repeated Stage stages = 1;
}

message Stage {
  message SelectStage {
    message SelectExpr {
      oneof expr {
        LogicalExpr logical_expr = 1;
        FunctionExpr function_expr = 2;
      }
    }
    map<string, SelectExpr> exprs = 1;
  }

  message FilterStage {
    message FilterExpr {
      oneof expr {
        LogicalExpr logical_expr = 1;
        TextExpr text_expr = 2;
      }
    }
    FilterExpr expr = 1;
  }

  message TopKStage {
    LogicalExpr expr = 1;
    uint64 k = 2;
    bool asc = 3;
  }

  message CountStage {}

  message RerankStage {
    // Model to be used for reranking.
    optional string model = 1;
    // Query rerank against.
    optional string query = 2;
    // Fields to rerank by.
    repeated string fields = 3;
    // TopK multiple.
    optional uint32 topk_multiple = 4;
  }

  oneof stage {
    SelectStage select = 1;
    FilterStage filter = 2;
    TopKStage top_k = 3;
    CountStage count = 4;
    RerankStage rerank = 5;
  }
}
