Skip to content

Deploying across environments

Your RAG pipeline (what to index, how to embed it, how to answer, and the pages that search it) is configuration. Build it once on a development site, export it, and deploy it to test and live like the rest of your site's configuration. Each environment then builds its own index from its own content, with its own vector database and keys.

What deploys and what stays

Deploys with exported configuration Stays with each environment
Corpus Builder drafts: content types, fields, metadata Content
The corpus, including its embedding model The RAG indexes built from it, and their Qdrant collections
The profile: purpose, reranking, generation, limits, enabled The environment's scope in settings.php
The template index drupal_rag_public and its server's settings The Qdrant host and API key (Qdrant provider settings, Key)
Views on the template index, such as the knowledge search page Provider API keys (Key)
The tokenizer directory in settings.php
Evaluation sets (content entities; move them with Drush)

Keep the environment-owned values in settings.php or a config split, as you would for any other host or key. Drupal's configuration import refuses to import another environment's generated RAG indexes, so environments never share or overwrite each other's resources.

Setting up each environment once

On every environment, before its first build:

  1. Add the scope, with a UUID unique to that environment, and the tokenizer directory to settings.php:
$settings['drupal_rag_toolkit_resource_scope'] = [
  'version' => 1,
  'scope_id' => '<a UUID for this environment>',
  'namespace' => 'site',
];
$settings['drupal_rag_toolkit_search_api_tokenizer_vocabulary_directory'] = '/path/outside/webroot/tokenizer';
  1. Deploy the code and configuration (drush deploy, or drush updb and drush cim).
  2. Run, once:
drush drupal-rag-toolkit:tokenizer-install
drush drupal-rag-toolkit:initialize
  1. Have cron or a scheduled task run drush drupal-rag-toolkit:dispatch-queued every minute, if operators will start builds from the Index lifecycle page.

Deploy configuration before the first build

Active indexes belong to the corpus's UUID. Import the development site's configuration (or install from it) before an environment builds its first index. An environment that built an index for its own separately installed corpus refuses an import that would replace that corpus; uninstall the module there and start again.

A routine deploy

After drush deploy, rebuild only if the pipeline changed:

result=$(drush drupal-rag-toolkit:build --if-changed --workers=12)
run=$(echo "$result" | jq -r '.run_id // empty')
if [ -n "$run" ]; then
  drush drupal-rag-toolkit:reindex-validate "$run" \
    --question="Where can residents get help paying rent?" \
    --term=demo_audience=<term UUID>
  drush drupal-rag-toolkit:reindex-activate "$run"
  drush drupal-rag-toolkit:retire-historical
fi

--if-changed compares the draft and embedding model with the active index and prints {"state": "current"} when nothing changed, so a deploy does not pay for embeddings it already has. Content edits never need a rebuild: saving a node updates the active index.

Validation takes one --term per metadata field, keyed as on the validation form (demo_audience above). Use taxonomy term UUIDs, which are the same on every environment that imported the same terms; IDs usually differ.

retire-historical removes the Search API index, server and vector collection of failed builds and of indexes older than the rollback index, so each environment keeps two: active and rollback. It never touches another environment's indexes.

If validation fails, the new index is not activated and the previous one keeps serving. Activating a different model's index swaps search over without downtime.

Moving evaluation sets

Evaluation sets reference content, so they are content entities rather than configuration. Move a reviewed set with Drush:

drush drupal-rag-toolkit:evaluation-export retrieval_baseline > baseline.jsonl
drush drupal-rag-toolkit:evaluation-import baseline.jsonl   # on the target

The import creates a draft and refuses a set whose nodes do not exist on the target. Activate it before running it.

Copying a database between environments

A copied database still names the environment it came from. Until it is taken over, its RAG search reports unavailable instead of writing to the original environment's collections. With the copy's own scope in settings.php, drush drupal-rag-toolkit:initialize takes it over, so the deploy steps above work unchanged after a database copy: they build, validate and activate this environment's own index. The other environment's indexes are kept in its records and never used or removed here. See the support matrix.