Knowledge Bases API
Knowledge Bases allow you to store and search healthcare documents, clinical guidelines, and domain-specific information that AI Workers can reference during conversations. They use vector search to find relevant information based on semantic similarity.
Base URL
https://api.engine.boolbyte.com/api/knowledgebase
Create Knowledge Base
POST /api/knowledgebase/create
Creates a new knowledge base for storing searchable information.
Using JavaScript SDK:
import { EngineClient } from '@boolbyte/engine';
const client = new EngineClient({ apiKey: 'YOUR_API_KEY' });
const knowledgeBase = await client.knowledgeBase.createKnowledgeBase({
name: 'clinical-guidelines',
description: 'Medical guidelines and protocols for clinical decision support'
});
Request Body:
{
"name": "clinical-guidelines",
"description": "Medical guidelines and protocols for clinical decision support",
"type": "manual",
"source": "uploaded_document"
}
Response:
{
"success": true,
"message": "Knowledge base created successfully",
"data": {
"id": "kb-123",
"name": "clinical-guidelines",
"description": "Medical guidelines and protocols for clinical decision support",
"type": "manual",
"status": "ready",
"source": "uploaded_document",
"chunkCount": 0,
"lastUpdated": "2024-01-15T10:30:00.000Z",
"nextUpdateAt": null,
"updateFrequency": null,
"errorMessage": null,
"createdAt": "2024-01-15T10:30:00.000Z",
"updatedAt": "2024-01-15T10:30:00.000Z"
}
}
Create Knowledge Base from File
POST /api/knowledgebase/upload
Creates a knowledge base from an uploaded file. Supports PDF, DOCX, TXT, and other document formats.
Using JavaScript SDK:
const knowledgeBase = await client.knowledgeBase.createKnowledgeBaseFromFile(
medicalGuidelinesFile, // File object
'Medical Guidelines',
'Comprehensive medical treatment guidelines'
);
Request (multipart/form-data):
curl -X POST https://api.engine.boolbyte.com/api/knowledgebase/upload \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "[email protected]" \
-F "name=Medical Guidelines" \
-F "description=Comprehensive medical treatment guidelines"
Response:
{
"success": true,
"message": "Knowledge base created from file successfully",
"data": {
"id": "kb-456",
"name": "Medical Guidelines",
"description": "Comprehensive medical treatment guidelines",
"createdAt": "2024-01-15T10:30:00Z",
"updatedAt": "2024-01-15T10:30:00Z"
}
}
List Knowledge Bases
GET /api/knowledgebase/list
Retrieves all knowledge bases for your team.
Using JavaScript SDK:
const knowledgeBases = await client.knowledgeBase.listKnowledgeBases();
Response:
{
"success": true,
"message": "Knowledge bases retrieved successfully",
"data": [
{
"id": "kb-123",
"name": "clinical-guidelines",
"description": "Medical guidelines and protocols for clinical decision support",
"createdAt": "2024-01-15T10:30:00Z",
"updatedAt": "2024-01-15T10:30:00Z"
},
{
"id": "kb-456",
"name": "Medical Guidelines",
"description": "Comprehensive medical treatment guidelines",
"createdAt": "2024-01-15T10:35:00Z",
"updatedAt": "2024-01-15T10:35:00Z"
}
]
}
Get Knowledge Base
GET /api/knowledgebase/{knowledgeBaseId}
Retrieves details about a specific knowledge base.
Using JavaScript SDK:
const knowledgeBase = await client.knowledgeBase.getKnowledgeBase('kb-123');
Response:
{
"success": true,
"message": "Knowledge base retrieved successfully",
"data": {
"id": "kb-123",
"name": "clinical-guidelines",
"description": "Medical guidelines and protocols for clinical decision support",
"createdAt": "2024-01-15T10:30:00Z",
"updatedAt": "2024-01-15T10:30:00Z"
}
}
Supported File Types
Knowledge bases support various document formats:
| File Type | Extensions | Description |
|---|---|---|
.pdf | Medical reports, guidelines, research papers | |
| Word Documents | .docx, .doc | Clinical protocols, treatment plans |
| Text Files | .txt, .md | Simple text documents, notes |
| CSV | .csv | Structured data, patient lists |
| HTML | .html, .htm | Web-based documentation |
File Size Limits
- Maximum file size: 50 MB per file
- Maximum files per knowledge base: 100 files
- Processing time: 1-5 minutes depending on file size and complexity
Common Use Cases
Clinical Guidelines Knowledge Base
// Upload clinical guidelines
const guidelinesKB = await client.knowledgeBase.createKnowledgeBaseFromFile(
clinicalGuidelinesPDF,
'Clinical Guidelines 2024',
'Latest clinical practice guidelines for common conditions'
);
// Use with a worker
const worker = await client.worker.createWorker({
name: 'clinical-assistant',
description: 'AI assistant with access to clinical guidelines',
defaultModelName: 'openai/gpt-4',
toolConfigs: {
tools: [
{
toolName: 'knowledge_search',
config: {
knowledgeBaseId: guidelinesKB.data.id,
searchThreshold: 0.75,
maxResults: 5
}
}
]
}
});
Drug Information Database
// Create knowledge base for drug information
const drugKB = await client.knowledgeBase.createKnowledgeBaseFromFile(
drugDatabaseFile,
'Drug Information Database',
'Comprehensive drug information including dosages, interactions, and contraindications'
);
Research Papers Repository
// Upload research papers
const researchKB = await client.knowledgeBase.createKnowledgeBaseFromFile(
researchPapersPDF,
'Medical Research Papers',
'Collection of recent medical research papers and studies'
);
Hospital Policies and Procedures
// Create knowledge base for hospital policies
const policiesKB = await client.knowledgeBase.createKnowledgeBaseFromFile(
hospitalPoliciesFile,
'Hospital Policies',
'Internal hospital policies, procedures, and protocols'
);
Integration with Workers
Knowledge bases are typically integrated with AI Workers through tool configurations. Workers can search and reference knowledge base content during conversations.
Example: Clinical Decision Support Worker
const clinicalWorker = await client.worker.createWorker({
name: 'clinical-decision-support',
description: 'AI assistant for clinical decision support with access to guidelines',
instructions: 'You are a clinical decision support assistant. Use the knowledge base to provide evidence-based recommendations.',
defaultModelName: 'openai/gpt-4',
toolConfigs: {
tools: [
{
toolName: 'knowledge_search',
config: {
knowledgeBaseId: 'kb-123',
searchThreshold: 0.8,
maxResults: 3
}
},
{
toolName: 'fhir_access',
config: {
serverId: 'fhir-server-123',
permissions: ['read'],
resourceTypes: ['Patient', 'Condition', 'MedicationStatement']
}
}
]
}
});
Example: Medication Assistant
const medicationWorker = await client.worker.createWorker({
name: 'medication-assistant',
description: 'AI assistant for medication information and dosing',
instructions: 'Help healthcare providers with medication information, dosing, and interactions.',
defaultModelName: 'openai/gpt-4',
toolConfigs: {
tools: [
{
toolName: 'knowledge_search',
config: {
knowledgeBaseId: 'kb-456', // Drug information database
searchThreshold: 0.75,
maxResults: 5
}
}
]
}
});
Best Practices
1. Organize Content by Topic
Create separate knowledge bases for different types of content:
- Clinical guidelines
- Drug information
- Research papers
- Hospital policies
2. Use Descriptive Names and Descriptions
const kb = await client.knowledgeBase.createKnowledgeBase({
name: 'diabetes-management-guidelines-2024',
description: 'ADA 2024 guidelines for diabetes management including medication protocols, monitoring recommendations, and patient education materials'
});
3. Regular Updates
Keep knowledge bases current by uploading updated documents:
// Update existing knowledge base with new content
const updatedKB = await client.knowledgeBase.createKnowledgeBaseFromFile(
updatedGuidelinesFile,
'Updated Clinical Guidelines',
'Latest version of clinical guidelines with new recommendations'
);
4. Optimize Search Results
Configure appropriate search thresholds and result limits:
toolConfigs: {
tools: [
{
toolName: 'knowledge_search',
config: {
knowledgeBaseId: 'kb-123',
searchThreshold: 0.8, // Higher threshold for more relevant results
maxResults: 3 // Limit results to avoid overwhelming responses
}
}
]
}
Error Handling
{
"success": false,
"message": "Knowledge base not found",
"data": null,
"error": {
"code": "knowledge_base_not_found",
"details": "Knowledge base with ID 'kb-123' not found"
}
}
Common Error Codes
knowledge_base_not_found: Knowledge base ID doesn't existfile_too_large: Uploaded file exceeds size limitunsupported_file_type: File type is not supportedprocessing_failed: File processing failedname_taken: Knowledge base name already exists
Next Steps
- Workers - Attach knowledge bases to AI Workers
- Sessions & Tasks - Use knowledge in conversations
- Storage API - Manage file storage for knowledge bases
- Toolkits - Explore available tools for knowledge integration