Description
CW Knowledge Base and AI Assistant combines four related WordPress modules into one plugin:
- OpenRouter key store — stores the OpenRouter API key and model encrypted in a custom database table, never in
wp_options, and shares them through simplewp2bor_*functions. - Chat — a ChatGPT-style front-end and wp-admin chat that calls OpenRouter, reads the Markdown knowledge base, and lets visitors rate answers or submit
UPDATE:corrections. - RAG — converts BIO posts and uploaded Markdown into a plain-text knowledge base in
wp-content/uploads/rag/, with an index, topic files, category files, tag files and a machine-readable search index. - BIO Questions — imports memory-jogger questions from CSV files, creates draft posts from them, and turns answered posts into RAG documents.
WordPress.org category: Knowledge Base / AI Chatbots.
Everything is plain Markdown on disk. There is no vector database and no embedding service. The RAG module writes files; the Chat module reads them.
How the pieces fit together
- BIO Questions reads CSV files from
wp-content/uploads/questions/and creates draft posts titled with each question. When an editor adds an answer and saves, the draft publishes. - RAG turns published, draft and private BIO posts into
topic-*.mddocuments and links them fromcat-*.mdandtag-*.mdfiles. - Chat searches the generated index, reads the matching documents, and calls OpenRouter for the answer.
- Visitors can rate an answer or type
UPDATE:to submit a correction. An administrator approves corrections on the Chat → Feedback screen; an approved correction is written to the knowledge base and indexed immediately. - Administrators can also upload Markdown directly on the RAG screen, or upload a chat transcript from the chat footer.
Admin screens
- OpenRouter — save and test the API key and model. The key is shown masked.
- Chat — the same chat interface as the front end, plus Feedback and Report sub-screens.
- RAG — rebuild the knowledge base, upload Markdown, re-index the folder, process chat transcripts and posts, and inspect the knowledge status.
- QUESTIONS — import CSV question files, generate draft posts, and fill demo answers for testing.
Knowledge base files
The RAG module writes to wp-content/uploads/rag/:
index.md— the router: one short row per document with a summary and searchable keywords.topic-<slug>.md— one canonical document per BIO post; the answers live here.cat-<category>.md— a link index over the topics in one BIO category, plus answers folded in from chats and topics.tag-<tag>.md— a link index over the topics sharing a tag..wp2brag-search.json— machine-readable document and section index with line numbers and snippets.correction-feedback-<id>.md— approvedUPDATE:corrections.chat-*.md— uploaded chat transcripts waiting to be filed.archive/— chat transcripts already filed into category summaries.
The plugin never deletes hand-added Markdown files. It only removes its own generated topic-, cat- and tag- files when the underlying post or term is gone.
Memory-jogger questions
The BIO Questions module reads CSV files from wp-content/uploads/questions/. Each row is question,category,tag. The category is a life area such as Childhood, Family, School, Work or Hobbies. The plugin prefixes generated categories with BIO-, so Childhood becomes BIO-Childhood.
On the QUESTIONS screen an administrator can:
- upload a CSV, load one CSV into the table, or reseed every CSV;
- generate draft posts from 1 to 200 questions, in sequential or random order;
- delete generated posts without deleting the questions;
- clear the questions table or remove it entirely;
- fill demo answers for testing.
An empty answer is still catalogued by RAG as _No answer recorded yet._. Answer drafts before rebuilding, or filter the post statuses with wp2brag_post_statuses, so unanswered prompts do not appear in the knowledge base.
Ratings and corrections
A thumbs up or down is stored as a pending feedback row. A rating alone never changes the knowledge base; it is review material and can be exported as JSONL from the Feedback screen. A thumbs down can be followed by a note.
An UPDATE: message is treated as a correction. It is not sent to OpenRouter. The previous question and answer are stored with the correction, and an administrator approves or rejects it on Chat → Feedback. An approved correction becomes correction-feedback-<id>.md and is indexed immediately.
Security and privacy
- The OpenRouter API key is encrypted with libsodium secretbox, or OpenSSL AES-256-GCM as a fallback. The encryption key is derived from the WordPress auth salt. Define
WP2BOR_KEYinwp-config.phpto pin it independently of the salts. - The API key is never printed in full. The admin screen shows only the last four characters.
- Chat history is kept in the browser in a hidden form field and is lost when the page reloads. The only chat text written to the database is the feedback snapshot a visitor explicitly submits.
- The chat appearance settings are stored in the browser’s
localStorageand are not sent to the server. - Uploads are restricted to the WordPress uploads folder. The plugin refuses to overwrite its generated files.
External services
This plugin connects to the following external service.
OpenRouter — used by the Chat module to generate answers.
- Endpoint:
https://openrouter.ai/api/v1/chat/completions - Key test endpoint:
https://openrouter.ai/api/v1/key - Data sent: the chat messages, the selected model, and the conversation context. No site data is sent unless it is part of a chat message or a document the chat reads.
- The API key is supplied by the site owner.
- OpenRouter terms: https://openrouter.ai/terms
- OpenRouter privacy policy: https://openrouter.ai/privacy
Installation
- Upload the
cw-knowledge-base-and-ai-assistantfolder towp-content/plugins/, or install the zip through Plugins → Add New → Upload Plugin. - Activate CW Knowledge Base and AI Assistant.
- Open OpenRouter in wp-admin and save an API key and model. The chat needs this key; the RAG and BIO Questions modules work without it.
- Open RAG and choose Rebuild knowledge to generate the first catalog.
- Open Chat or the generated front-end Chat page to start asking questions.
Frequently Asked Questions
Does the chat need an OpenRouter key?
Yes. The Chat module calls OpenRouter. The RAG and BIO Questions modules work without a key.
Where is the knowledge base stored?
In wp-content/uploads/rag/. The folder name is set by WP2BRAG_DOCS_FOLDER and WP2BCHAT_DOCS_FOLDER. Change both constants together if you rename the folder.
Can I edit the Markdown by hand?
Yes. Add or edit .md files in wp-content/uploads/rag/, then choose Re-index folder on the RAG screen. The plugin never deletes hand-added files.
What happens when I uninstall?
The Markdown catalog and the feedback table are kept. The chat page and plugin options are removed. The encrypted OpenRouter credentials and the BIO questions table are only dropped when you explicitly opt in.
Can I use the chat without the RAG module?
Yes. RAG is the primary source, but the chat also has a fallback 2nd Brain wiki in wp-content/uploads/2ndbrain/. If neither source exists, the chat answers from the model’s own knowledge.
Does the plugin send my documents to OpenRouter?
Only the text the chat actually reads while answering a question. The RAG generator itself is deterministic and does not call any external service.
Changelog
1.0.1
- Security: sanitize the posted chat transcript and conversation history before writing Markdown to
wp-content/uploads/rag/. - Security: decode and sanitize the JSON list of cited documents posted with feedback.
- Fixed the WordPress.org contributor list so it includes the plugin owner account.
1.0.0
- Initial unified release.
- Combines 06 OpenRouter 1.0.3, 100 BIO Questions 1.5.1, 20 Chat 2.1.0 and 25 RAG 2.0.0.
- Single text domain:
cw-knowledge-base-and-ai-assistant. - Single activation entry point and a merged uninstall routine.
- OpenRouter key store, Chat, RAG and BIO Questions keep their original admin screens and settings.