openapi.json 34 KB

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