DokuBrain
Guides

Search & RAG

Hybrid search and AI-powered Q&A across your document corpus.

Search & RAG

DokuBrain provides two ways to find information in your documents: hybrid search for finding relevant chunks, and RAG queries for getting AI-generated answers with source citations.

Hybrid search combines semantic (vector) similarity with keyword matching for the best of both worlds. Semantic search understands meaning ("payment overdue" matches "past due balance"), while keyword search catches exact terms (invoice numbers, names).

Hybrid search
curl -X POST https://api.dokubrain.com/api/v1/corpus/search \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "non-compete clause duration",
    "project_ids": ["proj_abc123"],
    "limit": 10,
    "threshold": 0.7
  }'

Search parameters

ParameterTypeDefaultDescription
querystringrequiredThe search query
limitnumber10Maximum results to return
thresholdnumber0.5Minimum similarity score (0-1)
project_idsstring[]allFilter by project
documentTypesstring[]allFilter by document type

RAG queries

RAG (Retrieval-Augmented Generation) queries retrieve relevant document chunks and use an LLM to generate an answer based on them:

RAG query
curl -X POST https://api.dokubrain.com/api/v1/corpus/query \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "question": "What are the termination conditions in the Acme contract?",
    "project_ids": ["proj_abc123"],
    "includeSourceChunks": true
  }'
RAG response
{
  "success": true,
  "data": {
    "answer": "The Acme contract can be terminated under three conditions: (1) either party may terminate with 30 days written notice, (2) immediate termination for material breach, (3) automatic termination if Acme fails to make payment within 60 days of the due date.",
    "sources": [
      {
        "documentId": "doc_xyz789",
        "documentName": "Acme_Services_Agreement.pdf",
        "chunkText": "Either party may terminate this Agreement...",
        "page": 12,
        "score": 0.94
      }
    ],
    "quality": {
      "relevancy": 0.95,
      "grounding": 0.98,
      "hallucinationRisk": "low"
    }
  }
}

Quality scoring

Every RAG response includes quality metrics:

  • Relevancy — how well the answer addresses the question (0-1)
  • Grounding — how well the answer is supported by source chunks (0-1)
  • Hallucination risklow, medium, or high

Multi-step reasoning

For complex questions that require reasoning across multiple documents, use multi-step queries:

Multi-step reasoning
curl -X POST https://api.dokubrain.com/api/v1/corpus/query \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "question": "Compare the liability caps across all our vendor contracts",
    "mode": "multi_step",
    "maxSteps": 5
  }'

Multi-step mode is useful for compliance reviews, risk assessments, and cross-document analysis.

On this page