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

message FieldSpec {
  FieldType data_type = 1;
  bool required = 2;
  FieldIndex index = 3;
}

message FieldIndex {
  oneof index {
    KeywordIndex keyword_index = 1;
    VectorIndex vector_index = 2;
    SemanticIndex semantic_index = 3;
  }
}

// Field data types

message FieldType {
  oneof data_type {
    FieldTypeText text = 1;
    FieldTypeInteger integer = 2;
    FieldTypeFloat float = 3;
    FieldTypeBoolean boolean = 4;
    FieldTypeF32Vector f32_vector = 5;
    FieldTypeU8Vector u8_vector = 6;
    FieldTypeBinaryVector binary_vector = 7;
    FieldTypeBytes bytes = 8;
  }
}

message FieldTypeText {}
message FieldTypeInteger {}
message FieldTypeFloat {}
message FieldTypeBoolean {}

message FieldTypeF32Vector {
  uint32 dimension = 1;
}

message FieldTypeU8Vector {
  uint32 dimension = 1;
}

message FieldTypeBinaryVector {
  uint32 dimension = 1;
}

message FieldTypeBytes {}

// Keyword index specification

message KeywordIndex {
  // Index type
  KeywordIndexType index_type = 1;
}

enum KeywordIndexType {
  // Unspecified
  KEYWORD_INDEX_TYPE_UNSPECIFIED = 0;
  // Keyword index
  KEYWORD_INDEX_TYPE_TEXT = 1;
  // KEYWORD_INDEX_TYPE_CODE = 2;
  // KEYWORD_INDEX_TYPE_LOG = 3;
}

// Vector index specification

message VectorIndex {
  // Distance metric
  VectorDistanceMetric metric = 1;
}

enum VectorDistanceMetric {
  // Unspecified
  VECTOR_DISTANCE_METRIC_UNSPECIFIED = 0;
  // Cosine distance
  VECTOR_DISTANCE_METRIC_COSINE = 1;
  // Euclidean distance
  VECTOR_DISTANCE_METRIC_EUCLIDEAN = 2;
  // Dot product
  VECTOR_DISTANCE_METRIC_DOT_PRODUCT = 3;
  // Hamming distance
  VECTOR_DISTANCE_METRIC_HAMMING = 4;
}

// Semantic index specification

enum EmbeddingDataType {
  // Unspecified
  EMBEDDING_DATA_TYPE_UNSPECIFIED = 0;
  // Raw float32
  EMBEDDING_DATA_TYPE_F32 = 1;
  // Scalar quantized uint8
  EMBEDDING_DATA_TYPE_U8 = 2;
  // Binary quantized uint8
  EMBEDDING_DATA_TYPE_BINARY = 3;
}

message SemanticIndex {
  // Model to be used for embedding text to vectors.
  optional string model = 1;
  // Data type of the embedding vectors.
  optional EmbeddingDataType embedding_type = 2;
}
