openapi.json 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981
  1. {
  2. "openapi": "3.1.0",
  3. "info": {
  4. "title": "smartbotic-vectorapi",
  5. "version": "0.1.0",
  6. "description": "General-purpose REST API fronting smartbotic-database. Supports multi-project namespacing and multi-key authorization with per-project grants."
  7. },
  8. "components": {
  9. "securitySchemes": {
  10. "bearerAuth": {
  11. "type": "http",
  12. "scheme": "bearer",
  13. "description": "API key issued by the /api/v1/keys endpoint. Pass as Authorization: Bearer <KEY>."
  14. }
  15. },
  16. "schemas": {
  17. "Error": {
  18. "type": "object",
  19. "properties": {
  20. "error": { "type": "string" },
  21. "message": { "type": "string" }
  22. },
  23. "required": ["error", "message"]
  24. },
  25. "CollectionMeta": {
  26. "type": "object",
  27. "properties": {
  28. "name": { "type": "string" },
  29. "kind": { "type": "string", "enum": ["json", "vector"] },
  30. "vector_dimension": { "type": "integer", "minimum": 1 },
  31. "embedding_model": { "type": "string" },
  32. "created_at": { "type": "integer" }
  33. },
  34. "required": ["name", "kind"]
  35. },
  36. "KeyScopeRule": {
  37. "type": "object",
  38. "properties": {
  39. "collection": { "type": "string", "description": "Collection name the rule applies to" },
  40. "ops": {
  41. "type": "array",
  42. "items": { "type": "string", "enum": ["read","list","search","insert","update","delete"] },
  43. "description": "Permitted operations on this collection"
  44. },
  45. "require_human_token": { "type": "boolean", "description": "Phase 2: require a CAPTCHA token (reserved)" }
  46. },
  47. "required": ["collection", "ops"]
  48. },
  49. "KeyScope": {
  50. "type": "object",
  51. "description": "Capability scope that constrains a non-admin key to specific collections and operations. A scoped key is safe to embed in untrusted clients (e.g. read-only, insert-only, origin-pinned, rate-limited, expiring). Scoped keys cannot manage collections or projects.",
  52. "properties": {
  53. "rules": {
  54. "type": "array",
  55. "items": { "$ref": "#/components/schemas/KeyScopeRule" },
  56. "minItems": 1,
  57. "description": "At least one rule is required. A request is allowed only if a matching rule exists for the (collection, op) pair."
  58. },
  59. "origins": {
  60. "type": "array",
  61. "items": { "type": "string" },
  62. "description": "Allowed Origin header values. Empty array means any origin is permitted. When non-empty, requests without a matching Origin header are rejected (fails closed)."
  63. },
  64. "rate_limit_per_min": {
  65. "type": "integer",
  66. "minimum": 0,
  67. "description": "Maximum requests per minute for this key (keyed by key id). 0 means unlimited. Exceeding the limit returns 429 with a Retry-After: 60 header."
  68. },
  69. "expires_at": {
  70. "type": "integer",
  71. "description": "Unix epoch seconds after which the key is treated as expired (auth returns 401). 0 means the key never expires."
  72. }
  73. },
  74. "required": ["rules"]
  75. },
  76. "ApiKeyPublic": {
  77. "type": "object",
  78. "properties": {
  79. "id": { "type": "string", "description": "Stable non-secret identifier used to reference the key in PATCH/DELETE" },
  80. "key_prefix": { "type": "string" },
  81. "label": { "type": "string" },
  82. "projects": { "type": "array", "items": { "type": "string" } },
  83. "admin": { "type": "boolean" },
  84. "created_at": { "type": "integer" },
  85. "scope": { "$ref": "#/components/schemas/KeyScope", "description": "Present only when the key carries a capability scope" }
  86. }
  87. }
  88. }
  89. },
  90. "security": [{ "bearerAuth": [] }],
  91. "paths": {
  92. "/healthz": {
  93. "get": {
  94. "summary": "Liveness check — always 200 if the process is running",
  95. "operationId": "healthz",
  96. "security": [],
  97. "responses": {
  98. "200": { "description": "OK" }
  99. }
  100. }
  101. },
  102. "/readyz": {
  103. "get": {
  104. "summary": "Readiness check — 200 when the database is reachable",
  105. "operationId": "readyz",
  106. "security": [],
  107. "responses": {
  108. "200": { "description": "Ready" },
  109. "503": { "description": "Database not reachable" }
  110. }
  111. }
  112. },
  113. "/api/v1/projects": {
  114. "get": {
  115. "summary": "List projects the key may access (admin sees all)",
  116. "operationId": "listProjects",
  117. "responses": {
  118. "200": {
  119. "description": "Project list",
  120. "content": {
  121. "application/json": {
  122. "schema": {
  123. "type": "object",
  124. "properties": {
  125. "projects": { "type": "array", "items": { "type": "string" } }
  126. }
  127. }
  128. }
  129. }
  130. },
  131. "401": { "description": "Unauthorized" }
  132. }
  133. },
  134. "post": {
  135. "summary": "Create a new project (admin only)",
  136. "operationId": "createProject",
  137. "requestBody": {
  138. "required": true,
  139. "content": {
  140. "application/json": {
  141. "schema": {
  142. "type": "object",
  143. "properties": {
  144. "name": { "type": "string" }
  145. },
  146. "required": ["name"]
  147. }
  148. }
  149. }
  150. },
  151. "responses": {
  152. "201": { "description": "Project created" },
  153. "401": { "description": "Unauthorized" },
  154. "403": { "description": "Forbidden — admin required" },
  155. "422": { "description": "Validation error" }
  156. }
  157. }
  158. },
  159. "/api/v1/projects/{project}": {
  160. "parameters": [
  161. {
  162. "name": "project",
  163. "in": "path",
  164. "required": true,
  165. "schema": { "type": "string" },
  166. "description": "Project name"
  167. }
  168. ],
  169. "get": {
  170. "summary": "Get project info (collection and document counts)",
  171. "operationId": "getProject",
  172. "responses": {
  173. "200": {
  174. "description": "Project info",
  175. "content": {
  176. "application/json": {
  177. "schema": {
  178. "type": "object",
  179. "properties": {
  180. "name": { "type": "string" },
  181. "collections": { "type": "integer" },
  182. "documents": { "type": "integer" }
  183. }
  184. }
  185. }
  186. }
  187. },
  188. "401": { "description": "Unauthorized" },
  189. "403": { "description": "Forbidden" },
  190. "404": { "description": "Project not found" }
  191. }
  192. },
  193. "delete": {
  194. "summary": "Drop a project (admin only; not 'default')",
  195. "operationId": "deleteProject",
  196. "responses": {
  197. "200": { "description": "Project deleted" },
  198. "401": { "description": "Unauthorized" },
  199. "403": { "description": "Forbidden — admin required or cannot drop default" },
  200. "404": { "description": "Project not found" }
  201. }
  202. }
  203. },
  204. "/api/v1/keys": {
  205. "get": {
  206. "summary": "List API keys (admin only; secret masked; returns id and key_prefix)",
  207. "operationId": "listKeys",
  208. "responses": {
  209. "200": {
  210. "description": "Key list",
  211. "content": {
  212. "application/json": {
  213. "schema": {
  214. "type": "object",
  215. "properties": {
  216. "keys": {
  217. "type": "array",
  218. "items": { "$ref": "#/components/schemas/ApiKeyPublic" }
  219. }
  220. }
  221. }
  222. }
  223. }
  224. },
  225. "401": { "description": "Unauthorized" },
  226. "403": { "description": "Forbidden — admin required" }
  227. }
  228. },
  229. "post": {
  230. "summary": "Generate a new API key (admin only); returns the secret key value once",
  231. "operationId": "createKey",
  232. "requestBody": {
  233. "required": true,
  234. "content": {
  235. "application/json": {
  236. "schema": {
  237. "type": "object",
  238. "properties": {
  239. "label": { "type": "string" },
  240. "projects": {
  241. "type": "array",
  242. "items": { "type": "string" },
  243. "description": "Project names the key may access; use [\"*\"] for all projects"
  244. },
  245. "admin": { "type": "boolean", "default": false },
  246. "scope": { "$ref": "#/components/schemas/KeyScope", "description": "Optional capability scope. Mutually exclusive with admin:true." }
  247. },
  248. "required": ["label", "projects"]
  249. }
  250. }
  251. }
  252. },
  253. "responses": {
  254. "201": {
  255. "description": "Key created; contains the secret key value (shown once) and the stable id",
  256. "content": {
  257. "application/json": {
  258. "schema": {
  259. "type": "object",
  260. "properties": {
  261. "id": { "type": "string", "description": "Stable non-secret identifier for this key" },
  262. "key": { "type": "string", "description": "Secret key value — shown only once" },
  263. "label": { "type": "string" },
  264. "projects": { "type": "array", "items": { "type": "string" } },
  265. "admin": { "type": "boolean" },
  266. "scope": { "$ref": "#/components/schemas/KeyScope" }
  267. }
  268. }
  269. }
  270. }
  271. },
  272. "401": { "description": "Unauthorized" },
  273. "403": { "description": "Forbidden — admin required" },
  274. "422": { "description": "Validation error" }
  275. }
  276. }
  277. },
  278. "/api/v1/keys/{id}": {
  279. "parameters": [
  280. {
  281. "name": "id",
  282. "in": "path",
  283. "required": true,
  284. "schema": { "type": "string" },
  285. "description": "Stable non-secret key id (from the id field in list/create responses)"
  286. }
  287. ],
  288. "patch": {
  289. "summary": "Update key grants (admin only)",
  290. "operationId": "updateKey",
  291. "requestBody": {
  292. "required": true,
  293. "content": {
  294. "application/json": {
  295. "schema": {
  296. "type": "object",
  297. "properties": {
  298. "label": { "type": "string" },
  299. "projects": { "type": "array", "items": { "type": "string" } },
  300. "admin": { "type": "boolean" },
  301. "scope": { "$ref": "#/components/schemas/KeyScope", "description": "Set or replace the capability scope. Omit to leave unchanged. Pass null to clear the scope." }
  302. }
  303. }
  304. }
  305. }
  306. },
  307. "responses": {
  308. "200": { "description": "Key updated" },
  309. "401": { "description": "Unauthorized" },
  310. "403": { "description": "Forbidden — admin required" },
  311. "404": { "description": "Key not found" }
  312. }
  313. },
  314. "delete": {
  315. "summary": "Revoke an API key (admin only)",
  316. "operationId": "deleteKey",
  317. "responses": {
  318. "200": { "description": "Key revoked" },
  319. "401": { "description": "Unauthorized" },
  320. "403": { "description": "Forbidden — admin required" },
  321. "404": { "description": "Key not found" }
  322. }
  323. }
  324. },
  325. "/api/v1/projects/{project}/collections": {
  326. "parameters": [
  327. {
  328. "name": "project",
  329. "in": "path",
  330. "required": true,
  331. "schema": { "type": "string" },
  332. "description": "Project name"
  333. }
  334. ],
  335. "get": {
  336. "summary": "List collections in a project",
  337. "operationId": "listCollections",
  338. "parameters": [
  339. {
  340. "name": "q",
  341. "in": "query",
  342. "schema": { "type": "string" },
  343. "description": "Case-insensitive substring filter on collection name (applied server-side)."
  344. },
  345. {
  346. "name": "sort",
  347. "in": "query",
  348. "schema": { "type": "string", "enum": ["name", "kind", "documents", "size", "created_at"], "default": "name" },
  349. "description": "Field to sort by (applied server-side). Ties break by name."
  350. },
  351. {
  352. "name": "desc",
  353. "in": "query",
  354. "schema": { "type": "boolean", "default": false }
  355. }
  356. ],
  357. "responses": {
  358. "200": {
  359. "description": "Collection list",
  360. "content": {
  361. "application/json": {
  362. "schema": {
  363. "type": "object",
  364. "properties": {
  365. "collections": {
  366. "type": "array",
  367. "items": { "$ref": "#/components/schemas/CollectionMeta" }
  368. }
  369. }
  370. }
  371. }
  372. }
  373. },
  374. "401": { "description": "Unauthorized" },
  375. "403": { "description": "Forbidden" }
  376. }
  377. },
  378. "post": {
  379. "summary": "Create a collection in a project",
  380. "operationId": "createCollection",
  381. "requestBody": {
  382. "required": true,
  383. "content": {
  384. "application/json": {
  385. "schema": {
  386. "type": "object",
  387. "properties": {
  388. "name": { "type": "string" },
  389. "kind": { "type": "string", "enum": ["json", "vector"] },
  390. "vector_dimension": {
  391. "type": "integer",
  392. "minimum": 1,
  393. "description": "Required when kind=vector"
  394. },
  395. "embedding_model": {
  396. "type": "string",
  397. "description": "Optional; defaults to global default_embedding_model"
  398. }
  399. },
  400. "required": ["name", "kind"]
  401. }
  402. }
  403. }
  404. },
  405. "responses": {
  406. "201": { "description": "Collection created" },
  407. "401": { "description": "Unauthorized" },
  408. "403": { "description": "Forbidden" },
  409. "422": { "description": "Validation error (e.g. missing vector_dimension for vector kind)" }
  410. }
  411. }
  412. },
  413. "/api/v1/projects/{project}/collections/{name}": {
  414. "parameters": [
  415. {
  416. "name": "project",
  417. "in": "path",
  418. "required": true,
  419. "schema": { "type": "string" },
  420. "description": "Project name"
  421. },
  422. {
  423. "name": "name",
  424. "in": "path",
  425. "required": true,
  426. "schema": { "type": "string" },
  427. "description": "Collection name"
  428. }
  429. ],
  430. "get": {
  431. "summary": "Get collection metadata",
  432. "operationId": "getCollection",
  433. "responses": {
  434. "200": {
  435. "description": "Collection metadata",
  436. "content": {
  437. "application/json": {
  438. "schema": { "$ref": "#/components/schemas/CollectionMeta" }
  439. }
  440. }
  441. },
  442. "401": { "description": "Unauthorized" },
  443. "403": { "description": "Forbidden" },
  444. "404": { "description": "Collection not found" }
  445. }
  446. },
  447. "delete": {
  448. "summary": "Drop a collection and all its documents",
  449. "operationId": "deleteCollection",
  450. "responses": {
  451. "200": { "description": "Collection deleted" },
  452. "401": { "description": "Unauthorized" },
  453. "403": { "description": "Forbidden" },
  454. "404": { "description": "Collection not found" }
  455. }
  456. }
  457. },
  458. "/api/v1/projects/{project}/collections/{name}/documents": {
  459. "parameters": [
  460. {
  461. "name": "project",
  462. "in": "path",
  463. "required": true,
  464. "schema": { "type": "string" },
  465. "description": "Project name"
  466. },
  467. {
  468. "name": "name",
  469. "in": "path",
  470. "required": true,
  471. "schema": { "type": "string" },
  472. "description": "Collection name"
  473. }
  474. ],
  475. "get": {
  476. "summary": "Find documents with optional filter, pagination, and sort",
  477. "operationId": "findDocuments",
  478. "parameters": [
  479. {
  480. "name": "filter",
  481. "in": "query",
  482. "schema": { "type": "string" },
  483. "description": "Filter expression in field:op:value grammar (e.g. age:gte:30, name:eq:Alice). Multiple filters are ANDed."
  484. },
  485. {
  486. "name": "limit",
  487. "in": "query",
  488. "schema": { "type": "integer", "default": 20 }
  489. },
  490. {
  491. "name": "offset",
  492. "in": "query",
  493. "schema": { "type": "integer", "default": 0 }
  494. },
  495. {
  496. "name": "sort",
  497. "in": "query",
  498. "schema": { "type": "string" },
  499. "description": "Field to sort by"
  500. },
  501. {
  502. "name": "desc",
  503. "in": "query",
  504. "schema": { "type": "boolean", "default": false }
  505. }
  506. ],
  507. "responses": {
  508. "200": {
  509. "description": "Document list",
  510. "content": {
  511. "application/json": {
  512. "schema": {
  513. "type": "object",
  514. "properties": {
  515. "documents": { "type": "array", "items": { "type": "object" } },
  516. "count": { "type": "integer" }
  517. }
  518. }
  519. }
  520. }
  521. },
  522. "401": { "description": "Unauthorized" },
  523. "403": { "description": "Forbidden" },
  524. "404": { "description": "Collection not found" },
  525. "429": { "description": "Too Many Requests (rate-limited scoped key)" }
  526. }
  527. },
  528. "post": {
  529. "summary": "Insert a new JSON document",
  530. "operationId": "insertDocument",
  531. "parameters": [
  532. {
  533. "name": "X-Captcha-Token",
  534. "in": "header",
  535. "required": false,
  536. "schema": { "type": "string" },
  537. "description": "CAPTCHA response token. Required when the scoped key rule has require_human_token=true; verified server-side via the configured captcha provider."
  538. }
  539. ],
  540. "requestBody": {
  541. "required": true,
  542. "content": {
  543. "application/json": {
  544. "schema": {
  545. "type": "object",
  546. "properties": {
  547. "data": {
  548. "type": "object",
  549. "description": "Arbitrary JSON document payload"
  550. }
  551. }
  552. }
  553. }
  554. }
  555. },
  556. "responses": {
  557. "201": {
  558. "description": "Document inserted",
  559. "content": {
  560. "application/json": {
  561. "schema": {
  562. "type": "object",
  563. "properties": {
  564. "id": { "type": "string" }
  565. }
  566. }
  567. }
  568. }
  569. },
  570. "401": { "description": "Unauthorized" },
  571. "403": { "description": "Forbidden" },
  572. "404": { "description": "Collection not found" },
  573. "422": { "description": "Validation error" },
  574. "429": { "description": "Too Many Requests (rate-limited scoped key)" }
  575. }
  576. }
  577. },
  578. "/api/v1/projects/{project}/collections/{name}/documents/{id}": {
  579. "parameters": [
  580. {
  581. "name": "project",
  582. "in": "path",
  583. "required": true,
  584. "schema": { "type": "string" },
  585. "description": "Project name"
  586. },
  587. {
  588. "name": "name",
  589. "in": "path",
  590. "required": true,
  591. "schema": { "type": "string" },
  592. "description": "Collection name"
  593. },
  594. {
  595. "name": "id",
  596. "in": "path",
  597. "required": true,
  598. "schema": { "type": "string" },
  599. "description": "Document ID"
  600. }
  601. ],
  602. "get": {
  603. "summary": "Get a document by ID",
  604. "operationId": "getDocument",
  605. "responses": {
  606. "200": {
  607. "description": "Document",
  608. "content": {
  609. "application/json": {
  610. "schema": { "type": "object" }
  611. }
  612. }
  613. },
  614. "401": { "description": "Unauthorized" },
  615. "403": { "description": "Forbidden" },
  616. "404": { "description": "Document not found" },
  617. "429": { "description": "Too Many Requests (rate-limited scoped key)" }
  618. }
  619. },
  620. "put": {
  621. "summary": "Replace a document (full upsert by ID)",
  622. "operationId": "replaceDocument",
  623. "requestBody": {
  624. "required": true,
  625. "content": {
  626. "application/json": {
  627. "schema": { "type": "object" }
  628. }
  629. }
  630. },
  631. "responses": {
  632. "200": { "description": "Document replaced" },
  633. "401": { "description": "Unauthorized" },
  634. "403": { "description": "Forbidden" },
  635. "404": { "description": "Collection not found" },
  636. "422": { "description": "Validation error" },
  637. "429": { "description": "Too Many Requests (rate-limited scoped key)" }
  638. }
  639. },
  640. "patch": {
  641. "summary": "Partially update a document (merge fields)",
  642. "operationId": "patchDocument",
  643. "requestBody": {
  644. "required": true,
  645. "content": {
  646. "application/json": {
  647. "schema": { "type": "object" }
  648. }
  649. }
  650. },
  651. "responses": {
  652. "200": { "description": "Document updated" },
  653. "401": { "description": "Unauthorized" },
  654. "403": { "description": "Forbidden" },
  655. "404": { "description": "Document not found" },
  656. "422": { "description": "Validation error" },
  657. "429": { "description": "Too Many Requests (rate-limited scoped key)" }
  658. }
  659. },
  660. "delete": {
  661. "summary": "Delete a document by ID",
  662. "operationId": "deleteDocument",
  663. "responses": {
  664. "200": { "description": "Document deleted" },
  665. "401": { "description": "Unauthorized" },
  666. "403": { "description": "Forbidden" },
  667. "404": { "description": "Document not found" },
  668. "429": { "description": "Too Many Requests (rate-limited scoped key)" }
  669. }
  670. }
  671. },
  672. "/api/v1/projects/{project}/collections/{name}/vectors": {
  673. "parameters": [
  674. {
  675. "name": "project",
  676. "in": "path",
  677. "required": true,
  678. "schema": { "type": "string" },
  679. "description": "Project name"
  680. },
  681. {
  682. "name": "name",
  683. "in": "path",
  684. "required": true,
  685. "schema": { "type": "string" },
  686. "description": "Collection name (must be kind=vector)"
  687. }
  688. ],
  689. "post": {
  690. "summary": "Store a vector; supply either text (auto-embedded) or an explicit vector array",
  691. "description": "Store a vector. Supply either `text` (auto-embedded) or a pre-computed `vector` array. When supplying `text`, the server-side embedding result is cached by default. Send `Cache-Control: no-store` to bypass the cache: the text will be re-embedded fresh and the result will not be stored.",
  692. "operationId": "upsertVector",
  693. "parameters": [
  694. {
  695. "name": "X-Captcha-Token",
  696. "in": "header",
  697. "required": false,
  698. "schema": { "type": "string" },
  699. "description": "CAPTCHA response token. Required when the scoped key rule has require_human_token=true; verified server-side via the configured captcha provider."
  700. }
  701. ],
  702. "requestBody": {
  703. "required": true,
  704. "content": {
  705. "application/json": {
  706. "schema": {
  707. "type": "object",
  708. "properties": {
  709. "id": {
  710. "type": "string",
  711. "description": "Optional stable ID; auto-generated if omitted"
  712. },
  713. "text": {
  714. "type": "string",
  715. "description": "Source text; will be embedded using the collection's embedding_model"
  716. },
  717. "vector": {
  718. "type": "array",
  719. "items": { "type": "number" },
  720. "description": "Pre-computed embedding; dimension must match the collection's vector_dimension"
  721. },
  722. "metadata": {
  723. "type": "object",
  724. "description": "Arbitrary JSON payload stored alongside the vector"
  725. }
  726. }
  727. }
  728. }
  729. }
  730. },
  731. "responses": {
  732. "201": {
  733. "description": "Vector stored",
  734. "content": {
  735. "application/json": {
  736. "schema": {
  737. "type": "object",
  738. "properties": {
  739. "id": { "type": "string" }
  740. }
  741. }
  742. }
  743. }
  744. },
  745. "401": { "description": "Unauthorized" },
  746. "403": { "description": "Forbidden" },
  747. "404": { "description": "Collection not found" },
  748. "422": { "description": "Validation error (wrong dimension, not a vector collection, etc.)" },
  749. "429": { "description": "Too Many Requests (rate-limited scoped key)" }
  750. }
  751. }
  752. },
  753. "/api/v1/projects/{project}/collections/{name}/search": {
  754. "parameters": [
  755. {
  756. "name": "project",
  757. "in": "path",
  758. "required": true,
  759. "schema": { "type": "string" },
  760. "description": "Project name"
  761. },
  762. {
  763. "name": "name",
  764. "in": "path",
  765. "required": true,
  766. "schema": { "type": "string" },
  767. "description": "Collection name (must be kind=vector)"
  768. }
  769. ],
  770. "post": {
  771. "summary": "Cosine-similarity search; supply either query_text (auto-embedded) or query_vector",
  772. "description": "Supply either `query_text` or `query_vector`. **For low latency, prefer `query_vector`.** `query_text` requires a synchronous server-side embedding round-trip to the configured provider, which typically dominates request latency (seconds for large models). Clients issuing many searches (e.g. an LLM/n8n agent) should embed once on their side and pass `query_vector` to skip that step entirely; cosine search itself is sub-millisecond. Send `Cache-Control: no-store` to bypass the server-side embedding cache: the query text will be re-embedded fresh and the result will not be stored.",
  773. "operationId": "searchVectors",
  774. "requestBody": {
  775. "required": true,
  776. "content": {
  777. "application/json": {
  778. "schema": {
  779. "type": "object",
  780. "properties": {
  781. "query_text": {
  782. "type": "string",
  783. "description": "Query text; embedded with the collection's model. Slow path: incurs a server-side embedding round-trip. Prefer query_vector when you can pre-embed."
  784. },
  785. "query_vector": {
  786. "type": "array",
  787. "items": { "type": "number" },
  788. "description": "Pre-computed query embedding (length must equal the collection's vector_dimension). Fast path: skips server-side embedding."
  789. },
  790. "top_k": {
  791. "type": "integer",
  792. "minimum": 1,
  793. "description": "Maximum number of results to return"
  794. },
  795. "min_score": {
  796. "type": "number",
  797. "description": "Minimum cosine similarity score (0–1)"
  798. },
  799. "filters": {
  800. "type": "array",
  801. "items": { "type": "string" },
  802. "description": "Metadata filters in field:op:value grammar (e.g. src:eq:n8n)"
  803. }
  804. },
  805. "required": ["top_k"]
  806. }
  807. }
  808. }
  809. },
  810. "responses": {
  811. "200": {
  812. "description": "Search results",
  813. "content": {
  814. "application/json": {
  815. "schema": {
  816. "type": "object",
  817. "properties": {
  818. "results": {
  819. "type": "array",
  820. "items": {
  821. "type": "object",
  822. "properties": {
  823. "id": { "type": "string" },
  824. "score": { "type": "number" },
  825. "metadata": { "type": "object" }
  826. }
  827. }
  828. }
  829. }
  830. }
  831. }
  832. }
  833. },
  834. "401": { "description": "Unauthorized" },
  835. "403": { "description": "Forbidden" },
  836. "404": { "description": "Collection not found" },
  837. "422": { "description": "Validation error" },
  838. "429": { "description": "Too Many Requests (rate-limited scoped key)" }
  839. }
  840. }
  841. },
  842. "/api/v1/projects/{project}/stats": {
  843. "parameters": [
  844. {
  845. "name": "project",
  846. "in": "path",
  847. "required": true,
  848. "schema": { "type": "string" },
  849. "description": "Project name"
  850. }
  851. ],
  852. "get": {
  853. "summary": "Per-project stats (accessible by any key granted the project)",
  854. "operationId": "projectStats",
  855. "responses": {
  856. "200": {
  857. "description": "Project stats",
  858. "content": {
  859. "application/json": {
  860. "schema": {
  861. "type": "object",
  862. "properties": {
  863. "project": { "type": "string" },
  864. "collections": { "type": "integer" },
  865. "documents": { "type": "integer" }
  866. }
  867. }
  868. }
  869. }
  870. },
  871. "401": { "description": "Unauthorized" },
  872. "403": { "description": "Forbidden" }
  873. }
  874. }
  875. },
  876. "/api/v1/settings": {
  877. "get": {
  878. "summary": "Get current settings (admin only); openai_api_key is masked to a boolean openai_api_key_set",
  879. "operationId": "getSettings",
  880. "responses": {
  881. "200": {
  882. "description": "Settings (with secret masked)",
  883. "content": {
  884. "application/json": {
  885. "schema": {
  886. "type": "object",
  887. "properties": {
  888. "openai_api_base": { "type": "string" },
  889. "openai_api_key_set": { "type": "boolean" },
  890. "default_embedding_model": { "type": "string" },
  891. "cors_origins": { "type": "array", "items": { "type": "string" } },
  892. "session_ttl_minutes": { "type": "integer" },
  893. "webui_enabled": { "type": "boolean" },
  894. "default_project": { "type": "string" },
  895. "embedding_connect_timeout_sec": { "type": "integer" },
  896. "embedding_read_timeout_sec": { "type": "integer" },
  897. "embedding_cache_size": { "type": "integer" },
  898. "embedding_cache_ttl_sec": { "type": "integer" },
  899. "embedding_cache_max_bytes": { "type": "integer" },
  900. "embedding_cache_normalize": { "type": "boolean" },
  901. "embedding_client_pool_size": { "type": "integer" },
  902. "captcha_provider": { "type": "string" },
  903. "captcha_secret_set": { "type": "boolean", "description": "True when a captcha_secret is configured (the secret itself is never returned)" },
  904. "captcha_verify_url": { "type": "string" }
  905. }
  906. }
  907. }
  908. }
  909. },
  910. "401": { "description": "Unauthorized" },
  911. "403": { "description": "Forbidden — admin required" }
  912. }
  913. },
  914. "put": {
  915. "summary": "Update settings (admin only); omit openai_api_key to keep the existing secret",
  916. "operationId": "updateSettings",
  917. "requestBody": {
  918. "required": true,
  919. "content": {
  920. "application/json": {
  921. "schema": {
  922. "type": "object",
  923. "properties": {
  924. "openai_api_base": { "type": "string" },
  925. "openai_api_key": { "type": "string", "description": "Omit or pass empty string to preserve the existing key" },
  926. "default_embedding_model": { "type": "string" },
  927. "cors_origins": { "type": "array", "items": { "type": "string" } },
  928. "session_ttl_minutes": { "type": "integer", "minimum": 1 },
  929. "webui_enabled": { "type": "boolean" },
  930. "default_project": { "type": "string" },
  931. "embedding_connect_timeout_sec": { "type": "integer", "minimum": 1, "description": "Embedding HTTP connect timeout in seconds (default 10)" },
  932. "embedding_read_timeout_sec": { "type": "integer", "minimum": 1, "description": "Embedding HTTP read timeout in seconds (default 60)" },
  933. "embedding_cache_size": { "type": "integer", "minimum": 0, "description": "Maximum number of cached embedding entries (default 4096)" },
  934. "embedding_cache_ttl_sec": { "type": "integer", "minimum": 0, "description": "Cache entry TTL in seconds; 0 = no expiry (default 86400)" },
  935. "embedding_cache_max_bytes": { "type": "integer", "minimum": 0, "description": "Maximum total bytes of cached vectors (default 268435456 = 256 MB)" },
  936. "embedding_cache_normalize": { "type": "boolean", "description": "When true, text is trimmed and lower-cased before cache lookup (default false)" },
  937. "embedding_client_pool_size": { "type": "integer", "minimum": 1, "description": "Number of keep-alive HTTP clients pooled per upstream origin (default 4)" },
  938. "captcha_provider": { "type": "string", "description": "CAPTCHA provider: empty string to disable, 'turnstile', or 'hcaptcha'" },
  939. "captcha_secret": { "type": "string", "description": "CAPTCHA server-side secret. Omit or pass empty string to preserve the existing secret." },
  940. "captcha_verify_url": { "type": "string", "description": "Full URL of the CAPTCHA verify endpoint (e.g. https://challenges.cloudflare.com/turnstile/v0/siteverify)" }
  941. }
  942. }
  943. }
  944. }
  945. },
  946. "responses": {
  947. "200": { "description": "Settings updated", "content": { "application/json": { "schema": { "type": "object", "properties": { "ok": { "type": "boolean" } } } } } },
  948. "401": { "description": "Unauthorized" },
  949. "403": { "description": "Forbidden — admin required" }
  950. }
  951. }
  952. },
  953. "/api/v1/stats": {
  954. "get": {
  955. "summary": "Server-wide stats (admin only)",
  956. "operationId": "globalStats",
  957. "responses": {
  958. "200": {
  959. "description": "Global stats",
  960. "content": {
  961. "application/json": {
  962. "schema": {
  963. "type": "object",
  964. "properties": {
  965. "projects": { "type": "integer" },
  966. "memory_pressure_level": { "type": "integer" },
  967. "collections": { "type": "integer" },
  968. "documents": { "type": "integer" },
  969. "embedding": { "type": "object", "properties": { "cache_size": { "type": "integer" }, "cache_capacity": { "type": "integer" }, "cache_hits": { "type": "integer" }, "cache_misses": { "type": "integer" }, "cache_hit_ratio": { "type": "number" }, "cache_bytes": { "type": "integer" } } }
  970. }
  971. }
  972. }
  973. }
  974. },
  975. "401": { "description": "Unauthorized" },
  976. "403": { "description": "Forbidden — admin required" }
  977. }
  978. }
  979. }
  980. }
  981. }