Skip to main content

Knowledge Base & RAG

RAG (Retrieval Augmented Generation) enables your AI agents to access and retrieve information from your organization’s knowledge base during conversations. This allows agents to provide accurate, up-to-date responses based on your company’s documentation, FAQs, policies, and other content.

Overview

What is RAG?

RAG combines the power of large language models with your organization’s specific knowledge:
  1. Document Storage: Upload your documents in MD format to knowledge bases
  2. Automatic Indexing: Documents are processed and indexed for semantic search
  3. Real-time Retrieval: During conversations, relevant content is retrieved based on user queries
  4. Context-aware Responses: The agent uses retrieved content to provide accurate answers

When to Use RAG

Ideal Use Cases:
  • Customer support with product documentation
  • Internal helpdesk with company policies
  • Sales agents with pricing and product information
  • Healthcare with protocol and procedure guides
  • Legal assistants with contract templates and regulations
Benefits:
  • Reduce hallucinations by grounding responses in actual documents
  • Keep information current without retraining models
  • Provide source-backed answers for compliance
  • Scale knowledge across multiple agents

Architecture

┌─────────────────────────────────────────────────────────────────────┐
│                        USER CONVERSATION                            │
└─────────────────────────────────────────────────────────────────────┘


┌─────────────────────────────────────────────────────────────────────┐
│                        AI AGENT (LLM)                               │
│                                                                     │
│   User asks: "What's your return policy?"                          │
└─────────────────────────────────────────────────────────────────────┘


┌─────────────────────────────────────────────────────────────────────┐
│                     KNOWLEDGE BASE QUERY                            │
│                                                                     │
│   Query: "return policy refund exchange"                           │
└─────────────────────────────────────────────────────────────────────┘


┌─────────────────────────────────────────────────────────────────────┐
│                    DOCUMENT RETRIEVAL                               │
│                                                                     │
│   Retrieved: "30-day return policy..."                             │
│              "Refund processing takes 5-7 business days..."        │
└─────────────────────────────────────────────────────────────────────┘


┌─────────────────────────────────────────────────────────────────────┐
│                    AUGMENTED RESPONSE                               │
│                                                                     │
│   Agent: "Our return policy allows returns within 30 days.         │
│           Refunds are processed in 5-7 business days..."           │
└─────────────────────────────────────────────────────────────────────┘

Configuration

Step 1: Create a Knowledge Base

First, create a knowledge base to store your documents:
  1. Navigate to Knowledge Bases in the sidebar
  2. Click Create Knowledge Base
  3. Enter a name and optional description
  4. Click Create Create Knowledge Base

Step 2: Upload Documents

Add documents to your knowledge base:
  1. Open your knowledge base
  2. Click Upload Documents
  3. Select files (only MD format supported)
  4. Wait for processing to complete (status: “Indexed”)
Enable RAG on your agent and link the knowledge base:
  1. Open your agent configuration
  2. Navigate to Features tab
  3. Enable RAG / Knowledge Base
  4. Select the knowledge base(s) to link
  5. Save your agent

Schema Reference

RAGFeature

Configuration for the RAG/Knowledge Base feature on an agent.
{
  "version": "v1",
  "isEnabled": true,
  "kbLinks": [
    { "id": "kb_123e4567-e89b-12d3-a456-426614174000" },
    { "id": "kb_987fcdeb-51a2-3bc4-d567-890123456789" }
  ]
}
PropertyTypeDefaultDescription
version"v1" | null"v1"Schema version
isEnabledboolean | nullfalseWhether RAG is enabled for this agent
kbLinksArray<KBLink>[] (required)Links to knowledge bases the agent can query
A reference to a knowledge base.
{
  "id": "kb_123e4567-e89b-12d3-a456-426614174000"
}
PropertyTypeConstraintsDescription
idstringminLength: 1, maxLength: 255Knowledge base identifier

KnowledgeBaseInfo

Full knowledge base information returned by API.
{
  "id": "kb_123e4567-e89b-12d3-a456-426614174000",
  "customerId": "cust_abc123",
  "name": "Customer Support KB",
  "description": "Product documentation and FAQ",
  "type": "Files",
  "createdAt": "2024-01-15T10:30:00Z",
  "updatedAt": "2024-01-15T10:30:00Z",
  "status": "Active",
  "statistics": {
    "knowledgeBaseId": "kb_123e4567-e89b-12d3-a456-426614174000",
    "documentsByStatus": {
      "Indexed": 15,
      "Processing": 2,
      "Failed": 0
    }
  }
}
PropertyTypeDescription
idstring (UUID)Unique knowledge base identifier
customerIdstring (UUID)Organization identifier
namestringKnowledge base name
descriptionstringOptional description
type"Files"Knowledge base type
createdAtstring (ISO 8601)Creation timestamp
updatedAtstring (ISO 8601)Last update timestamp
statusKnowledgeBaseStatusCurrent status
statisticsKnowledgeBaseStatisticsDocument processing statistics

KnowledgeBaseStatus

type KnowledgeBaseStatus = "Active" | "PendingDelete" | "Deleting";

DocumentStatus

type DocumentStatus =
  | "Uploaded"    // File received, awaiting processing
  | "Queued"      // In queue for processing
  | "Processing"  // Currently being indexed
  | "Indexed"     // Successfully indexed and searchable
  | "Failed"      // Processing failed
  | "Cancelled"   // Processing was cancelled
  | "PendingDelete"  // Marked for deletion
  | "Deleting";      // Currently being deleted

API Endpoints

Knowledge Base Management

MethodEndpointDescription
POST/api/v1/rag/kbCreate a knowledge base
GET/api/v1/rag/kbList knowledge bases
GET/api/v1/rag/kb/{id}Get knowledge base details
PUT/api/v1/rag/kb/{id}Update knowledge base
DELETE/api/v1/rag/kb/{id}Delete knowledge base

Document Management

MethodEndpointDescription
POST/api/v1/rag/kb/{id}/documentsUpload document
GET/api/v1/rag/kb/{id}/documentsList documents
GET/api/v1/rag/kb/{id}/documents/{docId}Get document details
DELETE/api/v1/rag/kb/{id}/documents/{docId}Delete document
MethodEndpointDescription
POST/api/v1/rag/searchSearch across knowledge bases

Examples

Complete Agent Configuration with RAG

const createAgentWithRAG = async () => {
  const response = await fetch('https://blackbox.dasha.ai/api/v1/agents', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      name: "Product Support Agent",
      config: {
        version: "v1",
        primaryLanguage: "en-US",
        llmConfig: {
          version: "v1",
          vendor: "openai",
          model: "gpt-4.1-mini",
          prompt: `You are a knowledgeable product support agent for TechCorp.

INSTRUCTIONS:
- Use the knowledge base to answer product questions accurately
- If you're not sure about something, say so honestly
- For complex issues, offer to transfer to a human specialist
- Always be helpful and professional

KNOWLEDGE BASE USAGE:
- Product specifications and features are in the knowledge base
- Warranty and return policies are documented
- Troubleshooting guides are available for common issues`
        },
        ttsConfig: {
          version: "v1",
          vendor: "ElevenLabs",
          voiceId: "YOUR_VOICE_ID",
          model: "eleven_turbo_v2_5"
        },
        features: {
          version: "v1",
          rag: {
            version: "v1",
            isEnabled: true,
            kbLinks: [
              { id: "kb_product_documentation" },
              { id: "kb_support_policies" }
            ]
          },
          silenceManagement: {
            version: "v1",
            isEnabled: true,
            maxReminderAttempts: 2,
            reminderSilenceThresholdSeconds: 5,
            endWhenReminderLimitExceeded: true
          }
        }
      }
    })
  });

  return response.json();
};

Linking Multiple Knowledge Bases

Link different knowledge bases for different purposes:
{
  config: {
    version: "v1",
    features: {
      version: "v1",
      rag: {
        version: "v1",
        isEnabled: true,
        kbLinks: [
          // Product documentation
          { id: "kb_products" },
          // Company policies
          { id: "kb_policies" },
          // FAQ and common questions
          { id: "kb_faq" }
        ]
      }
    }
  }
}

Searching Knowledge Base Programmatically

Test your knowledge base with direct search:
const searchKnowledgeBase = async (query) => {
  const response = await fetch('https://blackbox.dasha.ai/api/v1/rag/search', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      query: query,
      knowledgeBaseNames: ["Customer Support KB"],
      maxResults: 5,
      minScore: 0.5
    })
  });

  const results = await response.json();

  results.items.forEach((item, index) => {
    console.log(`Result ${index + 1}:`);
    console.log(`  Score: ${item.score}`);
    console.log(`  Title: ${item.title}`);
    console.log(`  Content: ${item.content?.substring(0, 200)}...`);
  });

  return results;
};

// Example usage
await searchKnowledgeBase("What is the return policy?");

Best Practices

Document Preparation

1. Structure Your Content
  • Use clear headings and sections
  • Include relevant keywords
  • Keep paragraphs focused on single topics
  • Use consistent terminology
2. Content Quality
  • Remove outdated information before uploading
  • Ensure accuracy of all content
  • Include common variations of terminology
  • Add context for acronyms and technical terms

Knowledge Base Organization

1. Separate by Domain
kb_products       - Product specifications and features
kb_support        - Troubleshooting and support guides
kb_policies       - Return, warranty, and company policies
kb_faq            - Frequently asked questions
2. Keep Updated
  • Regularly review and update documents
  • Remove outdated versions
  • Track document status for processing failures
3. Test Thoroughly
  • Test searches with common customer queries
  • Verify retrieval accuracy
  • Adjust content based on results

System Prompt Integration

1. Reference the Knowledge Base
You have access to our product knowledge base. Use it to:
- Answer specific product questions
- Provide accurate policy information
- Troubleshoot common issues
2. Set Expectations
When you're not sure about something:
- Check the knowledge base first
- If not found, be honest about limitations
- Offer to transfer to a human specialist
3. Handle Gaps
If the knowledge base doesn't contain the answer:
- Acknowledge the limitation
- Offer alternative help options
- Collect feedback for future improvements

Troubleshooting

Documents Not Indexing

Symptoms:
  • Documents stuck in “Processing” status
  • Documents showing “Failed” status
Solutions:
  1. Check document format is supported (MarkDown)
  2. Ensure file size is within limits
  3. Verify document content is extractable
  4. Check for special characters or encoding issues
  5. Re-upload the document if processing failed

Agent Not Using Knowledge Base

Symptoms:
  • Agent doesn’t reference KB content
  • Responses seem generic or incorrect
Solutions:
  1. Verify RAG is enabled (isEnabled: true)
  2. Check knowledge base links are correct
  3. Ensure documents are in “Indexed” status
  4. Test search directly via API
  5. Improve system prompt to explicitly mention KB usage

Poor Search Results

Symptoms:
  • Irrelevant content retrieved
  • Missing expected results
Solutions:
  1. Review document content structure
  2. Add more context and keywords to documents
  3. Adjust minScore threshold if too high
  4. Increase maxResults for broader coverage
  5. Test different query phrasings

Slow Responses

Symptoms:
  • Long delays before agent responds
  • Timeout errors
Solutions:
  1. Reduce maxResults in search configuration
  2. Optimize document count per knowledge base
  3. Split large knowledge bases by topic
  4. Check network latency to API

Limitations

  • File Size: Individual documents have size limits
  • Processing Time: Large documents may take longer to index
  • Format Support: Limited to MD format
  • Query Length: Search queries have character limits
  • Results Count: Maximum results per search is limited

Next Steps

Now that you understand RAG and Knowledge Base:
  1. Create Your First KB: Start with a small set of core documents
  2. Test Retrieval: Use the search API to verify content is accessible
  3. Configure Agent: Link KB and update system prompt
  4. Monitor Performance: Track usage and accuracy
  5. Iterate: Add documents and refine based on real conversations

API Cross-Refs