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
π
AI Search
online
Today
Dialog 2: Information Not Found
π
AI Search
online
Dialog 3: Document Summary Request
π
AI Search
online
Keywords Used
| Keyword | Purpose |
|---|---|
ADD TOOL | Register search and summary tools |
USE KB | Connect to the knowledge base |
SET CONTEXT | Define the AIβs role and behavior |
ADD SUGGESTION | Create quick action buttons |
BEGIN TALK/END TALK | Multi-line welcome message |
BEGIN SYSTEM PROMPT/END SYSTEM PROMPT | Define AI behavior rules |
How It Works
- Knowledge Base Connection:
USE KBloads your documents for semantic search - Tool Registration:
ADD TOOLenables search and summarization capabilities - Context Setting:
SET CONTEXTtells the AI how to behave - User Query: User asks a question in natural language
- RAG Process: System searches documents, retrieves relevant chunks
- 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
- Organize Documents: Keep documents in logical folders within
.gbdrive - Update Regularly: Re-index knowledge base when documents change
- Clear Context: Set a specific context to improve answer relevance
- Handle Missing Info: Always gracefully handle cases where info isnβt found
- Cite Sources: Configure the AI to cite document sources for credibility
Related Templates
- talk-to-data.md - Query structured data with natural language
- crawler.md - Crawl websites to build knowledge bases