appendSources citations ·
retriever warmup() at startup ·
AI autoresponder ·
cost and latency settings
Prerequisites
- Node.js 22.12 or newer.
- An Anthropic API key in the
ANTHROPIC_API_KEYenvironment variable (or another model provider, see below).
Your FAQ
Save it asfaq.md next to bot.js. Each ## section becomes one passage
the model can cite.
The bot
How it works
- Retrieval on every turn. Before each answer the plugin calls
retrieve(question)and adds the passages to the system prompt as a numbered block, with instructions to answer from them, cite them as[n]and treat them as data, not instructions. - Citations. With
appendSources: truethe reply ends with the sources the model cited. When nothing matches, no passage is sent and the persona makes the model say it does not know instead of guessing. - Never fails a reply. If the retriever throws or takes longer than
timeoutMs(10 s by default), the turn goes on without context. - Startup.
warmup()reads the file when the bot starts, so the first question does not wait for it. - Bigger knowledge bases. Replace
markdownRetrieverwith a call to your vector database or search API: any object withretrieve(query)that resolves{ text, citation?, score? }passages works.
Ready-made retriever:
@botmesh/ragThe @botmesh/rag package has loaders
(Markdown, text, JSON, PDF), chunking, embeddings (local, OpenAI or Ollama) and
a persisted index: rag: { retriever: createRag({ documents: ['./faq.md'] }), appendSources: true }.
Install it with npm install @botmesh/rag; see
@botmesh/rag.Try it
faq.md next to it.
The model is scripted by the test that runs this page
(packages/ai/tests/docs-examples-ai.test.ts), which also checks that the right
FAQ section reached the model; the retrieval and the sources line are real.
Other model providers
Switch to OpenAI, Gemini or a local Ollama model
Switch to OpenAI, Gemini or a local Ollama model
Only the provider options change; Gemini (Ollama on your machine (no package, no key; run
rag stays the same.OpenAI (npm install openai, key in OPENAI_API_KEY):npm install @google/genai, key in GEMINI_API_KEY):ollama pull llama3.1 first):Run it on WhatsApp or Telegram
node bot.js prints a QR code: scan it with WhatsApp (Linked devices).
For Telegram, install @botmesh/telegram and start the factory with
new TelegramProvider({ token: process.env.TELEGRAM_TOKEN ?? '' }).
Next steps
- AI memory & RAG guide: every
ragoption, and per-user memory - AI router: send payments to a deterministic flow and the rest to the AI
- Examples overview