openapi.json 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957
  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. "requestBody": {
  532. "required": true,
  533. "content": {
  534. "application/json": {
  535. "schema": {
  536. "type": "object",
  537. "properties": {
  538. "data": {
  539. "type": "object",
  540. "description": "Arbitrary JSON document payload"
  541. }
  542. }
  543. }
  544. }
  545. }
  546. },
  547. "responses": {
  548. "201": {
  549. "description": "Document inserted",
  550. "content": {
  551. "application/json": {
  552. "schema": {
  553. "type": "object",
  554. "properties": {
  555. "id": { "type": "string" }
  556. }
  557. }
  558. }
  559. }
  560. },
  561. "401": { "description": "Unauthorized" },
  562. "403": { "description": "Forbidden" },
  563. "404": { "description": "Collection not found" },
  564. "422": { "description": "Validation error" },
  565. "429": { "description": "Too Many Requests (rate-limited scoped key)" }
  566. }
  567. }
  568. },
  569. "/api/v1/projects/{project}/collections/{name}/documents/{id}": {
  570. "parameters": [
  571. {
  572. "name": "project",
  573. "in": "path",
  574. "required": true,
  575. "schema": { "type": "string" },
  576. "description": "Project name"
  577. },
  578. {
  579. "name": "name",
  580. "in": "path",
  581. "required": true,
  582. "schema": { "type": "string" },
  583. "description": "Collection name"
  584. },
  585. {
  586. "name": "id",
  587. "in": "path",
  588. "required": true,
  589. "schema": { "type": "string" },
  590. "description": "Document ID"
  591. }
  592. ],
  593. "get": {
  594. "summary": "Get a document by ID",
  595. "operationId": "getDocument",
  596. "responses": {
  597. "200": {
  598. "description": "Document",
  599. "content": {
  600. "application/json": {
  601. "schema": { "type": "object" }
  602. }
  603. }
  604. },
  605. "401": { "description": "Unauthorized" },
  606. "403": { "description": "Forbidden" },
  607. "404": { "description": "Document not found" },
  608. "429": { "description": "Too Many Requests (rate-limited scoped key)" }
  609. }
  610. },
  611. "put": {
  612. "summary": "Replace a document (full upsert by ID)",
  613. "operationId": "replaceDocument",
  614. "requestBody": {
  615. "required": true,
  616. "content": {
  617. "application/json": {
  618. "schema": { "type": "object" }
  619. }
  620. }
  621. },
  622. "responses": {
  623. "200": { "description": "Document replaced" },
  624. "401": { "description": "Unauthorized" },
  625. "403": { "description": "Forbidden" },
  626. "404": { "description": "Collection not found" },
  627. "422": { "description": "Validation error" },
  628. "429": { "description": "Too Many Requests (rate-limited scoped key)" }
  629. }
  630. },
  631. "patch": {
  632. "summary": "Partially update a document (merge fields)",
  633. "operationId": "patchDocument",
  634. "requestBody": {
  635. "required": true,
  636. "content": {
  637. "application/json": {
  638. "schema": { "type": "object" }
  639. }
  640. }
  641. },
  642. "responses": {
  643. "200": { "description": "Document updated" },
  644. "401": { "description": "Unauthorized" },
  645. "403": { "description": "Forbidden" },
  646. "404": { "description": "Document not found" },
  647. "422": { "description": "Validation error" },
  648. "429": { "description": "Too Many Requests (rate-limited scoped key)" }
  649. }
  650. },
  651. "delete": {
  652. "summary": "Delete a document by ID",
  653. "operationId": "deleteDocument",
  654. "responses": {
  655. "200": { "description": "Document deleted" },
  656. "401": { "description": "Unauthorized" },
  657. "403": { "description": "Forbidden" },
  658. "404": { "description": "Document not found" },
  659. "429": { "description": "Too Many Requests (rate-limited scoped key)" }
  660. }
  661. }
  662. },
  663. "/api/v1/projects/{project}/collections/{name}/vectors": {
  664. "parameters": [
  665. {
  666. "name": "project",
  667. "in": "path",
  668. "required": true,
  669. "schema": { "type": "string" },
  670. "description": "Project name"
  671. },
  672. {
  673. "name": "name",
  674. "in": "path",
  675. "required": true,
  676. "schema": { "type": "string" },
  677. "description": "Collection name (must be kind=vector)"
  678. }
  679. ],
  680. "post": {
  681. "summary": "Store a vector; supply either text (auto-embedded) or an explicit vector array",
  682. "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.",
  683. "operationId": "upsertVector",
  684. "requestBody": {
  685. "required": true,
  686. "content": {
  687. "application/json": {
  688. "schema": {
  689. "type": "object",
  690. "properties": {
  691. "id": {
  692. "type": "string",
  693. "description": "Optional stable ID; auto-generated if omitted"
  694. },
  695. "text": {
  696. "type": "string",
  697. "description": "Source text; will be embedded using the collection's embedding_model"
  698. },
  699. "vector": {
  700. "type": "array",
  701. "items": { "type": "number" },
  702. "description": "Pre-computed embedding; dimension must match the collection's vector_dimension"
  703. },
  704. "metadata": {
  705. "type": "object",
  706. "description": "Arbitrary JSON payload stored alongside the vector"
  707. }
  708. }
  709. }
  710. }
  711. }
  712. },
  713. "responses": {
  714. "201": {
  715. "description": "Vector stored",
  716. "content": {
  717. "application/json": {
  718. "schema": {
  719. "type": "object",
  720. "properties": {
  721. "id": { "type": "string" }
  722. }
  723. }
  724. }
  725. }
  726. },
  727. "401": { "description": "Unauthorized" },
  728. "403": { "description": "Forbidden" },
  729. "404": { "description": "Collection not found" },
  730. "422": { "description": "Validation error (wrong dimension, not a vector collection, etc.)" },
  731. "429": { "description": "Too Many Requests (rate-limited scoped key)" }
  732. }
  733. }
  734. },
  735. "/api/v1/projects/{project}/collections/{name}/search": {
  736. "parameters": [
  737. {
  738. "name": "project",
  739. "in": "path",
  740. "required": true,
  741. "schema": { "type": "string" },
  742. "description": "Project name"
  743. },
  744. {
  745. "name": "name",
  746. "in": "path",
  747. "required": true,
  748. "schema": { "type": "string" },
  749. "description": "Collection name (must be kind=vector)"
  750. }
  751. ],
  752. "post": {
  753. "summary": "Cosine-similarity search; supply either query_text (auto-embedded) or query_vector",
  754. "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.",
  755. "operationId": "searchVectors",
  756. "requestBody": {
  757. "required": true,
  758. "content": {
  759. "application/json": {
  760. "schema": {
  761. "type": "object",
  762. "properties": {
  763. "query_text": {
  764. "type": "string",
  765. "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."
  766. },
  767. "query_vector": {
  768. "type": "array",
  769. "items": { "type": "number" },
  770. "description": "Pre-computed query embedding (length must equal the collection's vector_dimension). Fast path: skips server-side embedding."
  771. },
  772. "top_k": {
  773. "type": "integer",
  774. "minimum": 1,
  775. "description": "Maximum number of results to return"
  776. },
  777. "min_score": {
  778. "type": "number",
  779. "description": "Minimum cosine similarity score (0–1)"
  780. },
  781. "filters": {
  782. "type": "array",
  783. "items": { "type": "string" },
  784. "description": "Metadata filters in field:op:value grammar (e.g. src:eq:n8n)"
  785. }
  786. },
  787. "required": ["top_k"]
  788. }
  789. }
  790. }
  791. },
  792. "responses": {
  793. "200": {
  794. "description": "Search results",
  795. "content": {
  796. "application/json": {
  797. "schema": {
  798. "type": "object",
  799. "properties": {
  800. "results": {
  801. "type": "array",
  802. "items": {
  803. "type": "object",
  804. "properties": {
  805. "id": { "type": "string" },
  806. "score": { "type": "number" },
  807. "metadata": { "type": "object" }
  808. }
  809. }
  810. }
  811. }
  812. }
  813. }
  814. }
  815. },
  816. "401": { "description": "Unauthorized" },
  817. "403": { "description": "Forbidden" },
  818. "404": { "description": "Collection not found" },
  819. "422": { "description": "Validation error" },
  820. "429": { "description": "Too Many Requests (rate-limited scoped key)" }
  821. }
  822. }
  823. },
  824. "/api/v1/projects/{project}/stats": {
  825. "parameters": [
  826. {
  827. "name": "project",
  828. "in": "path",
  829. "required": true,
  830. "schema": { "type": "string" },
  831. "description": "Project name"
  832. }
  833. ],
  834. "get": {
  835. "summary": "Per-project stats (accessible by any key granted the project)",
  836. "operationId": "projectStats",
  837. "responses": {
  838. "200": {
  839. "description": "Project stats",
  840. "content": {
  841. "application/json": {
  842. "schema": {
  843. "type": "object",
  844. "properties": {
  845. "project": { "type": "string" },
  846. "collections": { "type": "integer" },
  847. "documents": { "type": "integer" }
  848. }
  849. }
  850. }
  851. }
  852. },
  853. "401": { "description": "Unauthorized" },
  854. "403": { "description": "Forbidden" }
  855. }
  856. }
  857. },
  858. "/api/v1/settings": {
  859. "get": {
  860. "summary": "Get current settings (admin only); openai_api_key is masked to a boolean openai_api_key_set",
  861. "operationId": "getSettings",
  862. "responses": {
  863. "200": {
  864. "description": "Settings (with secret masked)",
  865. "content": {
  866. "application/json": {
  867. "schema": {
  868. "type": "object",
  869. "properties": {
  870. "openai_api_base": { "type": "string" },
  871. "openai_api_key_set": { "type": "boolean" },
  872. "default_embedding_model": { "type": "string" },
  873. "cors_origins": { "type": "array", "items": { "type": "string" } },
  874. "session_ttl_minutes": { "type": "integer" },
  875. "webui_enabled": { "type": "boolean" },
  876. "default_project": { "type": "string" },
  877. "embedding_connect_timeout_sec": { "type": "integer" },
  878. "embedding_read_timeout_sec": { "type": "integer" },
  879. "embedding_cache_size": { "type": "integer" },
  880. "embedding_cache_ttl_sec": { "type": "integer" },
  881. "embedding_cache_max_bytes": { "type": "integer" },
  882. "embedding_cache_normalize": { "type": "boolean" },
  883. "embedding_client_pool_size": { "type": "integer" }
  884. }
  885. }
  886. }
  887. }
  888. },
  889. "401": { "description": "Unauthorized" },
  890. "403": { "description": "Forbidden — admin required" }
  891. }
  892. },
  893. "put": {
  894. "summary": "Update settings (admin only); omit openai_api_key to keep the existing secret",
  895. "operationId": "updateSettings",
  896. "requestBody": {
  897. "required": true,
  898. "content": {
  899. "application/json": {
  900. "schema": {
  901. "type": "object",
  902. "properties": {
  903. "openai_api_base": { "type": "string" },
  904. "openai_api_key": { "type": "string", "description": "Omit or pass empty string to preserve the existing key" },
  905. "default_embedding_model": { "type": "string" },
  906. "cors_origins": { "type": "array", "items": { "type": "string" } },
  907. "session_ttl_minutes": { "type": "integer", "minimum": 1 },
  908. "webui_enabled": { "type": "boolean" },
  909. "default_project": { "type": "string" },
  910. "embedding_connect_timeout_sec": { "type": "integer", "minimum": 1, "description": "Embedding HTTP connect timeout in seconds (default 10)" },
  911. "embedding_read_timeout_sec": { "type": "integer", "minimum": 1, "description": "Embedding HTTP read timeout in seconds (default 60)" },
  912. "embedding_cache_size": { "type": "integer", "minimum": 0, "description": "Maximum number of cached embedding entries (default 4096)" },
  913. "embedding_cache_ttl_sec": { "type": "integer", "minimum": 0, "description": "Cache entry TTL in seconds; 0 = no expiry (default 86400)" },
  914. "embedding_cache_max_bytes": { "type": "integer", "minimum": 0, "description": "Maximum total bytes of cached vectors (default 268435456 = 256 MB)" },
  915. "embedding_cache_normalize": { "type": "boolean", "description": "When true, text is trimmed and lower-cased before cache lookup (default false)" },
  916. "embedding_client_pool_size": { "type": "integer", "minimum": 1, "description": "Number of keep-alive HTTP clients pooled per upstream origin (default 4)" }
  917. }
  918. }
  919. }
  920. }
  921. },
  922. "responses": {
  923. "200": { "description": "Settings updated", "content": { "application/json": { "schema": { "type": "object", "properties": { "ok": { "type": "boolean" } } } } } },
  924. "401": { "description": "Unauthorized" },
  925. "403": { "description": "Forbidden — admin required" }
  926. }
  927. }
  928. },
  929. "/api/v1/stats": {
  930. "get": {
  931. "summary": "Server-wide stats (admin only)",
  932. "operationId": "globalStats",
  933. "responses": {
  934. "200": {
  935. "description": "Global stats",
  936. "content": {
  937. "application/json": {
  938. "schema": {
  939. "type": "object",
  940. "properties": {
  941. "projects": { "type": "integer" },
  942. "memory_pressure_level": { "type": "integer" },
  943. "collections": { "type": "integer" },
  944. "documents": { "type": "integer" },
  945. "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" } } }
  946. }
  947. }
  948. }
  949. }
  950. },
  951. "401": { "description": "Unauthorized" },
  952. "403": { "description": "Forbidden — admin required" }
  953. }
  954. }
  955. }
  956. }
  957. }