forked from willynikes2/knowledge-base-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenapi.json
More file actions
542 lines (542 loc) · 23.4 KB
/
openapi.json
File metadata and controls
542 lines (542 loc) · 23.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
{
"openapi": "3.1.0",
"info": {
"title": "KB Brain API",
"version": "1.0.0",
"description": "Knowledge Base Brain API. Use this API to search, read, and ingest documents from the personal knowledge base. When you need to find information about projects, architecture, configurations, debugging sessions, or any accumulated knowledge, use the search and context endpoints. Use ingest and capture endpoints to record new knowledge, bug fixes, or research."
},
"servers": [
{
"url": "https://brain.cutdacord.app",
"description": "Production Brain API"
},
{
"url": "http://localhost:3838",
"description": "Local development"
}
],
"security": [
{
"BearerAuth": []
}
],
"components": {
"securitySchemes": {
"BearerAuth": {
"type": "http",
"scheme": "bearer",
"description": "API key as Bearer token. Use your KB_API_KEY_OPENAI value."
},
"ApiKeyAuth": {
"type": "apiKey",
"in": "header",
"name": "X-API-Key",
"description": "Alternative: API key via X-API-Key header"
}
},
"schemas": {
"SearchResult": {
"type": "object",
"properties": {
"id": { "type": "integer", "description": "Unique document identifier" },
"title": { "type": "string", "description": "Document title" },
"snippet": { "type": "string", "description": "Relevant excerpt from the document matching the search query" },
"doc_type": { "type": "string", "description": "Document type (e.g. note, tutorial, bookmark, config, debug-session, fix-pattern, web-article)" },
"tags": { "type": "array", "items": { "type": "string" }, "description": "Tags associated with the document" },
"file_size": { "type": "integer", "description": "Document size in bytes" },
"created_at": { "type": "string", "format": "date-time", "description": "Document creation timestamp" },
"rank": { "type": "number", "description": "Search relevance rank score" }
}
},
"Document": {
"type": "object",
"properties": {
"id": { "type": "integer" },
"title": { "type": "string" },
"content": { "type": "string", "description": "Full document content" },
"source": { "type": "string", "description": "Origin source URL or path" },
"doc_type": { "type": "string" },
"tags": { "type": "array", "items": { "type": "string" } },
"file_path": { "type": "string", "description": "Path to source file if applicable" },
"file_size": { "type": "integer" },
"created_at": { "type": "string", "format": "date-time" },
"updated_at": { "type": "string", "format": "date-time" }
}
},
"CaptureResponse": {
"type": "object",
"properties": {
"id": { "type": "integer" },
"title": { "type": "string" },
"vault_path": { "type": "string", "description": "Path in the Obsidian vault where the document was saved" },
"created_at": { "type": "string", "format": "date-time" }
}
},
"Error": {
"type": "object",
"properties": {
"error": { "type": "string", "description": "Error message" }
}
}
}
},
"paths": {
"/api/v1/health": {
"get": {
"operationId": "healthCheck",
"summary": "Health check",
"description": "Check if the KB Brain API is running and healthy. No authentication required. Returns status and uptime.",
"security": [],
"responses": {
"200": {
"description": "Service is healthy",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"status": { "type": "string", "example": "ok" },
"uptime": { "type": "number", "description": "Server uptime in seconds" }
}
}
}
}
}
}
}
},
"/api/v1/stats": {
"get": {
"operationId": "getStats",
"summary": "Knowledge base statistics",
"description": "Returns aggregate statistics about the knowledge base: total document count, total content size, and database size. Useful for understanding the scope of the knowledge base.",
"responses": {
"200": {
"description": "KB statistics",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"total_documents": { "type": "integer", "description": "Total number of documents in the KB" },
"total_size_bytes": { "type": "integer", "description": "Total size of all document content in bytes" },
"db_size_bytes": { "type": "integer", "description": "Total PostgreSQL database size in bytes" }
}
}
}
}
},
"401": { "description": "Missing or invalid API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
}
}
},
"/api/v1/search": {
"get": {
"operationId": "search",
"summary": "Full-text search",
"description": "Search the knowledge base using PostgreSQL full-text search. Use this to find documents, notes, tutorials, bookmarks, or any indexed content. The query supports natural language. Use the type parameter to narrow results to a specific document category. Results are ranked by relevance.",
"parameters": [
{
"name": "q",
"in": "query",
"required": true,
"description": "Search query string. Supports natural language and keyword combinations.",
"schema": { "type": "string" }
},
{
"name": "limit",
"in": "query",
"required": false,
"description": "Maximum number of results to return. Defaults to 10, max 50.",
"schema": { "type": "integer", "default": 10, "maximum": 50 }
},
{
"name": "type",
"in": "query",
"required": false,
"description": "Filter by document type (e.g. note, tutorial, bookmark, config, debug-session, fix-pattern, web-article).",
"schema": { "type": "string" }
},
{
"name": "project",
"in": "query",
"required": false,
"description": "Filter results by project name or tag.",
"schema": { "type": "string" }
}
],
"responses": {
"200": {
"description": "Search results ranked by relevance",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"results": {
"type": "array",
"items": { "$ref": "#/components/schemas/SearchResult" }
}
}
}
}
}
},
"400": { "description": "Missing required query parameter q", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
"401": { "description": "Missing or invalid API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
}
}
},
"/api/v1/search/smart": {
"get": {
"operationId": "smartSearch",
"summary": "Hybrid semantic + full-text search",
"description": "Advanced search combining full-text search with semantic/vector similarity. Use this when a regular search returns poor results or when you need conceptually related documents even if they don't share exact keywords. Better for finding information about a topic expressed in different terms.",
"parameters": [
{
"name": "q",
"in": "query",
"required": true,
"description": "Search query. Supports natural language, concepts, and keywords.",
"schema": { "type": "string" }
},
{
"name": "limit",
"in": "query",
"required": false,
"description": "Maximum number of results to return. Defaults to 10.",
"schema": { "type": "integer", "default": 10 }
},
{
"name": "type",
"in": "query",
"required": false,
"description": "Filter by document type.",
"schema": { "type": "string" }
},
{
"name": "project",
"in": "query",
"required": false,
"description": "Filter by project.",
"schema": { "type": "string" }
}
],
"responses": {
"200": {
"description": "Semantically ranked search results",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"results": {
"type": "array",
"items": { "$ref": "#/components/schemas/SearchResult" }
}
}
}
}
}
},
"400": { "description": "Missing required query parameter q", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
"401": { "description": "Missing or invalid API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
}
}
},
"/api/v1/context": {
"get": {
"operationId": "getContext",
"summary": "Token-efficient knowledge briefing",
"description": "Returns a synthesized briefing on a topic for LLM consumption. Returns a narrative summary with source citations instead of raw documents. Use to quickly understand a topic without reading full documents.",
"parameters": [
{
"name": "q",
"in": "query",
"required": true,
"description": "Topic or question to generate a briefing for.",
"schema": { "type": "string" }
},
{
"name": "limit",
"in": "query",
"required": false,
"description": "Maximum number of source documents to include in briefing. Defaults to 5.",
"schema": { "type": "integer", "default": 5 }
}
],
"responses": {
"200": {
"description": "Synthesized briefing with source citations",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"briefing": { "type": "string", "description": "Synthesized narrative briefing on the topic" },
"sources": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": { "type": "integer" },
"title": { "type": "string" }
}
},
"description": "Source documents used to generate the briefing"
}
}
}
}
}
},
"400": { "description": "Missing required query parameter q", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
"401": { "description": "Missing or invalid API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
}
}
},
"/api/v1/documents": {
"get": {
"operationId": "listDocuments",
"summary": "List documents",
"description": "Browse and paginate through all documents in the knowledge base. Filter by document type or tag to narrow results. Useful for exploring what's available or listing all documents of a specific category.",
"parameters": [
{
"name": "type",
"in": "query",
"required": false,
"description": "Filter by document type (e.g. note, tutorial, bookmark, config, debug-session, fix-pattern, web-article).",
"schema": { "type": "string" }
},
{
"name": "tag",
"in": "query",
"required": false,
"description": "Filter by a specific tag.",
"schema": { "type": "string" }
},
{
"name": "limit",
"in": "query",
"required": false,
"description": "Number of documents per page. Defaults to 20, max 100.",
"schema": { "type": "integer", "default": 20, "maximum": 100 }
},
{
"name": "offset",
"in": "query",
"required": false,
"description": "Number of documents to skip for pagination. Defaults to 0.",
"schema": { "type": "integer", "default": 0 }
}
],
"responses": {
"200": {
"description": "Paginated list of documents",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"documents": {
"type": "array",
"items": { "$ref": "#/components/schemas/Document" }
},
"total": { "type": "integer", "description": "Total number of documents matching the filters" }
}
}
}
}
},
"401": { "description": "Missing or invalid API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
}
}
},
"/api/v1/documents/{id}": {
"get": {
"operationId": "getDocument",
"summary": "Read full document",
"description": "Retrieve the complete content of a specific document by its ID. Use this after a search to read the full text of a result. Returns all metadata and the complete document content.",
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"description": "Document ID as returned by search or list endpoints.",
"schema": { "type": "integer" }
}
],
"responses": {
"200": {
"description": "Full document with content and metadata",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/Document" }
}
}
},
"401": { "description": "Missing or invalid API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
"404": { "description": "Document not found", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
}
}
},
"/api/v1/ingest": {
"post": {
"operationId": "ingestDocument",
"summary": "Ingest text content into the knowledge base",
"description": "Add a new document to the knowledge base by providing text content directly. Use this to store notes, summaries, research findings, or any text that should be searchable later. The document will be indexed for full-text and semantic search immediately.",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"required": ["title", "content"],
"properties": {
"title": { "type": "string", "description": "Document title" },
"content": { "type": "string", "description": "Full text content to ingest" },
"doc_type": { "type": "string", "description": "Document type classification (e.g. note, research, summary)", "default": "note" },
"tags": { "type": "array", "items": { "type": "string" }, "description": "Tags for categorization and filtering" },
"source": { "type": "string", "description": "Source URL or reference for the content" }
}
}
}
}
},
"responses": {
"201": {
"description": "Document successfully ingested",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"id": { "type": "integer" },
"title": { "type": "string" },
"created_at": { "type": "string", "format": "date-time" }
}
}
}
}
},
"400": { "description": "Missing required fields title or content", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
"401": { "description": "Missing or invalid API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
}
}
},
"/api/v1/capture/session": {
"post": {
"operationId": "captureSession",
"summary": "Record a debugging session",
"description": "Capture and store a debugging session for future reference. Use this to record what happened during a troubleshooting session: the problem, steps taken, commands run, and resolution. Stored as a structured debug-session document for later retrieval.",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"required": ["title", "problem", "resolution"],
"properties": {
"title": { "type": "string", "description": "Brief title describing the issue" },
"problem": { "type": "string", "description": "Description of the problem encountered" },
"steps": { "type": "array", "items": { "type": "string" }, "description": "Ordered list of debugging steps taken" },
"resolution": { "type": "string", "description": "How the problem was resolved" },
"tags": { "type": "array", "items": { "type": "string" }, "description": "Tags for categorization (e.g. project name, technology)" },
"commands": { "type": "array", "items": { "type": "string" }, "description": "Key commands or code snippets used during debugging" }
}
}
}
}
},
"responses": {
"201": {
"description": "Debugging session recorded",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/CaptureResponse" }
}
}
},
"400": { "description": "Missing required fields", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
"401": { "description": "Missing or invalid API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
}
}
},
"/api/v1/capture/fix": {
"post": {
"operationId": "captureFix",
"summary": "Record a bug fix pattern",
"description": "Store a bug fix as a reusable pattern. Use this when you fix a bug that could recur, to capture the root cause, fix approach, and prevention strategy. These patterns are indexed as fix-pattern documents and help avoid repeating the same mistakes.",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"required": ["title", "bug", "fix"],
"properties": {
"title": { "type": "string", "description": "Concise title for the fix pattern" },
"bug": { "type": "string", "description": "Description of the bug and its symptoms" },
"root_cause": { "type": "string", "description": "Root cause of the bug" },
"fix": { "type": "string", "description": "The fix applied and why it works" },
"prevention": { "type": "string", "description": "How to prevent this class of bug in the future" },
"tags": { "type": "array", "items": { "type": "string" }, "description": "Tags for categorization" },
"code_before": { "type": "string", "description": "Code snippet before the fix" },
"code_after": { "type": "string", "description": "Code snippet after the fix" }
}
}
}
}
},
"responses": {
"201": {
"description": "Fix pattern recorded",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/CaptureResponse" }
}
}
},
"400": { "description": "Missing required fields", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
"401": { "description": "Missing or invalid API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
}
}
},
"/api/v1/capture/web": {
"post": {
"operationId": "captureWeb",
"summary": "Capture and store a web article",
"description": "Fetch and ingest a web article or page into the knowledge base by URL. The content will be extracted, cleaned, and stored as a web-article document for future search and retrieval. Use this to save useful blog posts, documentation pages, or any online resource.",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"required": ["url"],
"properties": {
"url": { "type": "string", "format": "uri", "description": "URL of the web page to capture" },
"tags": { "type": "array", "items": { "type": "string" }, "description": "Tags to apply to the captured document" },
"title_override": { "type": "string", "description": "Optional custom title to use instead of the page title" }
}
}
}
}
},
"responses": {
"201": {
"description": "Web article captured and ingested",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/CaptureResponse" }
}
}
},
"400": { "description": "Missing required field url or invalid URL", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
"401": { "description": "Missing or invalid API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
"422": { "description": "Failed to fetch or parse the web page", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
}
}
}
}
}