Keyboard shortcuts

Press ← or β†’ to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

AI Search Template

The AI Search template provides an intelligent document search bot that uses AI to answer questions based on your uploaded documents. It combines vector search with large language models for accurate, context-aware responses.

Topic: AI-Powered Document Search & Q&A

This template is perfect for:

  • Knowledge base assistants
  • Document-based customer support
  • Internal documentation search
  • FAQ automation with source documents

The Code

REM AI Search - Intelligent Document Q&A
REM Uses RAG (Retrieval Augmented Generation) for accurate answers

' Add search tools
ADD TOOL "search-documents"
ADD TOOL "summarize-document"

' Use the knowledge base
USE KB "ai-search.gbkb"

' Set up the AI context
SET CONTEXT "document-search" AS "You are a helpful document search assistant. Answer questions based on the documents in your knowledge base. Always cite your sources when possible. If the answer is not in the documents, say so clearly."

' Clear and add suggestions
CLEAR SUGGESTIONS
ADD SUGGESTION "search" AS "Search documents"
ADD SUGGESTION "summary" AS "Get document summary"
ADD SUGGESTION "help" AS "How to use"

BEGIN TALK
**AI Search Assistant** πŸ”

I can help you find information in your documents using AI-powered search.

**What I can do:**
β€’ Search across all uploaded documents
β€’ Answer questions with context
β€’ Summarize long documents
β€’ Find specific information quickly

Just ask me a question or describe what you're looking for.
END TALK

BEGIN SYSTEM PROMPT
You are an AI document search assistant with access to a knowledge base of documents.

When answering questions:
1. Search the knowledge base for relevant information
2. Provide accurate answers based on the documents
3. Cite the source document when possible
4. If information isn't found, clearly state that
5. Offer to search for related topics

Be concise but thorough. Always prioritize accuracy over speed.
END SYSTEM PROMPT

Sample Dialogs

These conversations show how the AI Search template works in real-world scenarios.

Dialog 1: Document Search Query

Dialog 2: Information Not Found

Dialog 3: Document Summary Request

Keywords Used

KeywordPurpose
ADD TOOLRegister search and summary tools
USE KBConnect to the knowledge base
SET CONTEXTDefine the AI’s role and behavior
ADD SUGGESTIONCreate quick action buttons
BEGIN TALK/END TALKMulti-line welcome message
BEGIN SYSTEM PROMPT/END SYSTEM PROMPTDefine AI behavior rules

How It Works

  1. Knowledge Base Connection: USE KB loads your documents for semantic search
  2. Tool Registration: ADD TOOL enables search and summarization capabilities
  3. Context Setting: SET CONTEXT tells the AI how to behave
  4. User Query: User asks a question in natural language
  5. RAG Process: System searches documents, retrieves relevant chunks
  6. AI Response: LLM generates answer based on retrieved context

Template Structure

ai-search.gbai/
β”œβ”€β”€ ai-search.gbdialog/
β”‚   β”œβ”€β”€ start.bas          # Main entry point
β”‚   └── qr.bas             # QR code handler
β”œβ”€β”€ ai-search.gbdrive/
β”‚   └── manuals/           # Folder for PDF documents
β”‚       └── 42LB5800.pdf   # Example manual
β”œβ”€β”€ ai-search.gbkb/
β”‚   └── docs/              # Knowledge base documents
β”‚       └── README.md      # KB documentation
└── ai-search.gbot/
    └── config.csv         # Bot configuration

Customization Ideas

Add Document Categories

ADD SUGGESTION "manuals" AS "πŸ“š Product Manuals"
ADD SUGGESTION "policies" AS "πŸ“‹ Policies"
ADD SUGGESTION "tutorials" AS "πŸŽ“ Tutorials"

HEAR category

SWITCH category
    CASE "manuals"
        USE KB "manuals.gbkb"
    CASE "policies"
        USE KB "policies.gbkb"
    CASE "tutorials"
        USE KB "tutorials.gbkb"
END SWITCH

Add Source Citations

SET CONTEXT "search-with-citations" AS "Always include the document name and page number when citing information. Format: [Document Name, Page X]"

Add Search Filters

PARAM search_query AS STRING LIKE "how to reset" DESCRIPTION "What to search for"
PARAM doc_type AS STRING LIKE "manual" DESCRIPTION "Type of document: manual, policy, guide"

DESCRIPTION "Search documents with optional type filter"

IF doc_type <> "" THEN
    results = FIND "documents.csv", "type = '" + doc_type + "'"
    ' Search within filtered results
ELSE
    ' Search all documents
END IF

Add Follow-up Questions

TALK "Here's what I found about your question..."
TALK response

TALK "Would you like me to:"
ADD SUGGESTION "more" AS "Tell me more"
ADD SUGGESTION "related" AS "Show related topics"
ADD SUGGESTION "new" AS "Ask new question"
HEAR followup

IF followup = "more" THEN
    ' Provide more detail
ELSE IF followup = "related" THEN
    ' Show related topics
END IF

Best Practices

  1. Organize Documents: Keep documents in logical folders within .gbdrive
  2. Update Regularly: Re-index knowledge base when documents change
  3. Clear Context: Set a specific context to improve answer relevance
  4. Handle Missing Info: Always gracefully handle cases where info isn’t found
  5. Cite Sources: Configure the AI to cite document sources for credibility