ai_related_content
This module leverages the AI Search sub-module of the AI module to find related content. This is sometimes referred to as content recommendations or suggested content.
Features
This module provides a Views Block that allows the site builder to configure the content used to do the automated search in the AI Search (Vector database) and suggest related content.
The View itself is editable to control things like:
- How many related content items to show
- What View Mode to show related content in
- How should the related content be cached*
* This should not be underestimated, leveraging LLMs to do a vector search has a cost, caching the related content is important to avoid Denial of Wallet (DOW) attacks.
Post-Installation
Setting up your Vector Database
- Get set up
Configure the AI Search sub-module with a Search API Vector Database. Read the docs on that here.
- Prevent the current item from being a result
Ensure you have an 'nid' field set in the Search API Vector Database of choice as a Filterable Attribute - this is needed to exclude the current ID. The AI Related Content View edit screen will show a warning if you are missing this.
- Efficiently retrieve relevant results
Ideally use a Vector Database that supports grouping (e.g. Postgres, MariaDb, Milvus). If not, if multiple chunks are returned from the same content item, the AI Search module will run more queries on the Vector Database to retrieve the desired number of results (if available). This is still fast, so is optional.
- Ensure relevance
Enable the score threshold processor plugin in the Search API index and decide on a minimum relevance.
Setting up the AI Related Content View
- Automatically set it up using the helper form
Go to /admin/config/ai/ai-related-content-setup to install the AI Related Content View with your Search API Vector Database of choice. This creates a new View at Admin > Structure > Views > AI Related Content for you (or updates the existing View if you have it already).
- Prevent on-demand token usage (optional)
Ensure you choose the index to find existing Vectors from for the item being viewed, and do not enable on-demand generating of Vectors if you do not want to incur token usage via e.g. OpenAI. If you do want on-demand usage (e.g. for content not in an index) see the caching advice below.
- Decide how to visually display
Optionally modify your desired View Mode (defaults to Teaser)
- Ensure good caching
Optionally modify your caching (defaults to time based). Ensure you are not stopping the AI Search's built--in caching for vectors (available from AI Search 2.0+ only).
- Add to your content item
Configure the AI Related Content block to use a non-default View Mode to curate the portion of the contents used to search for related content, or use Twig Tweak using the snippets shown in the setup form.
Once configured you can edit your View, editing the AI Related Content Node Filter to change settings as desired. You can test your related content by entering a source Node ID to show related content for in the View Preview arguments. E.g. to show related content for Node 3, enter "3" in the arguments.
* Important: If you choose a View Mode that also renders the related content, you can hit an infinite loop!
Similar projects
AI Based Recommendations uses OpenAI module instead AI so is locked in to that. It also does not leverage Views and so does not provide the flexibility about how related content is display and how it is cached (see note above on importance of caching).
AI More Like This came later and is roughly a duplicate functionality, but relies on Postgres as the Vector Database, doesn't support adding related content to content not in your index, and doesn't leverage Search API so missing things like Content Access and other handy Search API plugins, so make sure you then duplicate any such functionality into your View.