Q&A Bots Enterprise SDK
The Q&A Bot SDK is designed for precise, single-turn question-answering. It is highly optimized for integration into customer support portals, helpdesk FAQ sections, and lookup applications such as employee handbooks, compliance policies, and product documentation.
Unlike the full conversational ChatBot, the Q&A Bot does not track long-term memory or message history. This stateless behavior reduces latency, lowers API costs, and ensures clean response isolation for standalone lookup queries.
Getting Started
Initialize the Q&A Bot with a knowledge database or folder of documents.
Simple Q&A Example
import { QABot } from '@ai-horizon/sdk';
const qaBot = QABot.initialize({
input_dir: "./compliance_policies",
system_prompt: "You are a strict compliance checking assistant. Cite policies exactly."
});
// Perform a single-shot query
const result = await qaBot.query("What is the policy for business travel reimbursement?");
console.log("Answer:", result.answer);Supported Source Formats
Just like the ChatBot, the Q&A Bot supports multiple target document formats:
// Init from PDF
const qaFromPdf = QABot.pdf_qa({
input_files: ["./docs/employee_handbook.pdf"]
});
// Init from a Webpage
const qaFromWeb = QABot.webpage_qa({
urls: ["https://support.mycompany.com/faq"]
});
// Init from a Word doc
const qaFromDocx = QABot.docx_qa({
input_files: ["./specs/product_user_guide.docx"]
});Key Configurations for Q&A Bot
The initialization methods support configuration options tailored for high-accuracy lookups:
| Parameter | Type | Default | Description |
|---|---|---|---|
input_dir | string | null | Folder path containing reference documents. |
input_files | Array | [] | List of files to index. |
similarity_top_k | number | 3 | Number of relevant chunks retrieved to answer the question. |
score_threshold | number | 0.7 | Minimum similarity score required to include a document source. Helps reduce hallucinations. |
system_prompt | string | null | Guides the system's focus and answering rules. |
stream | boolean | false | When true, response chunks are streamed for low-latency client rendering. |
Handling "I don't know" Responses
One of the most important aspects of enterprise compliance is preventing the AI from hallucinating. You can instruct the Q&A Bot to only reply based on retrieved sources:
const qaBot = QABot.pdf_qa({
input_files: ["./docs/security_audit.pdf"],
system_prompt: "Answer the question ONLY based on the provided context. If the answer is not in the context, reply 'Information not found in database.'"
});
const result = await qaBot.query("What was our 2024 revenue?");
// If 2024 revenue is not in the audit PDF, it will return "Information not found in database."