Skip to content

Getting started

This page takes a Drupal 11 site from nothing to a working knowledge search, using the reference setup: Search API, AI Search, Qdrant, and OpenAI or Ollama for embeddings. Exact versions are in the support matrix.

Before you start

You need:

  • Drupal 11.2 or later on PHP 8.3, managed with Composer and Drush.
  • A Qdrant database the site can reach.
  • An embedding provider: an OpenAI API key, or an Ollama server with an embedding model such as qwen3-embedding:0.6b.
  • Optionally, a chat model for reranking and generated summaries. Retrieval works without one.

Decide where your content may go. Builds send every selected item, including unpublished and access-restricted content, to the embedding provider. If that content must stay on your servers, use Ollama.

Only the Query API?

To use the PHP Query API with your own retrieval, install the base module alone: composer require 'drupal/drupal_rag_toolkit:^1.0@alpha' and drush en drupal_rag_toolkit. Nothing else is downloaded.

1. Install the packages and patches

Until the changes land upstream, the reference setup patches five packages: Drupal AI, the OpenAI and Ollama providers, AI Search and the Qdrant provider. The patches ship in the package's support-assets/ folder with checksums. Your site owns Composer Patches and its patch files. On a project with no existing patches/, patches.json or patches.lock.json, the bootstrap script copies them in after checking their checksums:

composer require 'drupal/drupal_rag_toolkit:^1.0@alpha'
(
  set -euo pipefail
  toolkit_dir=web/modules/contrib/drupal_rag_toolkit
  bash "$toolkit_dir/support-assets/bootstrap.sh" --consumer-root "$PWD"
  composer config --json allow-plugins.cweagans/composer-patches true
  composer config extra.composer-patches.patches-file patches.json
  composer require 'cweagans/composer-patches:^2.0'
)
composer require \
  'drupal/ai:1.4.11' \
  'drupal/search_api:^1.41' \
  'drupal/ai_search:1.3.0-alpha5' \
  'drupal/ai_vdb_provider_qdrant:1.3.3'

If your site already has a patch manifest, do not run the bootstrap. Copy the five files from support-assets/patches/ into patches/ and merge their entries from support-assets/patches.json by hand.

Composer Patches 1.x works too; you don't need to upgrade. List the same entries inline under extra.patches in composer.json, with paths such as ./patches/<file>, and leave out the Ollama patch if you don't use Ollama.

Then add one embedding provider:

# OpenAI
composer require 'drupal/ai_provider_openai:1.2.5' \
  'openai-php/client:0.20.1' 'guzzlehttp/guzzle:7.15.5' --with-all-dependencies
# or Ollama
composer require 'drupal/ai_provider_ollama:^1.2@RC'

The toolkit checks these exact versions before it sends anything to a provider. If Composer refuses because other locked packages have security advisories, require each version with --no-update and then update only that package, for example composer update openai-php/client.

Enable the modules with the recipe. Drush reads the path from Drupal's web root:

drush recipe modules/contrib/drupal_rag_toolkit/recipes/public-qdrant

2. Connect the providers

  1. Store your API key with the Key module, outside the web root, and select it in the Drupal AI provider settings. See provider and secret handling.
  2. Configure the Qdrant provider with your database's address.
  3. In Search API, create a server with the AI Search backend, the Qdrant database, the Cosine similarity metric and the Drupal RAG contextual chunks embedding strategy. For a hosted model its embeddings engine does not matter; the corpus's model sets it.
  4. Edit the disabled drupal_rag_public index and select that server. The index is a template that every build copies, so leave it disabled.

3. Name the environment

Each installation owns its own Qdrant collections, so a copy of the site, such as staging, never writes to production's. Add to settings.php, with a new UUID for every copy:

$settings['drupal_rag_toolkit_resource_scope'] = [
  'version' => 1,
  'scope_id' => '<a new UUID>',
  'namespace' => 'site',
];
$settings['drupal_rag_toolkit_search_api_tokenizer_vocabulary_directory'] = '/path/outside/webroot/tokenizer';

Indexing counts tokens locally, so chunks fit the model. Download the vocabulary file named in the tokenizer instructions into that directory; the package does not include it.

Open Configuration → Web services → RAG → RAG setup preflight, select Initialize environment, then choose the Embedding model and save it. The model is part of the corpus configuration: export configuration and it deploys to your other environments with the rest of the pipeline. Builds send every selected item to that provider, including unpublished and access-restricted content.

For a hosted model such as OpenAI's, the server's engine and dimensions follow from the model. For Ollama, also select the same model as the template server's embeddings engine and enter its dimensions, because Drupal AI names Ollama models by a machine key; refresh Ollama's model list in Drupal AI first.

Each check that is still blocked says what to do; the sources and active index checks clear in the next steps.

4. Run the build workers

Builds run in a separate Drush process. Run this every minute, from cron or a systemd timer, as the web server's user:

drush drupal-rag-toolkit:dispatch-queued

It does nothing when no build is waiting. Without it, the Index lifecycle page shows the exact command to run a queued build by hand.

5. Set up the profile

Open Public RAG profile:

  • Purpose: one line describing what the search is for, such as "Answers questions about the services provided by the government of Washington, DC." Reranking uses it to reject passages about something else.
  • Reranking: with a chat model selected, each retrieved passage is scored for how directly it answers the question. A minimum score of 7 works well.
  • Generation: select a chat model to offer generated summaries.

Set these before the first build: the build takes a copy of the profile, and validation uses it. Without reranking, results must reach the profile's relevance threshold (0.55 by default); for OpenAI's text-embedding-3-small, 0.50 or reranking works better.

6. Build, validate and activate

  1. In Corpus Builder, choose the content types, fields and metadata to index, and save the draft. Saving indexes nothing yet. Text held in paragraphs is listed as Field › Paragraph field, such as Content › Description; it is read in paragraph order.
  2. On Index lifecycle, choose the number of workers and select Build candidate, then Start source workers. 12 workers is a good default for OpenAI. As a guide, 500 nodes take about 2 minutes and 5,000 nodes about 30.
  3. When the build finishes, validate it with a question your content answers. If the corpus has taxonomy metadata, also give one term ID for each field; validation checks that filtering on it returns results.
  4. Activate it. From now on, saving a node updates the active index.
  5. On RAG setup preflight, select Enable desired public RAG profile. Search stays unavailable until you do.

From a deploy script

The same steps run from Drush, so a deployment can build without a browser or the worker runner:

drush drupal-rag-toolkit:initialize            # once per environment
drush drupal-rag-toolkit:preflight --before-build
drush drupal-rag-toolkit:build --workers=12    # prints the candidate's ID
drush drupal-rag-toolkit:reindex-validate <candidate> \
  --question="Where can residents get help paying rent?" \
  --term=demo_audience=<term UUID>
drush drupal-rag-toolkit:reindex-activate <candidate>

preflight prints the checks of RAG setup preflight as JSON and exits with 1 when one fails; --before-build skips the active index check. Metadata keys are the ones the validation form shows. build uses the only enabled Corpus Builder draft for the default corpus, or the one named with --draft. Give --term once for each metadata field of the corpus; taxonomy terms may be IDs or UUIDs, and UUIDs are the same in every environment.

If a build fails, the page shows a short reason, and Reports → Recent log messages (type drupal_rag_toolkit_search_api) has the cause, such as an unreachable vector database.

To change what is indexed later, edit the draft and build a new candidate. The active index keeps serving until you activate the new one.

7. Try it

Use Test query to see the outcome, sources and timings for a question.

For a ready-made visitor page, apply the sample recipe:

drush recipe modules/contrib/drupal_rag_toolkit/recipes/knowledge-search

It adds a Knowledge search View at /knowledge-search that lists the recommended sources and offers a generated summary with citations, streamed as it is written. It is optional; edit or delete it like any other View.

How the summary cites its sources is set under Citations on the profile settings page:

  • Cite each claim in the answer puts a marker such as [1] after each claim. A visitor clicks it to open the cited page, in a new tab by default. Claim-by-claim citing needs a capable generation model; an answer that piles all its markers at the end is shown without markers.
  • Citation markers open the page in a new tab or the same tab, or are plain text.
  • Marker style is numbers ([1]) or letters ([a]).
  • List the sources below the answer adds the numbered source list.

Next, write an evaluation set so you can measure changes. See Evaluating quality.

Uninstalling

drush pmu drupal_rag_toolkit_search_api drupal_rag_toolkit -y

Uninstalling deletes the toolkit's configuration, its Search API indexes and servers, and its records, so a later install starts fresh. Qdrant collections are kept and listed by name, because deleting vectors cannot be undone; after the uninstall the toolkit can no longer remove them, so delete them in Qdrant.

To delete the collections as well, stop serving and remove every index first, once per profile:

drush drupal-rag-toolkit:reindex-deactivate default
drush drupal-rag-toolkit:retire-historical
drush pmu drupal_rag_toolkit_search_api drupal_rag_toolkit -y

The settings.php lines are yours to remove. Uninstalling refuses while a build is running: pause it with drush drupal-rag-toolkit:reindex-parallel-pause first.