database.proto 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482
  1. // Smartbotic Database Service
  2. // Document-oriented storage with persistence and replication
  3. syntax = "proto3";
  4. package smartbotic.databasepb;
  5. // Error code range: 6000-6999 for Database errors
  6. // 6000: Generic database error
  7. // 6001: Collection not found
  8. // 6002: Document not found
  9. // 6003: Document already exists
  10. // 6004: Version conflict
  11. // 6005: Invalid query
  12. // 6006: File not found
  13. // 6007: File too large
  14. // 6008: Encryption error
  15. // 6009: Replication error
  16. // 6010: Version not found
  17. // ===== Main Database Service =====
  18. // v2.12.0 - REFUSAL DETAIL. Any refused write may carry trailing metadata
  19. // `sbdb-error-detail-bin`: UTF-8 JSON (gRPC base64s a -bin value on the wire)
  20. // that says WHY in a form a program can branch on, whether the refusal came as
  21. // an error status or in-band (status OK, success=false). Keys, all optional:
  22. //
  23. // reason "unique_violation" | "missing_parent" | "delete_restricted"
  24. // | "read_only" | "memory_pressure" | "view_write"
  25. // | "not_found" | "version_conflict" | "invalid_increment"
  26. // | "duplicate_id" (2.12.1) | "file_too_large"
  27. // | "mime_type_not_allowed" (2.12.3)
  28. // code the gRPC status code number - present for in-band
  29. // refusals, whose status is OK
  30. // fields the field(s) concerned: the constrained field(s) of a
  31. // unique violation, the reference field of a missing
  32. // parent, the field an increment could not be applied to
  33. // values object, field -> the value that collided / was refused
  34. // conflicting_id unique violation: the document already holding the value
  35. // relation missing parent: the relation that refused the write
  36. // current_version version conflict: the document's current version
  37. //
  38. // Absent on a server older than 2.12.0. The reason exists because a status
  39. // code alone is ambiguous: FAILED_PRECONDITION means a missing parent, a
  40. // restricted delete AND read-only mode.
  41. service DatabaseService {
  42. // Document operations
  43. rpc Insert(InsertRequest) returns (InsertResponse);
  44. rpc Get(GetRequest) returns (GetResponse);
  45. rpc Update(UpdateRequest) returns (UpdateResponse);
  46. rpc Upsert(UpsertRequest) returns (UpsertResponse);
  47. rpc Delete(DeleteRequest) returns (DeleteResponse);
  48. rpc PatchDocument(PatchDocumentRequest) returns (PatchDocumentResponse);
  49. rpc Exists(ExistsRequest) returns (ExistsResponse);
  50. // Version history operations
  51. rpc GetVersionHistory(GetVersionHistoryRequest) returns (GetVersionHistoryResponse);
  52. rpc GetDocumentVersion(GetDocumentVersionRequest) returns (GetDocumentVersionResponse);
  53. rpc RestoreVersion(RestoreVersionRequest) returns (RestoreVersionResponse);
  54. rpc RestoreToDate(RestoreToDateRequest) returns (RestoreToDateResponse);
  55. // Batch operations
  56. rpc BatchInsert(BatchInsertRequest) returns (BatchInsertResponse);
  57. rpc BatchGet(BatchGetRequest) returns (BatchGetResponse);
  58. rpc BatchDelete(BatchDeleteRequest) returns (BatchDeleteResponse);
  59. // Query operations
  60. rpc Find(FindRequest) returns (FindResponse);
  61. rpc Count(CountRequest) returns (CountResponse);
  62. rpc SimilaritySearch(SimilaritySearchRequest) returns (SimilaritySearchResponse);
  63. // v2.13.0 - stream one collection out, documents plus (optionally) their
  64. // stored vectors. See ExportRequest for the contract.
  65. rpc ExportCollection(ExportRequest) returns (stream ExportChunk);
  66. // Set operations (Redis compatibility)
  67. rpc SetAdd(SetAddRequest) returns (SetAddResponse);
  68. rpc SetRemove(SetRemoveRequest) returns (SetRemoveResponse);
  69. rpc SetMembers(SetMembersRequest) returns (SetMembersResponse);
  70. rpc SetIsMember(SetIsMemberRequest) returns (SetIsMemberResponse);
  71. // Collection management
  72. rpc CreateCollection(CreateCollectionRequest) returns (CreateCollectionResponse);
  73. rpc DropCollection(DropCollectionRequest) returns (DropCollectionResponse);
  74. rpc ListCollections(ListCollectionsRequest) returns (ListCollectionsResponse);
  75. rpc GetCollectionInfo(GetCollectionInfoRequest) returns (GetCollectionInfoResponse);
  76. // v2.3 — Project management. Projects are top-level namespaces over
  77. // collections. The "default" project is implicit and always exists.
  78. rpc ListProjects(ListProjectsRequest) returns (ListProjectsResponse);
  79. rpc CreateProject(CreateProjectRequest) returns (CreateProjectResponse);
  80. rpc DropProject(DropProjectRequest) returns (DropProjectResponse);
  81. // View management
  82. rpc CreateView(CreateViewRequest) returns (CreateViewResponse);
  83. rpc DropView(DropViewRequest) returns (DropViewResponse);
  84. rpc ListViews(ListViewsRequest) returns (ListViewsResponse);
  85. rpc GetViewInfo(GetViewInfoRequest) returns (GetViewInfoResponse);
  86. // v2.11.0 T6b — relation (referential integrity) management. Admin-only:
  87. // `_relations` is a system collection and a relation names another
  88. // collection's schema, so declaring one is not ordinary per-collection
  89. // write access.
  90. rpc CreateRelation(CreateRelationRequest) returns (CreateRelationResponse);
  91. rpc DropRelation(DropRelationRequest) returns (DropRelationResponse);
  92. rpc ListRelations(ListRelationsRequest) returns (ListRelationsResponse);
  93. rpc GetRelationInfo(GetRelationInfoRequest) returns (GetRelationInfoResponse);
  94. // v2.11.0 T5 — "what would happen if I deleted this?" without deleting
  95. // it. Read-only and gated as an ordinary per-collection read, not admin.
  96. rpc DescribeDelete(DescribeDeleteRequest) returns (DescribeDeleteResponse);
  97. // v2.11.0 T7 — "does this relation's reverse index actually match live
  98. // data?" A relation declared over a collection that already had rows
  99. // before v2.11.0 T7 shipped (or one whose sub-db was lost/restored from
  100. // an older snapshot) can carry postings for parent ids that no longer
  101. // exist. This walks the reverse index and probes each parent id;
  102. // mutates nothing. ⚠ Cost is proportional to the number of DISTINCT
  103. // parents referenced, not collection size, but on a very large child
  104. // collection that is still a full index walk - treat this as an
  105. // operator/migration tool, not something to call on a hot path.
  106. // Admin-only, like the other relation-management RPCs above (NOT gated
  107. // as a per-collection read on `child`, despite being read-only and
  108. // reporting facts about that collection's data): answering requires
  109. // resolving the relation first to learn its `child`, and gating after
  110. // that lookup would make a nonexistent-relation response distinguishable
  111. // from an existing-but-unauthorized one - a probe-able existence oracle,
  112. // which is exactly what gate() exists to prevent elsewhere.
  113. rpc CheckRelation(CheckRelationRequest) returns (CheckRelationResponse);
  114. // Collection configuration
  115. rpc ConfigureCollection(ConfigureCollectionRequest) returns (ConfigureCollectionResponse);
  116. // v2.9.0 — secondary indexes. Declaration is explicit per collection: an
  117. // index costs write throughput, and indexing every field would build useless
  118. // ones (a low-cardinality field like a status enum is slower through an
  119. // index than a scan).
  120. rpc CreateIndex(CreateIndexRequest) returns (CreateIndexResponse);
  121. rpc DropIndex(DropIndexRequest) returns (DropIndexResponse);
  122. rpc ListIndexes(ListIndexesRequest) returns (ListIndexesResponse);
  123. // v2.10.0 — the distinct values an indexed field holds, with row counts.
  124. // Answered from the index, one step per distinct value rather than per row.
  125. rpc GetIndexValues(GetIndexValuesRequest) returns (GetIndexValuesResponse);
  126. rpc GetCollectionConfig(GetCollectionConfigRequest) returns (GetCollectionConfigResponse);
  127. rpc MigrateCollectionTimestamps(MigrateCollectionTimestampsRequest) returns (MigrateCollectionTimestampsResponse);
  128. // File operations
  129. rpc UploadFile(stream FileChunk) returns (UploadFileResponse);
  130. rpc DownloadFile(DownloadFileRequest) returns (stream FileChunk);
  131. rpc DeleteFile(DeleteFileRequest) returns (DeleteFileResponse);
  132. rpc GetFileInfo(GetFileInfoRequest) returns (FileInfo);
  133. rpc ListFiles(ListFilesRequest) returns (ListFilesResponse);
  134. rpc SetFileTtl(SetFileTtlRequest) returns (SetFileTtlResponse);
  135. // Event subscription
  136. rpc Subscribe(SubscribeRequest) returns (stream DatabaseEvent);
  137. // Health and stats
  138. rpc HealthCheck(HealthCheckRequest) returns (HealthCheckResponse);
  139. rpc GetStats(GetStatsRequest) returns (GetStatsResponse);
  140. rpc GetMemoryStats(GetMemoryStatsRequest) returns (GetMemoryStatsResponse);
  141. // Read-only runtime state control
  142. rpc SetReadOnly(SetReadOnlyRequest) returns (SetReadOnlyResponse);
  143. rpc GetReadOnlyStatus(GetReadOnlyStatusRequest) returns (GetReadOnlyStatusResponse);
  144. }
  145. // ===== Replication Service =====
  146. service DatabaseReplication {
  147. // Bidirectional streaming for real-time sync
  148. rpc SyncStream(stream ReplicationMessage) returns (stream ReplicationMessage);
  149. // Pull missed entries (for recovery)
  150. rpc GetEntriesSince(GetEntriesRequest) returns (stream ReplicationEntry);
  151. // Get current node state
  152. rpc GetNodeState(GetNodeStateRequest) returns (NodeState);
  153. }
  154. // ===== Document Types =====
  155. message Document {
  156. string id = 1;
  157. string collection = 2;
  158. bytes data = 3; // JSON-encoded document data
  159. uint64 version = 4;
  160. uint64 created_at = 5; // Timestamp in milliseconds
  161. uint64 updated_at = 6;
  162. uint64 expires_at = 7; // 0 = no expiration
  163. string node_id = 8; // Origin node for replication
  164. bool encrypted = 9;
  165. repeated string encrypted_fields = 10;
  166. string created_by = 11; // User ID who created the document
  167. string updated_by = 12; // User ID who last updated the document
  168. // v2.13.0 - the stored vector as raw float32 little-endian bytes. Set ONLY
  169. // when the request asked for vectors (GetRequest/FindRequest
  170. // include_vector, ExportRequest include_vectors) and a vector is stored.
  171. bytes vector = 13;
  172. }
  173. // ===== Document Operations =====
  174. message InsertRequest {
  175. string collection = 1;
  176. bytes data = 2; // JSON document
  177. string id = 3; // Optional, auto-generated if empty
  178. uint32 ttl_seconds = 4; // 0 = use collection default
  179. string actor = 5; // User ID performing the operation (for audit)
  180. }
  181. message InsertResponse {
  182. string id = 1;
  183. uint64 version = 2;
  184. }
  185. message GetRequest {
  186. string collection = 1;
  187. string id = 2;
  188. bool include_vector = 3; // v2.13.0 - fill Document.vector
  189. }
  190. message GetResponse {
  191. Document document = 1;
  192. bool found = 2;
  193. }
  194. message UpdateRequest {
  195. string collection = 1;
  196. string id = 2;
  197. bytes data = 3;
  198. uint64 expected_version = 4; // 0 = no version check (force update)
  199. string actor = 5; // User ID performing the operation (for audit)
  200. // v2.8.0 — change the document's expiry as part of the update.
  201. //
  202. // `optional` gives three distinct meanings, which a plain uint32 cannot:
  203. // absent -> leave the existing expiry alone (the default, and what an
  204. // update did implicitly once it stopped WIPING the expiry)
  205. // 0 -> clear the expiry: the document becomes permanent
  206. // N -> expire N seconds from now
  207. //
  208. // Before this, ttl_seconds existed only on Insert/Upsert/BatchInsert, so
  209. // changing a TTL meant rewriting the whole document via upsert.
  210. optional uint32 ttl_seconds = 6;
  211. }
  212. message UpdateResponse {
  213. uint64 new_version = 1;
  214. bool success = 2;
  215. string error = 3;
  216. // v2.12.0 - when success=false, the gRPC status code this refusal WOULD
  217. // carry: NOT_FOUND, ABORTED (version conflict), FAILED_PRECONDITION
  218. // (read-only), RESOURCE_EXHAUSTED (memory pressure), INVALID_ARGUMENT
  219. // (write to a view). These refusals stay in-band (status OK) so clients
  220. // older than 2.12.0 see exactly what they always saw; 0 from an older
  221. // server. The trailing `sbdb-error-detail-bin` adds the reason.
  222. int32 error_code = 4;
  223. }
  224. message UpsertRequest {
  225. string collection = 1;
  226. bytes data = 2;
  227. string id = 3;
  228. uint32 ttl_seconds = 4;
  229. string actor = 5; // User ID performing the operation (for audit)
  230. }
  231. message UpsertResponse {
  232. string id = 1;
  233. uint64 version = 2;
  234. bool inserted = 3; // true if inserted, false if updated
  235. }
  236. message DeleteRequest {
  237. string collection = 1;
  238. string id = 2;
  239. // v2.12.0 - who is deleting, as `actor` is on every other write. Reported
  240. // on the resulting DatabaseEvent (and on the events of any documents a
  241. // relation cascade deletes or nulls because of it). Not stored: the
  242. // document is gone, and its last version in history keeps the updated_by
  243. // of whoever last WROTE it, which is not who deleted it.
  244. string actor = 3;
  245. }
  246. message DeleteResponse {
  247. bool deleted = 1;
  248. }
  249. message PatchDocumentRequest {
  250. string collection = 1;
  251. string id = 2;
  252. bytes patch_json = 3; // JSON fields to merge into existing document
  253. string actor = 4; // User ID performing the operation (for audit)
  254. // v2.8.0 — same three-way semantics as UpdateRequest.ttl_seconds: absent
  255. // leaves the expiry alone, 0 clears it, N sets N seconds from now.
  256. optional uint32 ttl_seconds = 5;
  257. // v2.12.0 - apply only if the document is still at this version: a
  258. // conditional PARTIAL update. updateIfVersion replaces the whole body, so a
  259. // caller that only wants to change one field ("claim this task") would
  260. // have to write back everything it read, reverting any field a concurrent
  261. // writer changed meanwhile. A mismatch is refused with status ABORTED,
  262. // reason "version_conflict" and the current version in the detail.
  263. // Absent = unconditional, as before.
  264. optional uint64 expected_version = 6;
  265. // v2.12.0 - ATOMIC INCREMENT. A JSON object of field -> number to add, in
  266. // the same locked read-modify-write as the merge, so concurrent increments
  267. // never lose an update. Dotted paths descend objects (creating them).
  268. // - an absent or null field counts as 0;
  269. // - integer + integer stays an integer (overflow is refused), anything
  270. // else is a double;
  271. // - a non-numeric stored value, a non-numeric delta, or a field that
  272. // patch_json also sets is refused with INVALID_ARGUMENT, reason
  273. // "invalid_increment", and the field in the detail.
  274. // Nothing is written when any increment is refused. patch_json may be
  275. // empty when only incrementing. The new values come back in
  276. // PatchDocumentResponse.incremented_json.
  277. bytes increments_json = 7;
  278. }
  279. message PatchDocumentResponse {
  280. uint64 new_version = 1;
  281. bool success = 2;
  282. string error = 3;
  283. // v2.12.0 - as UpdateResponse.error_code.
  284. int32 error_code = 4;
  285. // v2.12.0 - JSON object, field -> value AFTER the increments, for every
  286. // field in increments_json. Empty when there were none.
  287. bytes incremented_json = 5;
  288. }
  289. message ExistsRequest {
  290. string collection = 1;
  291. string id = 2;
  292. }
  293. message ExistsResponse {
  294. bool exists = 1;
  295. }
  296. // ===== Version History Operations =====
  297. message DocumentVersionEntry {
  298. uint64 version = 1;
  299. bytes data = 2; // JSON-encoded document data at this version
  300. uint64 timestamp = 3; // When this version was created (updatedAt)
  301. string updated_by = 4;
  302. bool encrypted = 5;
  303. repeated string encrypted_fields = 6;
  304. }
  305. message GetVersionHistoryRequest {
  306. string collection = 1;
  307. string id = 2;
  308. uint32 limit = 3; // 0 = all versions
  309. uint32 offset = 4;
  310. }
  311. message GetVersionHistoryResponse {
  312. repeated DocumentVersionEntry versions = 1;
  313. uint64 current_version = 2; // 0 if document is deleted
  314. uint64 total_count = 3;
  315. bool document_deleted = 4;
  316. }
  317. message GetDocumentVersionRequest {
  318. string collection = 1;
  319. string id = 2;
  320. uint64 version = 3;
  321. }
  322. message GetDocumentVersionResponse {
  323. DocumentVersionEntry version_entry = 1;
  324. bool found = 2;
  325. }
  326. message RestoreVersionRequest {
  327. string collection = 1;
  328. string id = 2;
  329. uint64 version = 3; // Version number to restore
  330. string actor = 4; // User performing the restore
  331. }
  332. message RestoreVersionResponse {
  333. uint64 new_version = 1; // The newly created version number
  334. bool success = 2;
  335. string error = 3;
  336. }
  337. message RestoreToDateRequest {
  338. string collection = 1;
  339. string id = 2;
  340. uint64 timestamp = 3; // Find version active at this time (ms since epoch)
  341. string actor = 4;
  342. }
  343. message RestoreToDateResponse {
  344. uint64 restored_version = 1; // Which old version was restored from
  345. uint64 new_version = 2; // The newly created version number
  346. bool success = 3;
  347. string error = 4;
  348. }
  349. // ===== Batch Operations =====
  350. message BatchInsertRequest {
  351. string collection = 1;
  352. repeated BatchInsertItem items = 2;
  353. string actor = 3; // User ID performing the operation (for audit)
  354. }
  355. message BatchInsertItem {
  356. bytes data = 1;
  357. string id = 2;
  358. uint32 ttl_seconds = 3;
  359. }
  360. message BatchInsertResponse {
  361. repeated string ids = 1;
  362. uint32 success_count = 2;
  363. uint32 error_count = 3;
  364. }
  365. message BatchGetRequest {
  366. string collection = 1;
  367. repeated string ids = 2;
  368. }
  369. message BatchGetResponse {
  370. repeated Document documents = 1;
  371. }
  372. message BatchDeleteRequest {
  373. string collection = 1;
  374. repeated string ids = 2;
  375. string actor = 3; // v2.12.0 - as DeleteRequest.actor, for every id
  376. }
  377. message BatchDeleteResponse {
  378. uint64 deleted_count = 1;
  379. // v2.12.0 - the ids actually deleted, in request order. An id that is
  380. // absent here did not exist. If the call fails partway (a relation
  381. // refuses one id), the status is an error and no response is delivered:
  382. // ids before it may already be gone - re-read to learn which.
  383. repeated string deleted_ids = 2;
  384. }
  385. // ===== Query Operations =====
  386. message FindRequest {
  387. string collection = 1;
  388. repeated Filter filters = 2;
  389. Sort sort = 3;
  390. uint32 limit = 4; // Default 100
  391. uint32 offset = 5;
  392. repeated string projection = 6; // Fields to include (empty = all)
  393. bool include_vector = 7; // v2.13.0 - fill Document.vector on each result
  394. }
  395. message Filter {
  396. string field = 1;
  397. FilterOp op = 2;
  398. bytes value = 3; // JSON-encoded value
  399. }
  400. enum FilterOp {
  401. FILTER_OP_UNSPECIFIED = 0;
  402. FILTER_OP_EQ = 1;
  403. FILTER_OP_NE = 2;
  404. FILTER_OP_GT = 3;
  405. FILTER_OP_GTE = 4;
  406. FILTER_OP_LT = 5;
  407. FILTER_OP_LTE = 6;
  408. FILTER_OP_IN = 7;
  409. FILTER_OP_CONTAINS = 8;
  410. FILTER_OP_EXISTS = 9;
  411. FILTER_OP_REGEX = 10;
  412. FILTER_OP_SEARCH = 11; // Full-text search across ID and string fields
  413. }
  414. message Sort {
  415. string field = 1;
  416. bool descending = 2;
  417. }
  418. message FindResponse {
  419. repeated Document documents = 1;
  420. uint64 total_count = 2;
  421. bool has_more = 3;
  422. // WAL fallback metrics (for queries that include evicted documents)
  423. bool used_wal_fallback = 4; // True if WAL was scanned for evicted docs
  424. uint32 memory_match_count = 5; // Documents matched from memory
  425. uint32 wal_match_count = 6; // Documents matched from WAL
  426. uint64 memory_search_micros = 7; // Time spent searching memory (µs)
  427. uint64 wal_search_micros = 8; // Time spent loading/searching WAL (µs)
  428. }
  429. message CountRequest {
  430. string collection = 1;
  431. repeated Filter filters = 2;
  432. }
  433. message CountResponse {
  434. uint64 count = 1;
  435. }
  436. // ===== Export (v2.13.0) =====
  437. //
  438. // One collection, never a project: the unit is a collection named exactly as
  439. // every other call names one, so a caller whose tenancy is a collection-name
  440. // prefix cannot be handed another tenant's rows. Gated as an ordinary READ of
  441. // that collection (column masks and row predicates apply), not admin.
  442. //
  443. // The stream is: one header, then row batches, then one trailer.
  444. // - One stream is one LMDB read transaction: an exact snapshot, rows in id
  445. // order, none skipped or repeated. header.rows_at_snapshot counts the rows
  446. // the stream will send if it completes, so rows_sent == rows_at_snapshot
  447. // checks it.
  448. // - Resuming with after_id = trailer.last_id starts a NEW snapshot strictly
  449. // after that id: it never repeats a row, but can miss one inserted during
  450. // the gap with an id that sorts before the cursor.
  451. // - A stream ends early (complete=false, last_id set) when it reaches the
  452. // server's time cap (header.max_stream_seconds) - that is the resume case.
  453. // - A row larger than the server's send limit ends the stream with
  454. // RESOURCE_EXHAUSTED, reason row_too_large, conflicting_id = that row; the
  455. // rows before it were sent. It is never skipped silently.
  456. // - A stream that ends without a trailer did not complete. Treat it as
  457. // failed; a client must never read a stream without a trailer as whole.
  458. // - A restored row gets FRESH metadata: insert stamps _created_at,
  459. // _updated_at, _version and _created_by itself. The originals are in each
  460. // exported Document; keep them there, or copy them into your own field
  461. // before importing if you need them as data.
  462. message ExportRequest {
  463. string collection = 1;
  464. // Include each row's vector (Document.vector) and its vector_state.
  465. // Refused with INVALID_ARGUMENT (reason no_vector_index) on a collection
  466. // with vector_dimension 0, which cannot hold vectors.
  467. bool include_vectors = 2;
  468. string after_id = 3; // resume cursor; empty = from the start
  469. uint32 batch_rows = 4; // rows per ExportRows; 0 = default; clamped, never refused
  470. }
  471. enum VectorState {
  472. VECTOR_STATE_UNSPECIFIED = 0; // include_vectors was false
  473. VECTOR_STATE_PRESENT = 1; // vector stored; Document.vector holds it
  474. VECTOR_STATE_NONE = 2; // written without a vector
  475. VECTOR_STATE_MISSING = 3; // written WITH a vector, and its entry is gone
  476. VECTOR_STATE_UNKNOWN = 4; // no entry, and the row predates the marker (pre-2.13.0)
  477. }
  478. message ExportHeader {
  479. string collection = 1;
  480. uint32 vector_dimension = 2;
  481. string vector_dtype = 3; // "float32-le"
  482. uint64 rows_at_snapshot = 4;
  483. uint32 batch_rows_cap = 5; // the most rows a batch holds (requested, clamped); a batch also closes at 8 MB, so it may hold fewer
  484. uint32 max_stream_seconds = 6;
  485. }
  486. message ExportRow {
  487. Document document = 1; // same shape as a Get result
  488. VectorState vector_state = 2;
  489. }
  490. message ExportRows {
  491. repeated ExportRow rows = 1;
  492. }
  493. message ExportTrailer {
  494. uint64 rows_sent = 1;
  495. string last_id = 2; // id of the last row sent; the resume cursor
  496. bool complete = 3; // true only when the end of the collection was reached
  497. }
  498. message ExportChunk {
  499. oneof chunk {
  500. ExportHeader header = 1;
  501. ExportRows rows = 2;
  502. ExportTrailer trailer = 3;
  503. }
  504. }
  505. message SimilaritySearchRequest {
  506. string collection = 1;
  507. repeated float query_vector = 2;
  508. uint32 top_k = 3;
  509. float min_score = 4;
  510. }
  511. message SimilaritySearchResponse {
  512. repeated SimilarityResult results = 1;
  513. }
  514. message SimilarityResult {
  515. string id = 1;
  516. float score = 2;
  517. bytes data = 3;
  518. }
  519. // ===== Set Operations =====
  520. message SetAddRequest {
  521. string collection = 1;
  522. string set_id = 2;
  523. string member = 3;
  524. }
  525. message SetAddResponse {
  526. bool added = 1; // false if already exists
  527. }
  528. message SetRemoveRequest {
  529. string collection = 1;
  530. string set_id = 2;
  531. string member = 3;
  532. }
  533. message SetRemoveResponse {
  534. bool removed = 1;
  535. }
  536. message SetMembersRequest {
  537. string collection = 1;
  538. string set_id = 2;
  539. }
  540. message SetMembersResponse {
  541. repeated string members = 1;
  542. }
  543. message SetIsMemberRequest {
  544. string collection = 1;
  545. string set_id = 2;
  546. string member = 3;
  547. }
  548. message SetIsMemberResponse {
  549. bool is_member = 1;
  550. }
  551. // ===== Collection Management =====
  552. message CreateCollectionRequest {
  553. string name = 1;
  554. CollectionOptions options = 2;
  555. }
  556. message CollectionOptions {
  557. bool auto_create_id = 1;
  558. uint32 default_ttl_seconds = 2;
  559. bool encrypted = 3;
  560. repeated string sensitive_fields = 4;
  561. uint32 max_versions = 5; // Max version history per document (0 = unlimited)
  562. uint32 vector_dimension = 6; // Dimension of vectors stored in this collection (0 = not a vector collection)
  563. // NEW in v1.7.0 — eviction priority for the collection.
  564. // UNSPECIFIED is treated as NORMAL for backward compatibility.
  565. MemoryPriority memory_priority = 7;
  566. }
  567. enum MemoryPriority {
  568. MEMORY_PRIORITY_UNSPECIFIED = 0; // treated as NORMAL
  569. MEMORY_PRIORITY_LOW = 1;
  570. MEMORY_PRIORITY_NORMAL = 2;
  571. MEMORY_PRIORITY_HIGH = 3;
  572. }
  573. message CreateCollectionResponse {
  574. bool created = 1;
  575. }
  576. message DropCollectionRequest {
  577. string name = 1;
  578. }
  579. message DropCollectionResponse {
  580. bool dropped = 1;
  581. }
  582. message ListCollectionsRequest {
  583. // v2.8.0 — restrict the listing to one project namespace, mirroring
  584. // ListViewsRequest. Empty lists every project (operator/CLI use); clients
  585. // always set it, so a workspace never sees another workspace's collection
  586. // names. A collection name is information about the shape of someone else's
  587. // data even when its contents are unreachable.
  588. string project = 1;
  589. }
  590. message ListCollectionsResponse {
  591. repeated string names = 1;
  592. }
  593. message GetCollectionInfoRequest {
  594. string name = 1;
  595. }
  596. message GetCollectionInfoResponse {
  597. CollectionInfo info = 1;
  598. bool found = 2;
  599. }
  600. // What a collection IS: its creation-time options and its size.
  601. //
  602. // Settings changeable after creation are NOT here - timestamp_precision,
  603. // versioning_enabled and relations_enforced are read with GetCollectionConfig
  604. // (see CollectionConfig), which always populates all three on a reply. Their
  605. // absence from this message does not mean they cannot be read.
  606. message CollectionInfo {
  607. string name = 1;
  608. uint64 document_count = 2;
  609. uint64 size_bytes = 3;
  610. CollectionOptions options = 4;
  611. uint64 created_at = 5;
  612. uint64 updated_at = 6;
  613. uint32 vector_dimension = 7; // Dimension of vectors stored in this collection (0 = not a vector collection)
  614. }
  615. // ===== Project Management (v2.3) =====
  616. //
  617. // Projects are top-level namespaces over collections. Collections live
  618. // inside a project; wire-form "my_app:users" addresses collection "users"
  619. // in project "my_app", bare "users" addresses ("default", "users"). The
  620. // "default" project is implicit and always present.
  621. //
  622. // Stage F ships the RPC surface backed by a filesystem-only placeholder
  623. // (`<dataDir>/projects/<name>/env/`). Stage B replaces the placeholder
  624. // with the real ProjectStore-backed implementation.
  625. message ListProjectsRequest {}
  626. message ListProjectsResponse {
  627. // Alphabetical. Always includes "default".
  628. repeated string projects = 1;
  629. }
  630. message CreateProjectRequest {
  631. string name = 1;
  632. }
  633. message CreateProjectResponse {
  634. // true = newly created, false = already existed (idempotent) OR validation error.
  635. bool created = 1;
  636. // Populated on validation failure (e.g. invalid name). Empty on success
  637. // and on the idempotent "already existed" path.
  638. string error = 2;
  639. }
  640. message DropProjectRequest {
  641. string name = 1;
  642. }
  643. message DropProjectResponse {
  644. bool dropped = 1;
  645. // Populated when the drop is refused — e.g. name == "default",
  646. // unknown project, or filesystem error.
  647. string error = 2;
  648. }
  649. // ===== File Operations =====
  650. message FileChunk {
  651. oneof content {
  652. FileMetadata metadata = 1; // First chunk includes metadata
  653. bytes data = 2; // Subsequent chunks are data
  654. }
  655. }
  656. message FileMetadata {
  657. string id = 1; // Set by server on upload response
  658. string name = 2;
  659. string mime_type = 3;
  660. uint64 size = 4;
  661. string file_type = 5; // "plugin", "document", "generated"
  662. string related_id = 6; // plugin_id, conversation_id, etc.
  663. map<string, string> metadata = 7; // Custom metadata
  664. bool is_public = 8; // Visibility flag
  665. // v2.6.0 — owning project. Empty means "default", matching the rule for
  666. // bare collection names. Files are namespaced so that per-project access
  667. // policy has something to attach to.
  668. string project = 9;
  669. // v2.8.0 — relative time-to-live in seconds, applied at upload. Converted
  670. // once to an absolute expiry server-side, so a file's lifetime does not
  671. // restart when it is read or on restart.
  672. //
  673. // `optional` is load-bearing: ABSENT means "inherit the configured default
  674. // for this file type", while an explicitly SET 0 means "never expire" and
  675. // overrides that default. A plain uint32 cannot express the difference,
  676. // which would make it impossible to opt one file out of a retention policy.
  677. optional uint32 ttl_seconds = 10;
  678. }
  679. message UploadFileResponse {
  680. string id = 1;
  681. uint64 size = 2;
  682. string checksum = 3; // SHA-256
  683. bool deduplicated = 4; // True if blob already existed
  684. }
  685. message DownloadFileRequest {
  686. string id = 1;
  687. string project = 2; // v2.6.0 — empty means "default"
  688. }
  689. message DeleteFileRequest {
  690. string id = 1;
  691. string project = 2; // v2.6.0 — empty means "default"
  692. }
  693. message DeleteFileResponse {
  694. bool deleted = 1;
  695. }
  696. message GetFileInfoRequest {
  697. string id = 1;
  698. string project = 2; // v2.6.0 — empty means "default"
  699. }
  700. message FileInfo {
  701. string id = 1;
  702. string name = 2;
  703. string mime_type = 3;
  704. uint64 size = 4;
  705. string file_type = 5;
  706. string related_id = 6;
  707. string checksum = 7;
  708. uint64 created_at = 8;
  709. map<string, string> metadata = 9;
  710. bool is_public = 10; // Visibility flag
  711. uint32 ref_count = 11; // Blob reference count (informational)
  712. string project = 12; // v2.6.0 — owning project
  713. uint64 expires_at = 13; // v2.8.0 — absolute expiry ms, 0 = never
  714. }
  715. message ListFilesRequest {
  716. string file_type = 1; // Filter by type (optional)
  717. string related_id = 2; // Filter by related ID (optional)
  718. uint32 limit = 3;
  719. uint32 offset = 4;
  720. string checksum = 5; // Filter by checksum (for dedup queries)
  721. string name = 6; // Filter by exact filename (optional)
  722. string project = 7; // v2.6.0 — empty means "default"
  723. }
  724. // v2.8.0 — change the expiry of a file that is already stored. A file's TTL was
  725. // otherwise fixed at upload.
  726. message SetFileTtlRequest {
  727. string id = 1;
  728. string project = 2; // empty means "default"
  729. // Absent is invalid here - the call exists to change the expiry, so it must
  730. // say what to. 0 clears the expiry (keep indefinitely); N expires the file N
  731. // seconds from now.
  732. uint32 ttl_seconds = 3;
  733. }
  734. message SetFileTtlResponse {
  735. bool updated = 1; // false if no such file in that project
  736. uint64 expires_at = 2; // the resulting absolute expiry, 0 = never
  737. }
  738. message ListFilesResponse {
  739. repeated FileInfo files = 1;
  740. uint64 total_count = 2;
  741. bool has_more = 3;
  742. }
  743. // ===== Event Subscription =====
  744. message SubscribeRequest {
  745. repeated string collections = 1; // Empty = all collections
  746. repeated string patterns = 2; // Glob patterns (e.g., "assistants:*")
  747. bool include_data = 3; // Include document data in events
  748. }
  749. message DatabaseEvent {
  750. EventType type = 1;
  751. string collection = 2;
  752. string document_id = 3;
  753. uint64 timestamp = 4;
  754. string node_id = 5;
  755. bytes data = 6; // JSON document (if include_data)
  756. // v2.12.0 - who caused this change: the `actor` the write or delete
  757. // request carried. Empty when the request carried none, and for changes
  758. // the database makes itself (TTL expiry). Sent whether or not
  759. // include_data is set.
  760. //
  761. // For a document a relation cascade deleted or nulled, it is the actor of
  762. // the delete that triggered the cascade - the cascade is that caller's
  763. // doing, not whoever last wrote the child.
  764. //
  765. // This is what makes a write-triggered-write loop guard possible: a
  766. // subscriber that reacts to events by writing can tag its own writes and
  767. // recognise them here. Before this an event said nothing about its
  768. // origin; insert/update provenance had to be read back from version
  769. // history after the fact (racing any later write), and a delete's was not
  770. // recorded anywhere.
  771. string actor = 7;
  772. }
  773. enum EventType {
  774. EVENT_UNKNOWN = 0;
  775. EVENT_INSERT = 1;
  776. EVENT_UPDATE = 2;
  777. EVENT_DELETE = 3;
  778. EVENT_EXPIRE = 4;
  779. EVENT_INVALIDATE = 5;
  780. // NEW in v1.7.0 — memory-pressure observability events.
  781. EVENT_MEMORY_PRESSURE_HIGH = 6; // Emitted when pressure reaches hard threshold
  782. EVENT_MEMORY_EVICTION_BURST = 7; // Emitted when eviction runs a large burst
  783. }
  784. // ===== Replication =====
  785. message ReplicationEntry {
  786. uint64 sequence = 1;
  787. uint64 global_timestamp = 2;
  788. string node_id = 3;
  789. OperationType op = 4;
  790. string collection = 5;
  791. string document_id = 6;
  792. uint64 document_version = 7;
  793. bytes data = 8;
  794. }
  795. enum OperationType {
  796. OP_UNKNOWN = 0;
  797. OP_INSERT = 1;
  798. OP_UPDATE = 2;
  799. OP_DELETE = 3;
  800. OP_UPSERT = 4;
  801. OP_CREATE_COLLECTION = 5;
  802. OP_DROP_COLLECTION = 6;
  803. }
  804. message ReplicationMessage {
  805. oneof content {
  806. ReplicationEntry entry = 1;
  807. Heartbeat heartbeat = 2;
  808. WatermarkUpdate watermark = 3;
  809. SyncRequest sync_request = 4;
  810. }
  811. }
  812. message Heartbeat {
  813. string node_id = 1;
  814. uint64 timestamp = 2;
  815. uint64 sequence = 3;
  816. }
  817. message WatermarkUpdate {
  818. string node_id = 1;
  819. uint64 sequence = 2;
  820. }
  821. message SyncRequest {
  822. uint64 from_sequence = 1;
  823. }
  824. message GetEntriesRequest {
  825. uint64 from_sequence = 1;
  826. uint32 limit = 2;
  827. }
  828. message GetNodeStateRequest {
  829. }
  830. message NodeState {
  831. string node_id = 1;
  832. uint64 current_sequence = 2;
  833. map<string, uint64> peer_watermarks = 3;
  834. uint64 document_count = 4;
  835. repeated string collections = 5;
  836. bool healthy = 6;
  837. // Per-collection sequence tracking for collection discovery
  838. map<string, uint64> collection_sequences = 7;
  839. }
  840. // ===== Health and Stats =====
  841. message HealthCheckRequest {
  842. }
  843. message HealthCheckResponse {
  844. bool healthy = 1;
  845. uint64 uptime_seconds = 2;
  846. uint64 document_count = 3;
  847. uint64 memory_used_bytes = 4;
  848. uint64 wal_size_bytes = 5;
  849. repeated PeerHealth peers = 6;
  850. }
  851. message PeerHealth {
  852. string node_id = 1;
  853. bool connected = 2;
  854. uint64 latency_ms = 3;
  855. uint64 lag_entries = 4;
  856. }
  857. message GetStatsRequest {
  858. }
  859. message GetStatsResponse {
  860. uint64 total_documents = 1;
  861. uint64 total_collections = 2;
  862. uint64 memory_used_bytes = 3;
  863. uint64 wal_sequence = 4;
  864. uint64 wal_size_bytes = 5;
  865. uint64 snapshot_count = 6;
  866. uint64 last_snapshot_sequence = 7;
  867. uint64 insert_count = 8;
  868. uint64 update_count = 9;
  869. uint64 delete_count = 10;
  870. uint64 query_count = 11;
  871. // Memory eviction stats
  872. uint64 evicted_documents = 12; // Documents currently evicted to disk
  873. uint64 total_evictions = 13; // Total eviction operations performed
  874. uint64 recovery_count = 14; // Documents recovered from eviction
  875. // Memory configuration
  876. uint64 max_memory_bytes = 15; // Configured max memory limit
  877. uint32 eviction_threshold_percent = 16; // Start evicting at this % of max
  878. uint32 eviction_target_percent = 17; // Evict down to this % of max
  879. // Operation timing (microseconds) - for performance monitoring
  880. uint64 get_count = 18; // Number of get operations
  881. uint64 get_total_micros = 19; // Total time spent in get operations
  882. uint64 get_max_micros = 20; // Max single get operation time
  883. uint64 insert_total_micros = 21;
  884. uint64 insert_max_micros = 22;
  885. uint64 update_total_micros = 23;
  886. uint64 update_max_micros = 24;
  887. uint64 query_total_micros = 25;
  888. uint64 query_max_micros = 26;
  889. }
  890. // ===== View Operations =====
  891. message ViewDefinition {
  892. string name = 1; // view name (globally unique, cannot start with _)
  893. string collection = 2; // target real collection (must NOT be another view)
  894. repeated string include = 3; // field paths to include (dot-notation for nested)
  895. repeated string exclude = 4; // field paths to exclude (ignored if include is non-empty)
  896. repeated Filter where = 5; // baked-in filters (AND-merged with caller filters)
  897. Sort default_sort = 6; // baked-in default sort (used when caller doesn't specify)
  898. uint64 created_at = 7;
  899. uint64 updated_at = 8;
  900. }
  901. message CreateViewRequest {
  902. string name = 1;
  903. string collection = 2;
  904. repeated string include = 3;
  905. repeated string exclude = 4;
  906. repeated Filter where = 5;
  907. Sort default_sort = 6;
  908. }
  909. message CreateViewResponse {
  910. bool success = 1;
  911. string error = 2;
  912. }
  913. message DropViewRequest {
  914. string name = 1;
  915. }
  916. message DropViewResponse {
  917. bool success = 1;
  918. string error = 2;
  919. }
  920. message ListViewsRequest {
  921. // Restrict the listing to one project namespace. Empty lists every
  922. // project (operator/CLI use). Clients always set it so a workspace
  923. // never sees another workspace's views.
  924. string project = 1;
  925. }
  926. message ListViewsResponse {
  927. repeated ViewDefinition views = 1;
  928. }
  929. message GetViewInfoRequest {
  930. string name = 1;
  931. }
  932. message GetViewInfoResponse {
  933. ViewDefinition view = 1;
  934. bool found = 2;
  935. }
  936. // ===== Relation (Referential Integrity) Operations — v2.11.0 T6b =====
  937. //
  938. // A relation says: documents in `child` reference documents in `parent`
  939. // through `child_field` (a dot-path that may resolve to a single id or an
  940. // array of ids). Declarations are persisted in the global `_relations`
  941. // system collection (mirrors `_views`) and are project-qualified like any
  942. // other collection-carrying name. Management is admin-only.
  943. message RelationDefinition {
  944. string name = 1; // relation name, project-qualified
  945. string child = 2; // collection holding the reference, project-qualified
  946. string child_field = 3; // dot-path on the child; may resolve to an array of ids
  947. string parent = 4; // collection being referenced, project-qualified
  948. // "restrict" (default) | "cascade" | "set_null" | "no_action".
  949. //
  950. // ALL FOUR ARE ENFORCED as of v2.11.0, and an unrecognised value is
  951. // REFUSED by CreateRelation rather than coerced to "restrict".
  952. // restrict - the parent delete fails FAILED_PRECONDITION while any
  953. // child still references it.
  954. // cascade - DESTRUCTIVE: children referencing the parent are deleted
  955. // atomically with it. If child_field resolves to an ARRAY,
  956. // the parent id is pulled from the array and the child is
  957. // KEPT (cascade and set_null collapse there). Refused if a
  958. // child is itself protected by its own restrict relation.
  959. // Not recursive.
  960. // set_null - DESTRUCTIVE: the child's reference field is set to null
  961. // and the child is kept. Arrays behave as under cascade.
  962. // no_action - the delete proceeds, the reference is left dangling.
  963. string on_delete = 5;
  964. // ENFORCED as of v2.11.0: a write to the child naming a parent that does
  965. // not exist is rejected with FAILED_PRECONDITION. An empty-string
  966. // reference is a hard rejection.
  967. bool validate_on_write = 6;
  968. uint64 created_at = 7;
  969. uint64 updated_at = 8;
  970. }
  971. message CreateRelationRequest {
  972. string name = 1;
  973. string child = 2;
  974. string child_field = 3;
  975. string parent = 4;
  976. string on_delete = 5; // empty defaults to "restrict"
  977. bool validate_on_write = 6;
  978. }
  979. message CreateRelationResponse {
  980. bool success = 1;
  981. string error = 2;
  982. // v2.11.0 T7 — rows indexed by the bootstrap scan. Declaring a relation
  983. // over a collection that already has rows backfills the reverse index
  984. // immediately (mirrors CreateIndexResponse.rows_indexed), so enforcement
  985. // covers pre-existing children from the moment the relation is declared,
  986. // not only writes made afterwards.
  987. uint64 rows_indexed = 3;
  988. }
  989. message DropRelationRequest {
  990. string name = 1;
  991. }
  992. message DropRelationResponse {
  993. bool success = 1;
  994. string error = 2;
  995. }
  996. message ListRelationsRequest {
  997. // Restrict the listing to one project namespace. Empty lists every
  998. // project (operator/CLI use). Clients always send their own project so
  999. // one workspace never enumerates another's relations.
  1000. string project = 1;
  1001. }
  1002. message ListRelationsResponse {
  1003. repeated RelationDefinition relations = 1;
  1004. }
  1005. message GetRelationInfoRequest {
  1006. string name = 1;
  1007. }
  1008. message GetRelationInfoResponse {
  1009. RelationDefinition relation = 1;
  1010. bool found = 2;
  1011. }
  1012. // v2.11.0 T5 — "what would happen if I deleted this?", answered without
  1013. // deleting anything. A relational database exposes its constraints through
  1014. // DDL you can read; a document store has none, so this has to be a query.
  1015. // Gated as an ordinary READ on `collection` (it changes nothing), unlike
  1016. // the relation-management RPCs above which are admin-only.
  1017. message DescribeDeleteRequest {
  1018. string collection = 1;
  1019. string id = 2;
  1020. }
  1021. message RelationImpact {
  1022. string relation = 1;
  1023. string child_collection = 2;
  1024. string child_field = 3;
  1025. string on_delete = 4; // restrict | cascade | set_null | no_action
  1026. uint64 child_count = 5;
  1027. repeated string sample_child_ids = 6; // at most five
  1028. bool blocks = 7;
  1029. }
  1030. message DescribeDeleteResponse {
  1031. bool success = 1;
  1032. string error = 2;
  1033. bool would_be_blocked = 3;
  1034. repeated RelationImpact impacts = 4;
  1035. }
  1036. // v2.11.0 T7 — the bootstrap-scan gap. Declaring a relation with T3 alone
  1037. // only maintains the reverse index going FORWARD from writes made after
  1038. // declaration; rows already in the child collection were never indexed, so
  1039. // enforcement silently missed them. This RPC answers "is that still true
  1040. // right now, for this relation" without changing anything.
  1041. message CheckRelationRequest {
  1042. string name = 1; // relation name, project-qualified like the others
  1043. }
  1044. // One parent id referenced by the child collection's data, whose parent
  1045. // document does not exist.
  1046. message DanglingReference {
  1047. string parent_id = 1;
  1048. uint64 child_count = 2; // children of this parent, from the index
  1049. repeated string sample_child_ids = 3; // at most five
  1050. }
  1051. message CheckRelationResponse {
  1052. bool success = 1;
  1053. string error = 2;
  1054. // Every dangling parent id found, not just the reported sample - so a
  1055. // capped `dangling` list below does not silently understate the problem.
  1056. uint64 total_dangling = 3;
  1057. // Capped (see the server implementation) so a badly out-of-sync relation
  1058. // cannot blow up the response size; total_dangling is the true count.
  1059. repeated DanglingReference dangling = 4;
  1060. }
  1061. // ===== Collection Configuration =====
  1062. // Per-collection configuration for timestamp precision and other runtime knobs.
  1063. // Stored in the _collection_meta system collection.
  1064. message CollectionConfig {
  1065. // "ms" (default) — _created_at/_updated_at stamped in milliseconds since epoch
  1066. // "ns" — _created_at/_updated_at stamped in nanoseconds since epoch
  1067. // Empty on a ConfigureCollection request means "leave unchanged".
  1068. string timestamp_precision = 1;
  1069. // v2.4.5 — version history on/off for an EXISTING collection.
  1070. //
  1071. // `optional` (proto3 field presence) is load-bearing, not decoration: a
  1072. // plain bool defaults to false, so any ConfigureCollection call that meant
  1073. // to set only timestamp_precision would silently switch versioning OFF.
  1074. // With presence, an absent field means "leave unchanged" and the server
  1075. // overlays only what the caller actually set.
  1076. //
  1077. // Disabling stops NEW versions being recorded; history already on disk
  1078. // stays readable, so this is reversible. Distinct from max_versions=0,
  1079. // which means "unlimited", not "off".
  1080. optional bool versioning_enabled = 2;
  1081. // v2.11.0 T8 — whether declared relations are enforced for this collection.
  1082. //
  1083. // `optional` for the same reason versioning_enabled is: a plain bool
  1084. // defaults to false, so a ConfigureCollection call that meant to set
  1085. // only timestamp_precision would silently switch relation enforcement
  1086. // OFF. With presence, an absent field means "leave unchanged".
  1087. //
  1088. // Defaults to true (enforced) when never explicitly configured -
  1089. // declaring a relation names its child and parent explicitly, so the
  1090. // declaration IS the opt-in.
  1091. optional bool relations_enforced = 3;
  1092. // Room for future per-collection knobs
  1093. }
  1094. message ConfigureCollectionRequest {
  1095. string collection = 1;
  1096. CollectionConfig config = 2;
  1097. }
  1098. message ConfigureCollectionResponse {
  1099. bool success = 1;
  1100. string error = 2;
  1101. }
  1102. // v2.9.0 — secondary index management.
  1103. message CreateIndexRequest {
  1104. // Project-qualified collection name, as every other collection-carrying
  1105. // request takes.
  1106. string collection = 1;
  1107. // Field to index. Dotted paths address nested fields ("nest.deep"), and the
  1108. // document metadata fields (_id, _created_at, _updated_at, _version) are
  1109. // addressable too.
  1110. string field = 2;
  1111. // v2.11.0 T11 — when true, the field carries a UNIQUE constraint: two
  1112. // documents may never hold the same value for it. Declaring this over a
  1113. // collection that already contains duplicate values is REFUSED (see
  1114. // CreateIndexResponse.duplicate_examples) rather than accepted and left
  1115. // silently unenforced against the data that already violates it.
  1116. //
  1117. // v2.12.0 - NULL IS NOT A VALUE for uniqueness: any number of documents
  1118. // may hold null (or omit the field), as in SQL. Before 2.12.0 two nulls
  1119. // collided while two absent fields did not.
  1120. bool unique = 3;
  1121. // v2.12.0 - a COMPOSITE unique constraint over the TUPLE of these fields
  1122. // (two or more; `field` must then be empty and `unique` true). Two
  1123. // documents may not hold the same combination. A document in which any
  1124. // of the fields is absent, null, an object or an array is not constrained
  1125. // - the SQL rule for a NULL in a unique key. Composite constraints back no
  1126. // query (the planner never uses them) and are listed by ListIndexes with
  1127. // `fields` set. Declaring one over existing duplicates is refused with
  1128. // examples, as for a single field.
  1129. repeated string fields = 4;
  1130. }
  1131. message CreateIndexResponse {
  1132. bool success = 1;
  1133. string error = 2;
  1134. // Rows indexed by the backfill. Creating an index over an existing
  1135. // collection populates it, so it is usable immediately rather than only for
  1136. // rows written afterwards.
  1137. uint64 rows_indexed = 3;
  1138. // True when the index already existed - creation is idempotent.
  1139. bool already_existed = 4;
  1140. // v2.11.0 T11 — set when a `unique=true` request was refused because the
  1141. // field already holds duplicate values. `error` explains the refusal;
  1142. // these are up to five example document ids that collide, one entry per
  1143. // colliding value, so the caller can go fix the data rather than guess.
  1144. repeated string duplicate_examples = 5;
  1145. }
  1146. message DropIndexRequest {
  1147. string collection = 1;
  1148. string field = 2;
  1149. // v2.12.0 - drop the composite unique constraint over exactly these
  1150. // fields, in the order they were declared. `field` must then be empty.
  1151. repeated string fields = 3;
  1152. }
  1153. message DropIndexResponse {
  1154. bool success = 1;
  1155. string error = 2;
  1156. }
  1157. message ListIndexesRequest {
  1158. string collection = 1;
  1159. }
  1160. message IndexInfo {
  1161. string field = 1;
  1162. // Distinct values held, and total postings. Both come from the index itself
  1163. // rather than a scan, so an operator can judge selectivity - a field whose
  1164. // postings are concentrated in few values will not be used by the planner.
  1165. uint64 distinct_values = 2;
  1166. uint64 entries = 3;
  1167. // v2.11.0 T11 — true when this index also carries a UNIQUE constraint.
  1168. bool unique = 4;
  1169. // v2.12.0 - set for a COMPOSITE unique constraint: its fields, in order.
  1170. // `field` then holds a display form ("a+b") and `unique` is true.
  1171. repeated string fields = 5;
  1172. }
  1173. message ListIndexesResponse {
  1174. bool success = 1;
  1175. string error = 2;
  1176. repeated IndexInfo indexes = 3;
  1177. }
  1178. message GetIndexValuesRequest {
  1179. string collection = 1;
  1180. string field = 2;
  1181. // Bounded on purpose: reading the values costs one document read each.
  1182. uint32 limit = 3;
  1183. // false walks from the highest value down, so limit=1 gives the maximum.
  1184. bool ascending = 4;
  1185. }
  1186. message IndexValueCount {
  1187. // The value as stored, JSON-encoded.
  1188. string value = 1;
  1189. uint64 count = 2;
  1190. }
  1191. message GetIndexValuesResponse {
  1192. bool success = 1;
  1193. string error = 2;
  1194. repeated IndexValueCount values = 3;
  1195. }
  1196. message GetCollectionConfigRequest {
  1197. string collection = 1;
  1198. }
  1199. message GetCollectionConfigResponse {
  1200. CollectionConfig config = 1;
  1201. bool found = 2;
  1202. }
  1203. message MigrateCollectionTimestampsRequest {
  1204. string collection = 1;
  1205. string from_precision = 2; // "ms" or "ns"
  1206. string to_precision = 3; // "ms" or "ns"
  1207. }
  1208. message MigrateCollectionTimestampsResponse {
  1209. bool success = 1;
  1210. string error = 2;
  1211. uint64 rows_migrated = 3; // how many documents had their timestamps updated
  1212. uint64 rows_skipped = 4; // already in target range (idempotent resume)
  1213. }
  1214. // ===== Read-Only Control =====
  1215. message SetReadOnlyRequest {
  1216. bool read_only = 1;
  1217. }
  1218. message SetReadOnlyResponse {
  1219. bool success = 1;
  1220. bool was_read_only = 2; // previous state
  1221. string error = 3;
  1222. }
  1223. message GetReadOnlyStatusRequest {}
  1224. message GetReadOnlyStatusResponse {
  1225. bool read_only = 1;
  1226. string reason = 2;
  1227. // Recovery outcome details (populated when auto-readonly triggered)
  1228. string recovery_outcome = 3; // "trivial_success" | "fresh_install" | "snapshot_fell_back" | "wal_only_replay" | "forced_empty" | "failed"
  1229. string expected_snapshot = 4;
  1230. string snapshot_used = 5;
  1231. string failure_reason = 6;
  1232. uint64 wal_entries_replayed = 7;
  1233. uint32 snapshots_attempted = 8;
  1234. }
  1235. // ===== Memory Stats =====
  1236. // Added in v1.7.0. Wire-compatible — server-side implementation lands in T9.
  1237. message GetMemoryStatsRequest {}
  1238. message CollectionMemoryStats {
  1239. string collection = 1;
  1240. uint64 document_count = 2;
  1241. uint64 estimated_bytes = 3;
  1242. uint64 evicted_stub_count = 4;
  1243. MemoryPriority priority = 5;
  1244. }
  1245. message GetMemoryStatsResponse {
  1246. uint64 total_memory_bytes = 1;
  1247. uint64 max_memory_bytes = 2;
  1248. uint32 pressure_percent = 3; // current usage / max × 100
  1249. string pressure_level = 4; // "normal" | "soft" | "hard" | "emergency"
  1250. repeated CollectionMemoryStats collections = 5;
  1251. // Most recent eviction
  1252. uint64 last_eviction_timestamp = 6; // ms since epoch, 0 if none
  1253. uint64 last_eviction_docs = 7;
  1254. uint64 last_eviction_bytes_freed = 8;
  1255. // v2.11.0 — TTL expiries a relation is refusing.
  1256. //
  1257. // ttl_blocked_documents is a GAUGE: how many documents are past their TTL
  1258. // right now and NOT being expired because deleting them would break a
  1259. // `restrict` relation (or because the cascade path is refusing while the
  1260. // LMDB mirror is unhealthy/drifted). It falls when a block lifts. Nonzero
  1261. // means those documents are outliving their retention policy - the
  1262. // deliberate alternative to silently orphaning their children.
  1263. //
  1264. // ttl_expiry_blocked_events is a monotonic COUNTER of refusal events, so it
  1265. // keeps rising while a block persists (each blocked document is retried on a
  1266. // slow cadence). Use the gauge for "how bad is it now", the counter for
  1267. // "is this still happening".
  1268. //
  1269. // Both are zero on any install that declares no relations.
  1270. uint64 ttl_blocked_documents = 9;
  1271. uint64 ttl_expiry_blocked_events = 10;
  1272. }