drupal/ai_recipe_basic_rag_chatbot

Provides basic implementation of 'Talk to your content' feature.

Maintainers

Package info

git.drupalcode.org/project/ai_recipe_basic_rag_chatbot.git

Homepage

Issues

Type:drupal-recipe

pkg:composer/drupal/ai_recipe_basic_rag_chatbot

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

1.x-dev 2026-06-11 15:13 UTC

This package is auto-updated.

Last update: 2026-06-11 13:14:45 UTC


README

Adds a "Talk to your content" chatbot to the Drupal admin interface. Editors can ask natural-language questions and the AI agent searches a vector index of site content, returning relevant answers with source links.

Requirements

  • Drupal 10.5+ or 11.2+
  • AI module with a configured default provider for:
    • embeddings — used to index content into the vector store (e.g. OpenAI text-embedding-3-small)
    • chat_with_tools — used by the agent to reason and call the RAG search tool (e.g. OpenAI GPT-4o, Claude Sonnet)
  • A vector-capable database backend supported by search_api_ai_search (e.g. PostgreSQL with pgvector, configured via the database settings in the content_vector server)

Configure default providers at /admin/config/ai/settings → Default Providers.

Apply

composer require drupal/ai_recipe_basic_rag_chatbot
php core/scripts/drupal recipe recipes/contrib/ai_recipe_basic_rag_chatbot
drush cache:rebuild

If chat_with_tools has no default model configured, the recipe apply will abort and roll back. Configure a default model and re-run.

What it does

Transitively applied: ai_recipe_content_search_vector

  • Installs node, search_api, and ai_search.
  • Requires a default embeddings provider to be set.
  • Creates a Search API server (content_vector) using the search_api_ai_search backend with contextual-chunks embedding strategy (chunk size 1000, overlap 100).
  • Creates a Search API index (content_vector) that indexes all node bundles with three fields: rendered HTML output (anonymous view), title, and absolute url.
  • Clones the Default view display of every node type into a search_index view mode used for the rendered HTML field.

This recipe

  • Installs ai_agents, ai_chatbot, and modeler_api.
  • Creates a Content Search Assistant AI agent (content_search_assistant) configured as an orchestration agent with:
    • Up to 3 reasoning loops.
    • The ai_search:rag_search tool locked to the content_vector index, returning up to 5 results with a minimum relevance score of 0.2.
    • A system prompt that instructs the agent to search before answering, reply in the language of the question, and append source links in [Read more](URI) / [Title](URI) format.
  • Creates an AI Assistant (content_search_assistant) backed by the agent above, using the default LLM provider, with session-based conversation history (2-message context window).
  • Places an ai_deepchat_block block (label: Search Chatbot, bot name: Talk to your content) in the content region of the active admin theme (Gin or Claro), visible only to authenticated users.

Using the chatbot

  1. Index your content — after applying the recipe, trigger an initial index run:

    drush search-api:index content_vector
    

    Or visit Configuration → Search API → Content Vector and click Index now. New and updated nodes are indexed automatically on save (index_directly: true); cron processes up to 5 items per run as a fallback.

  2. Open the chatbot — log in as any authenticated user and navigate to any admin page. The chatbot widget appears in the content area.

  3. Ask a question — type a question in natural language. The agent will search the vector index, synthesise an answer, and include links to the relevant pages.

Customising the agent behaviour

The agent's system prompt and tool constraints can be edited at Configuration → AI → Agents → Content Search Assistant (/admin/config/ai/agents/content_search_assistant):

  • Max results / min score — adjust the amount (default 5) and min_score (default 0.2) tool usage limits to trade recall vs. precision.
  • Max loops — increase beyond 3 if complex queries need more search-then-reason iterations.
  • System prompt — rewrite the instructions to change tone, language behaviour, or link formatting.

The chatbot block settings (placement, first message, theme) can be adjusted at Structure → Block layout.

Cost note

Every chatbot turn triggers at least one embeddings call (to vectorise the query) and one chat_with_tools call (the agent reasoning step), plus additional tool calls per loop iteration. High-traffic sites or complex multi-loop queries will incur proportional API costs. Review your provider's pricing before exposing the chatbot to a large authenticated user base.

Issue queue

Bugs and feature requests: https://www.drupal.org/project/issues/ai_recipe_basic_rag_chatbot