Skip to content

Searching chats

Where Search API is installed, Site Agent makes threads searchable through it: their titles, transcripts and tool results. With Database Search, Search API Instant or AI Search installed too, it adds what each of them needs. Without Search API it adds nothing, and nothing else is needed.

What is indexed

Threads are indexed with Search API's entity datasource, "Site Agent thread" (entity:site_agent_thread). Its fields are the thread's own: title, owner, origin, status, created and changed. The "Site Agent chat text" processor adds two properties to it:

Property Holds
Transcript (site_agent_transcript) The messages as the chat shows them, one value each: the user's, with the names of attached files in place of the notes the model reads, and the assistant's text.
Tool results (site_agent_tool_results) The thread's tool calls, oldest first, one value each: the tool, its arguments as JSON, and its result summary. A code call, such as PHP, keeps its whole result.

A remote client's thread has no transcript, so only its title and tool results are found. Tool calls may be indexed on their own too, with the "Site Agent tool call" datasource.

A thread's canonical link is its chat page, /admin/site-agent/THREAD, so Search API's result links, Views and Search API Instant lead there.

Who finds what

The "Site Agent thread access" processor is locked on: every index with threads or tool calls has it. It indexes the owner of each item's thread in the field "Site Agent thread owner" (site_agent_thread_owner), and adds a condition to each query, as Search API's content access processor adds node access:

  • An account with "View any Site Agent thread" finds every thread.
  • Any other signed-in account finds its own threads.
  • An anonymous visitor finds none.
  • A tool call follows its thread. Once the thread is deleted, only "View any Site Agent thread" finds it.
  • Items of other datasources in the same index are left alone.

The condition is in the query, so the backend applies it: results are never only filtered afterwards. Like content access, the processor searches as the query's search_api_access_account option, or the current user, and does nothing when search_api_bypass_access is set. A query's cache contexts vary by the account.

Keeping the index current

Search API tracks threads as entities. A thread's item is queued again when:

  • the thread is saved, which each turn does;
  • one of its tool calls is saved or deleted;
  • its transcript is deleted, by Transcript retention or through the ChatMemory plugin: the thread is saved, closed, keeping its changed time.

Deleting a thread deletes its item. With "Index items immediately", the shipped index's default, items are indexed at the end of the request; otherwise by cron.

The shipped index

With Database Search (search_api_db, part of Search API) installed, Site Agent's optional configuration adds a server and an index, both site_agent_chats. The index is on the site's own database, so nothing leaves the site. It holds the title, transcript, tool results, owner, origin, status and dates, with the Highlight processor's excerpts.

  1. Install Database Search: drush en search_api_db. Where it was installed before Site Agent was updated, drush updatedb adds them.
  2. Index the threads that exist: drush search-api:index site_agent_chats. Later changes are indexed as they happen.

To use another server, such as Solr, change the index's server at /admin/config/search/search-api/index/site_agent_chats/edit.

Where an enabled index of threads is on an available server other than AI Search, Site Agent answers GET /site-agent/threads/search?q=WORDS. It returns the ids of the account's own threads whose title, transcript or tool results match, as {"threads": [ID, …]}, for 3 characters or more, and gives the chat its address as drupalSettings.siteAgent.urls.threadSearch. The shipped index is used first, if there are several. Its queries have the search ID site_agent:history.

The chat history's search field uses it: titles match as you type, and once you pause, with 3 characters or more, chats whose transcript or tool results match the words are listed too.

Search API Instant

With Search API Instant installed, Site Agent's optional configuration adds a restricted search, "Site Agent chats" (site_agent_chats), with the keyword engine on the shipped index. Its results link to the thread's chat page, and Search API Instant checks the view access to each one. Answers vary by the user, since the access condition does.

  1. Grant "Use the Site Agent chats instant search" to the roles that read chats. It also needs "View published content".
  2. At Structure » Block layout, in the administration theme, place the block "Search API Instant launcher" with the search "Site Agent chats", for example in the header. The floating launcher stays off administration pages, and the chat is one.

Nothing sends chats to an embeddings provider unless a site builds an AI Search index of threads. Transcripts can hold personal data, the content the tools read and PHP output. An embeddings provider receives every chunk of them, under its own terms. Choose one whose terms suit that data, or one the site runs itself.

The same datasource and processors work on an AI Search server (the AI module's ai_search submodule, with the search_api_ai_search backend and a vector database provider such as Solr VDB Provider):

  1. Add an index on the AI Search server, with the "Site Agent thread" datasource and AI Search's tracker (ai_search_tracker). Enable the "Site Agent chat text" processor. The access processor is on by itself.
  2. Add the fields Transcript, Title and, if wanted, Tool results.
  3. In AI Search's fields form, set Transcript as the main content and Title as contextual content. Contextual content is added to every chunk, so long tool results are better left out. Set "Site Agent thread owner" as a filterable attribute.
  4. Index it, which embeds every thread through the provider.

The access condition becomes a filter of the vector database where its provider supports filters. The Solr VDB provider applies it before the vector search. Without the owner as a filterable attribute, the filter matches nothing, and only accounts with "View any Site Agent thread" find threads. AI Search also checks the view access to each result. A Search API Instant semantic search can search the index, with the keyword index site_agent_chats for literal matches and the keyword search as its fallback.