Skip to content

How indexing and serving work

The toolkit splits the work in two. Indexing turns your content into vectors as fast as it can, without deciding who may see what. Serving checks every result against current Drupal content and access before showing it. This page explains both halves and the words the screens use.

Words used on the screens

Term Meaning
Corpus The saved definition of what to index: content types and fields. A fresh install has one, default.
Draft An edited corpus definition that has not been built yet.
RAG index One build of a corpus, with its own Search API index, server, AI Search configuration and Qdrant collection.
Candidate index A RAG index being built or validated. It serves no queries.
Active index The RAG index that answers queries for the corpus.
Profile How questions are answered: purpose, reranking, generation and limits. Profiles use their corpus's active index.
Ledger The durable record, per source, of what was planned, embedded and written.
Worker One parallel lane of a build.
Slice Up to eight chunks of one source, sent in one embedding request and one vector write.

The lifecycle

Draft → Build → Validate → Activate → Retire.

  1. Draft. Corpus Builder saves what to index.
  2. Build. A candidate index gets its own resources. Workers split the selected nodes and index them in parallel.
  3. Validate. A question runs against the candidate to check that it returns your content.
  4. Activate. The candidate becomes the active index. The previous index stops serving but keeps its resources.
  5. Retire. An index you no longer need is retired, then Remove resources deletes its collection and configuration.

Rollback is activating the previous index again, while its ledger still verifies.

Building

When a build starts, the toolkit reads each selected node once, turns it into text, splits it into chunks sized for the embedding model, and records the plan in the ledger. Workers then send each source's chunks to the embedding provider in slices and write the vectors to Qdrant. Each write is recorded in the ledger, so a chunk is never embedded twice.

Indexing does not check whether a node is published or who may see it. Every selected default revision is indexed, including unpublished and restricted content. This keeps builds fast and simple, and access is checked when results are served, where it has to be checked anyway.

If an embedding request gets no answer, that one source is parked and the worker moves on. Parked sources are retried once automatically. Three parks in a row on one worker pause the build, which usually means a problem such as an invalid key or exhausted credits.

Nodes saved during a build are recorded and corrected when the build settles, before it is marked built.

Keeping the active index current

When a node is saved, the toolkit maintains the active index: it re-indexes only that node and updates its ledger entry. Unpublishing a node does not remove it from the index; serving stops showing it.

Serving a question

For each question:

  1. Embed the question. Embeddings are cached for an hour, so a repeated question costs nothing.
  2. Retrieve the nearest chunks from the active index's collection.
  3. Check each result. The toolkit confirms the source's ledger entry is complete, that the indexed version matches the current node, and that the requesting account may view the node and its fields, and every paragraph that contributed text. A stale or inaccessible result is dropped, never shown. The view check calls Drupal's entity access, so hook_entity_access() rules your site adds, such as hiding content of an unpublished section, apply to every result, citation and answer. This is part of the public contract. Results are checked after retrieval, so a page can show fewer results than the retrieval limit when many are hidden from the visitor.
  4. Rerank, if enabled. A chat model scores each passage from 0 to 10 for how directly it answers the question, within the profile's purpose. Passages below the minimum score are dropped.
  5. Answer. The query returns one of four outcomes:
  6. grounded: a generated answer with citations;
  7. evidence: cited sources without a generated answer;
  8. no grounded answer: nothing eligible answers the question;
  9. unavailable: a dependency, such as the provider, failed.

The toolkit never generates an answer without evidence. A generated answer is written only from the passages that passed these checks, and each source is cited once.

The knowledge search page

The optional sample page, added by the knowledge-search recipe, is at /knowledge-search. It shows the recommended sources for a question, then other search results without repeating them. It asks whether the visitor wants a generated summary. The summary streams in as it is written and is then replaced by the checked version with citations. Profiles with a guardrail set do not stream, so every word is checked before it is shown.

Sharing the site with other search indexes

The toolkit changes no Search API index or server it does not own.

  • Toolkit indexes carry a marker. Every Search API index the toolkit owns, candidates included, has an enforced module dependency on drupal_rag_toolkit_search_api. A module can skip RAG indexes by checking for it:
in_array('drupal_rag_toolkit_search_api', $index->getDependencies()['enforced']['module'] ?? [], TRUE)
  • Other modules' locked processors. Search API adds every locked processor to every index, and some modules, Search API Solr among them, do not limit theirs to their own indexes. A RAG index accepts such a processor when it changes no query and adds no field the index uses; it takes no part in the index's identity. A processor that changes queries, such as a site's access processor, stops preflight with its name. Have that processor return FALSE from supportsIndex() for indexes with the marker, and check the marker again before it alters a query, because Search API runs locked processors on loaded indexes even where supportsIndex() says no.
  • Query alter hooks. RAG retrieval is a Search API query, so other modules' hook_search_api_query_alter() implementations run on it. Its queries carry the tag drupal_rag_toolkit; skip them with $query->hasTag('drupal_rag_toolkit'). A condition added to a RAG query makes it unavailable rather than changing its results.
  • The toolkit's own processor attaches only to indexes whose server uses the toolkit's chunking strategy, so it is not saved into other indexes.
  • Plugin IDs, not classes. The toolkit recognizes processors by plugin ID, so a site may swap a processor's class, for example to change what rendered_item renders.

Privacy

  • Builds send every selected item to the embedding provider, and the vector database stores it. That includes unpublished content and content your site hides from visitors; access is checked when results are served.
  • Questions go to the embedding provider, and with reranking or generation, to the chat provider along with the retrieved passages.
  • Generated answers are not stored. Query embeddings and rerank scores are cached for an hour.