Black Branch/Docs
All sections

Inside the AI features

This page is for owners who have switched on, or are thinking about, the AI features. After reading it you know which program asks the model for what, how your keys are handled, how memory stores and finds old chat, and why memory stops itself with an alarm rather than carrying on wrongly.

The chat bot, automod, the help desk and memory all use a model from an AI provider you connect yourself. Setting them up, what each one does and what they cost are in The chat bot and AI features.

Who does what

Feature Which program asks the model What happens
Chat bot stream-ingest It listens to every chat message. When one mentions the bot, it builds the request (the behaviour text, recent chat, and what memory finds), asks the model, and posts the answer through stream-api as the bot's account. The reply passes the same word filter and link rules as a viewer's message
Automod, site messages stream-api, asked by the website The website asks before posting a site message. stream-api asks the model within its time limit and, if the message is risky, holds it for a mod
Automod, platform messages stream-ingest Checked in the background after the message is delivered. A risky one is flagged for mods, because it is already public on its platform
Help desk stream-ingest, through stream-api The help pop-up sends the question to the website, which passes it to stream-api, which queues it for stream-ingest to answer
Memory stream-ingest makes the numbers, stream-api stores and searches them See Memory below

A slow or failing model never stops chat. Automod lets a message through unchecked when its time runs out, the bot skips a reply it could not get, and memory is extra context the bot can do without.

The AI adapter

Every model request goes through one piece of code, the AI adapter. It uses no provider's software kit. It speaks two plain HTTPS formats itself:

Format Used for
Anthropic Messages Anthropic's Claude models
OpenAI-compatible (/chat/completions, /embeddings, /models) OpenAI, and every service that answers in the same format: OpenRouter, Ollama, LM Studio, vLLM and many more

Speaking the formats directly means any service that follows one of them works without a code change.

Slots

A feature never names a model. It names a slot, a job such as "Chat bot replies", and the adapter looks up which connection and model that slot runs on. The product has four slots:

Slot Job Longest answer Time allowed
bot.reply Chat bot replies 300 tokens 20 s
automod.classify Automod check (must answer in JSON) 120 tokens 1.2 s
helpdesk.answer Help desk answers 300 tokens 60 s
embeddings Memory (not text) 8 s

A slot with nothing set is off, so a new install makes no AI requests at all until you connect a provider and switch a feature on. In Admin Panel → AI → Models, Simple mode runs every chat slot on one default model, and Advanced mode lets each slot have its own, falling back to the default. A slot can also be pinned in the server's environment, which wins over the Admin Panel. A site plugin can add slots of its own.

Bring your own key

Your keys are stored encrypted, like every credential (see Credentials). The adapter keeps a few rules about them:

Memory

Memory lets the bot recall things said in chat long ago, not only in the last few minutes. It works with embeddings: a model turns a piece of text into a long list of numbers (a vector), so that texts with similar meaning get similar numbers. Finding "what was said about this before" then means finding the stored vectors closest to the question's vector.

Storing

  1. A chat message of at least four words (memory.minWords, 4 by default) is sent to the embeddings slot. Bots, the bot's own lines, and people who asked not to be remembered are left out.
  2. stream-api, the only writer, stores the vector with the message in a Postgres table that uses pgvector. An HNSW index makes searching it fast.
  3. Old memories are removed after memory.retentionDays, 90 days by default.

Only OpenAI-compatible connections can make embeddings. Anthropic has no embeddings service.

Finding

When the bot answers, it turns the question into a vector the same way and asks stream-api for the closest stored messages: at most five, only ones close enough to be relevant, and only a limited amount of text in total, so memory cannot crowd out the rest of the request.

The dimension comes from the database

Every embedding model makes vectors of one fixed length, its dimension (for example 1,536 numbers). Vectors of different lengths, or from different models, cannot be compared. So there is one source of truth for the dimension: the type of the database column (1,536 on a new install). No code carries the number.

Paused, with one alarm

When stream-api starts, it compares the column's dimension with memory.state. Whenever something is wrong that will not fix itself, memory pauses:

Reason What it means
Dimension mismatch The column and the recorded model disagree
Key rejected The provider refused the key
Quota The provider's account is out of credit or over its limit
Model not found The model is gone or misspelled
Store refused A vector did not fit the store

While memory is paused, nothing new is stored, and the bot answers without memory. One alarm says why: "Message memory stopped". The alternative, carrying on while storing nothing (or storing vectors that can never match), is the failure this design exists to prevent: a memory that quietly stopped months ago looks exactly like one that works.

To resume, fix the cause (a new key, credit on the account, another model) and press Resume in Admin Panel → AI → Embeddings. Resume asks the model for a test vector first and only resumes if it fits. Saving a new key or connection tries this by itself a few times.

Network errors and provider outages are different: they usually clear by themselves, so memory keeps trying and raises an alarm only after five failures in a row.

Alarms always go to stream-api's log (sudo blackbranch logs stream-api). To get them on your phone too, see Alerts pushed to your phone.

Next: Settings and modules

← How it works