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.
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | Screenshot 2025-09-08 at 21.57.37.png | 499.67 KB | robertoperuzzo |
| #8 | Screenshot 2025-09-08 at 21.58.07.png | 229.07 KB | robertoperuzzo |
Issue fork search_api_typesense-3543841
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
Comment #2
robertoperuzzoComment #3
robertoperuzzoComment #4
robertoperuzzoComment #5
robertoperuzzoComment #7
robertoperuzzoComment #8
robertoperuzzoI implemented an AI Agent that performs RAG (Retrieval-Augmented Generation) on top of Typesense’s semantic search.
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.
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
Flow at a glance
Typesense RAG/Vector Search (search_api_typesense)against that collection.Comment #9
robertoperuzzoComment #10
robertoperuzzoIt 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.
Comment #11
robertoperuzzoComment #12
robertoperuzzoComment #13
robertoperuzzo