syntax = "proto3";

package apf.ai.v1;

import "common.proto";
import "google/protobuf/struct.proto";

option csharp_namespace = "Apf.Ai.Grpc.V1";

// Stateless retrieval. The server runs a single SQL query that combines
// vector similarity with the principal's ACL clause — there is no
// retrieval path that bypasses the ACL filter.
service RagService {
  rpc Search(RagSearchRequest) returns (RagSearchResponse);
}

message RagSearchFilters {
  string source = 1;
  string document_id = 2;
}

message RagSearchRequest {
  string query = 1;
  int32 top_k = 2;
  RagSearchFilters filters = 3;
  Principal principal = 4;
}

message Chunk {
  string id = 1;
  string document_id = 2;
  string content = 3;
  string source = 4;
  double score = 5;
  google.protobuf.Struct metadata = 6;
}

message RagSearchResponse {
  repeated Chunk chunks = 1;
  string correlation_id = 2;
}
