Problem/Motivation

We need to integrate Typesense with the AI module's "agent" functionality to enable Retrieval Augmented Generation (RAG) in the chatbot. The existing ai_search module provides a RagTool that can trigger RAG, but it only supports specific vector databases like Milvus, Zilliz, and Pinecone. We need to extend this functionality to work with Typesense, leveraging its vector database capabilities.


Proposed resolution

Historical proposal (kept as history): The proposed resolution was to add a FunctionCall plugin to the existing Typesense module. This plugin would enable an agent to perform queries on Typesense, allowing us to leverage its vector database capabilities for RAG. This approach made sense previously because it kept Typesense-specific logic within its own module and avoided changing the core AI search module.

Updated proposal (use Tool API): Rather than implementing a FunctionCall plugin, implement a Tool plugin for the Typesense module using the Tool API module (https://www.drupal.org/project/tool). The Typesense Tool should expose a concise, well-documented tool contract that agents can call to perform semantic/vector searches and return results in a small, predictable JSON structure suitable for RAG.


Remaining tasks

  • [x] Analyze the ai_search module to understand how FunctionCall plugins are implemented and integrated with agents.
  • [x] Develop the FunctionCall plugin within the Typesense module to handle vector search queries.
  • [x] Ensure the plugin successfully retrieves relevant content from Typesense and provides it to the AI agent for RAG.
  • [x] Replace the FunctionCall plugin with Tool

User interface changes

None. The changes are all backend-related.


API changes

None.


Data model changes

None. The changes only affect how data is retrieved, not how it is stored.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

robertoperuzzo created an issue. See original summary.

robertoperuzzo’s picture

Issue summary: View changes
robertoperuzzo’s picture

Issue summary: View changes
robertoperuzzo’s picture

Issue summary: View changes
robertoperuzzo’s picture

Assigned: Unassigned » robertoperuzzo

robertoperuzzo’s picture

Assigned: robertoperuzzo » Unassigned
Status: Active » Needs review
robertoperuzzo’s picture

I implemented an AI Agent that performs RAG (Retrieval-Augmented Generation) on top of Typesense’s semantic search.

rag agent

When a user enters a query (as a prompt), the main agent doesn’t just run it directly. Instead, it first calls a sub-agent whose job is to determine which Typesense collection is most relevant to the query.

sub-agent

Once the sub-agent identifies the best collection, the main agent uses that collection to perform a semantic search in Typesense (following Typesense’s semantic search workflow). The retrieved context is then fed back into the AI to generate an enriched, context-aware answer—completing the RAG cycle.

Why the sub-agent matters

  • Dynamic routing: It automatically selects the right collection based on intent.
  • Scalability: No hardcoded mapping; adding new collections doesn’t require code changes.
  • Accuracy: Queries hit the most relevant data, improving retrieval quality and answers.

Flow at a glance

  • User enters a prompt.
  • Main agent calls the sub-agent to pick the most relevant Typesense collection.
  • Main agent runs Typesense Typesense RAG/Vector Search (search_api_typesense) against that collection.
robertoperuzzo’s picture

Assigned: Unassigned » robertoperuzzo
Status: Needs review » Needs work
robertoperuzzo’s picture

It appears that the AI Initiative's actual direction is to utilise the Tool API module instead of the current FunctionCall. So I'm going to refactor the existing two FunctionCall in Tool.

robertoperuzzo’s picture

Assigned: robertoperuzzo » Unassigned
Status: Needs work » Needs review
robertoperuzzo’s picture

Title: Implement Typesense support for RAG in the AI module » Implement RAG Tools for AI Agents
Assigned: Unassigned » robertoperuzzo
Status: Needs review » Needs work
robertoperuzzo’s picture

Issue summary: View changes