=== DocuBot AI by secureweb ===
Contributors: Secure Web Technologies, secureweb16
Donate link: https://securewebtechnologies.com/
Tags: chatbot, ai, rag, openai, groq, support, knowledge base
Requires at least: 6.0
Tested up to: 7.0
Stable tag: 1.4.0
Requires PHP: 7.4
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

AI-powered Q&A chatbot using Retrieval-Augmented Generation (RAG). Upload documents or write manual knowledge entries and let the AI answer visitor questions accurately.

== Description ==

DocuBot AI by secureweb allows you to create an intelligent customer support agent directly on your WordPress site. Unlike standard AI chatbots that give generic answers, this plugin uses **Retrieval-Augmented Generation (RAG)**. This means you can upload your own documents (PDF, DOCX, TXT) or write manual knowledge entries, and the AI will use *your* specific content to answer user questions.

### ✨ Key Features:
*   **Custom Knowledge Base:** Upload PDF, DOCX, or TXT files, or type knowledge manually in the admin dashboard.
*   **Chunk-level Editing:** Edit your AI's knowledge base block-by-block directly from the admin panel.
*   **Multiple LLM Support:** Choose between Groq (Llama 3, Mixtral, Gemma) for blazing fast responses, or OpenAI (GPT-4o).
*   **Customizable Widget:** Easily change the chatbot color, icon position, welcome message, and quick reply suggestions.
*   **No Coding Required:** Simple interface to train your AI and customize its appearance.

### ⚠️ External API & Privacy Disclosure (Important)
This plugin relies on third-party services to generate embeddings and chat responses. By using this plugin, you agree to send data to these services.

*   **OpenAI:** Used for generating document embeddings (text-embedding-3-small) and optionally for chat completions (GPT-4o, GPT-4o-mini). When a user asks a question, or when you upload a document, the text content is sent to OpenAI's servers. 
    *   [OpenAI Privacy Policy](https://openai.com/policies/privacy-policy)
    *   [OpenAI Terms of Service](https://openai.com/policies/terms-of-use)
*   **Groq:** Optionally used for blazing fast chat completions using models like Llama 3 or Mixtral. When a user asks a question, the query and relevant context from your database are sent to Groq's servers.
    *   [Groq Privacy Policy](https://groq.com/privacy-policy/)
    *   [Groq Terms of Use](https://groq.com/terms-of-use/)

**What data is sent?**
*   During document upload/manual entry: The text content of your documents is sent to OpenAI to generate mathematical embeddings.
*   During a chat session: The user's question, plus small snippets of your documents (the context), are sent to the selected AI provider (Groq or OpenAI) to generate the answer.

== Installation ==

1. Upload the plugin files to the `/wp-content/plugins/docubot-ai-secureweb-plugin` directory, or install the plugin through the WordPress plugins screen directly.
2. Activate the plugin through the 'Plugins' screen in WordPress.
3. Run `composer install` inside the plugin directory to install required dependencies (`smalot/pdfparser` and `phpoffice/phpword`). *(Note: If you downloaded a pre-built zip, this step might not be needed).*
4. Navigate to **AI Chatbot RAG** in your WordPress dashboard.
5. Go to the **AI & API Credentials** tab and enter your OpenAI API key (required for embeddings) and optionally your Groq API key.
6. Upload documents or write manual content in the **Knowledge Base** tab to train your AI.

== Frequently Asked Questions ==

= Do I need an OpenAI API Key? =
Yes, an OpenAI API key is currently required to generate mathematical embeddings for your documents (using the `text-embedding-3-small` model), even if you use Groq for the chat responses. If no OpenAI key is provided, the plugin will fall back to a less accurate "keyword match" system.

= What file types can I upload? =
The plugin currently supports `.txt`, `.pdf`, and `.docx` files. You can also write content manually directly in the dashboard.

= Where are my documents stored? =
The raw files are uploaded to your standard WordPress `wp-content/uploads/ai-docs/` folder. The extracted text is chunked and stored in a custom database table (`wp_docubot_ai_secureweb_embeddings`).

== Screenshots ==

1. The Knowledge Base management dashboard.
2. The AI & API Credentials setup screen.
3. The Chat Widget in action on the frontend.

== Changelog ==

= 1.4.0 =
* **Critical Change:** AI now answers **ONLY from uploaded content and data** — no more general knowledge or made-up answers. If info not in knowledge base, says sorry.
* **Critical Change:** Language auto-detection — **English by default**, auto-switches to Hindi if user asks in Hindi. No forced Hinglish.
* **Improved:** Higher relevance threshold (0.15) ensures only genuinely matching content is used for answers.
* **Improved:** Empty knowledge base message simplified to a clear English/Hindi message.
* **Updated:** Version bumped to 1.4.0.

= 1.3.0 =
* **Major Improvement:** Enhanced keyword similarity with prefix/partial matching for better Hindi-English mixed queries.
* **Major Improvement:** AI always receives at least some context data - no more "upload nahi kiya" responses when data exists.
* **Major Improvement:** Completely revamped response formatting engine - supports **bold**, *italic*, bullet lists, numbered lists, and proper paragraph spacing.
* **Improved:** New Hinglish-friendly system prompt - AI speaks Hindi+English mix with emojis for a human-like feel.
* **Improved:** Empty knowledge base message now shows friendly Hinglish text with emoji guidance.
* **Improved:** Enhanced CSS with rich text styling  - styled lists, code blocks, inline code, headings inside chat bubbles.
* **Updated:** Version bumped to 1.3.0.

= 1.2.1 =
* Added manual knowledge entry feature.
* Added inline chunk editing via AJAX.
* Refactored code structure to meet WordPress.org directory guidelines.
* Improved security with comprehensive nonce checks and capability checks.
* Extracted inline CSS and JS into separate enqueued files.

= 1.1.0 =
* Initial stable release with Groq and OpenAI support.
