Skip to main content
Image
Drupal AI Ecosystem Part 4 Drupal AI Search With PostgreSQL OpenSense Labs

Drupal AI Ecosystem Part 4: Drupal AI Search with PostgreSQL Vector Database

Drupal

Search is one of the most important ways people find information online. Whether it’s looking for a product, a tutorial, or an answer to a question, users expect search to "just understand” what they mean. Traditional search engines, however, often rely on matching exact keywords. If you search for “create a chatbot”, but an article is titled “building conversational assistants”, you might never see it, even though it’s exactly what you need. That’s where Drupal AI Search changes the game.

Instead of focusing on keywords, Drupal AI Search focuses on meaning. Utilizing artificial intelligence and vector databases, Drupal AI Search recognizes the relationships between words and concepts. Drupal AI Search can connect a user’s question with the most relevant information, even if the wording is completely different.

In this article, we’ll explore how to build an AI-powered search for your Drupal website using PostgreSQL’s Vector Database. You’ll see how it works, how to set it up, and how it can transform your search experience, making it faster, smarter, and more human-like.

Before implementing Drupal AI Search, see how our team can guide you in building AI-powered, vector-based search experiences that elevate content discovery and engagement.

Upgrade Your Site Experience

Now, let's understand Drupal AI Search and more!

Drupal AI Search: Your Adaptive Discovery Engine

Imagine if your website’s search bar could understand what people mean, not just what they type. That’s the idea behind Drupal AI Search.

Traditional search engines look for exact keyword matches. If you type “how to cook pasta”, they’ll only show pages that contain those same words. But what if the best article says “tips for making Italian noodles”? You might miss it completely.

Drupal AI Search works differently. It uses artificial intelligence to understand the meaning behind words. It turns both the content on your site and the user’s query into special numeric representations called embeddings. These embeddings capture the relationships between words, ideas, and context, almost like how our brains connect similar concepts.

For example: “How to cook pasta” and “Boiling spaghetti the right way” - even though the wording is different, Drupal AI Search knows they mean nearly the same thing. So, it can show both results when someone searches.

Why Use PostgreSQL Vector Database?

There are several specialized databases built for Drupal AI search, like Pinecone, Milvus, or Weaviate. These tools are powerful and purpose-built for vector search, but they often require setting up a separate service, managing new infrastructure, and handling extra costs.

With PostgreSQL’s pgvector extension, you can get the same vector search capabilities without adding another database system. It allows you to store and search embeddings directly in your existing PostgreSQL database, the same one already powering your Drupal site.

This approach has a few big advantages:

  1. No extra infrastructure is required: You use the database you already have.
  2. Cost-effective: No need to pay for or maintain a third-party vector service like Pinecone.
  3. Secure and simple: Your data stays in your own environment, reducing complexity and integration risk.
  4. Performance-ready: PostgreSQL with pgvector; can handle semantic search efficiently for many Drupal use cases.

In short, by using PostgreSQL’s vector database, you can bring AI-powered semantic search into Drupal quickly and affordably, leveraging the infrastructure you already trust.

How Drupal AI Search Works

Drupal AI Search works by converting both your website’s content and user queries into a format that computers can understand: numbers. These numbers, called embeddings, represent the meaning of the text instead of just the words.

Here’s what happens step by step:

  1. Content Embedding: When new content is added to your Drupal site, an AI model (like OpenAI or Hugging Face) converts the text into an embedding, a list of numbers that captures its meaning. This embedding is then stored in your PostgreSQL database using the pgvector extension.
  2. Query Embedding: When someone searches, their query is also turned into an embedding.
  3. Similarity Search: PostgreSQL compares the query’s embedding with the stored content embeddings to find the most similar ones. This comparison uses mathematical distance (like cosine similarity) to measure how close the meanings are.
  4. Results Ranking: The closest matches are shown first, giving the user the most relevant results, even if the exact words don’t match.

So when a user searches for “create a chatbot”, Drupal AI Search can also show results like “building conversational assistants”. It understands meaning, not just text.

Drupal AI Search Setup

Drupal Modules

  1. Search API: Core search framework for Drupal that allows you to index and query content.
  2. Key: Securely stores API keys for your AI services.
  3. AI Core: Provides the base architecture for AI integrations in Drupal.
  4. AI Provider: Connects Drupal to external AI models (e.g., OpenAI, Gemini).
  5. Postgres VDB Provider: Enables PostgreSQL Vector Database (pgvector) support for storing and querying embeddings.
  6. AI Chatbot (AI Core): Adds a conversational interface for users to interact with site content.
  7. AI Assistant (AI Core): Integrates intelligent assistants that can understand context and perform actions accordingly.
  8. AI API Explorer (AI Core): Helps test and manage API connections directly within Drupal.
  9. AI Agents: Automates advanced AI-driven tasks and workflows.

Database

  1. PostgreSQL 15+: Your main database for Drupal.
  2. PostgreSQL Vector Extension (pgvector): Adds vector data types and similarity search functions.

Installation

  1. Configure Lando Services
    name: drupal-11
    recipe: drupal11
    config:
      webroot: web
      php: "8.4"
      composer_version: "2-latest"
      xdebug: false
      via: nginx
      
    services:
      appserver:
        build_as_root:
          - apt-get update && apt-get install -y libpq-dev && docker-php-ext-install pgsql
      pg:
        type: postgres:17
        portforward: true
        creds:
          database: database
          user: postgres
          password: NO PASSWORD
        build_as_root:
          - apt-get update && apt-get install -y
    tooling:
      psql:
        service: pg
        cmd: psql -U postgres database
    
  2. Enable the Vector Extension
    1. Log in to your PostgreSQL service: 
    2. Then enable the pgvector extension: 
      CREATE EXTENSION vector;
  3. Verify the Installation
    1. By Command Line
      /dx

      Verify The Installation By Command Line Drupal AI Search OpenSense Labs

    2. pgAdmin 
      Verify The Installation pgAdmin Drupal AI Search OpenSense Labs
  4. Configure Vector DB
    1. Postgres configuration
      1. Run lando info --service pg to get the configuration
        Configure Vector DB Postgres Configuration Drupal AI Search OpenSense Labs
      2. Configure Postgres DB
        Navigate To: admin/config/ai/vdb_providers/postgres
        Settings Description
        HOST Use the internal host provided by Lando (usually database or pg).
        PORT Use the internal port number from Lando (default 5432).
        USERNAME postgres (or the username defined in .lando.yml).
        DATABASE Use the database name defined in .lando.yml (e.g., database).

        Configure Vector DB Configure Postgres DB Drupal AI Search OpenSense Labs
  5. Configure Search API
    1. Navigate to Search API page: admin/config/search/search-api
    2. Add Server
      1. Select backend: Drupal AI Search
      2. Embeddings Engine
      3. Vector Database: Postgres vector DB
      4. Vector Database Configuration
        1. Database Name: database(Can change based on configuration)
        2. Collection: Any valid collection (If the collection doesn’t exist, it creates a new collection)
        3. Similarity Metric: Cosine similarity measures how close two pieces of text are in meaning by calculating the angle between their vector representations; the smaller the angle, the more similar they are.
    3. Add Index
      1. Database source: Content (Can be anything)
      2. Server: Previously created server Assistant 
        Configure Search API Add Index Drupal AI Search OpenSense Labs
        Configure Search API Add Index Drupal AI Search OpenSense Labs1
      3. Add Field: Navigate to the Fields Tab
      4. Click on Add Fields to add a new field
        1. Select: Body or Rendered HTML output: 
          1. Type: Full text
          2. Index option: Main Content
        2. Title: 
          1. Type: String
          2. Index option: Contextual Content 
            Configure Search API Add New Field Drupal AI Search OpenSense Labs
  6. Index the content
    1. Navigate to the view page of the index to index the content. 
      Index The Content Navigate To View Page Drupal AI Search OpenSense Labs
    2. Verify collection in Postgres.
      Index The Content Verify Collection In Postgress Drupal AI Search OpenSense Labs
  7. Test Vector Database
    1. Navigate to admin/config/ai/explorers/vector_db_generator
    2. Add Prompt and run db query. 
      Test Vector Database Add Prompt Drupal AI Search OpenSense Labs
    3. Response: 
      Test Vector Database Response Drupal AI Search OpenSense Labs

AI Assistant: Your Conversational Search Companion

An AI Assistant is an intelligent, conversational interface that allows users to interact with your website naturally, just like talking to a smart helper. Instead of relying on keyword matches, it understands context, retrieves relevant information, and delivers human-like responses based on your site’s content.

Think of it as a bridge between your content and your users, one that understands intent and meaning, not just words.

  1. Understand context: It doesn't just match keywords but comprehends what users are actually asking for
  2. Retrieve relevant information: Using RAG (Retrieval-Augmented Generation), it searches through your indexed content to find the most relevant answers
  3. Provide conversational responses: It responds in natural language, making information more accessible and user-friendly
  4. Learn from your content: The assistant uses your website's actual content as its knowledge base, ensuring accurate and up-to-date responses

Key Components Of An AI Assistant

RAG (Retrieval-Augmented Generation): RAG is the backbone of intelligent search. Instead of relying solely on pre-trained knowledge, RAG allows the AI to:

  1. Search your vector database for relevant content
  2. Use that content as context to generate accurate, site-specific answers
  3. Provide responses grounded in your actual documentation

Configuration Parameters:

  1. RAG Threshold: Controls how closely results must match the query.
    1.     Lower = broader results
    2.     Higher = stricter, more relevant matches
  2. Max Results: Limits how many search results the assistant considers when formulating an answer
  3. AI Provider: The underlying language model (OpenAI, Gemini, etc.) that powers the conversational interface
  4. Prompt Instructions: You can guide the assistant’s tone or purpose, such as “Answer in short, clear sentences” or “Be detailed and include examples.”

Setup Steps

  1. Navigate to AI Assistant Page: admin/config/ai/ai-assistant;
    Setup Steps Navigate To AI Assistant Page Drupal AI Search OpenSense Labs
  2. Click on Add AI assitant.
    1. Add Basic Configuration:
      1. Label
      2. Description
      3. Instruction
    2. Configure Rag
      1. Enable Rag
      2. Select RAD Database
      3. Rag threshold
      4. Max Results
    3. Select AI Provider
      Setup Steps Select AI Provider Drupal AI Search OpenSense Labs
      Setup Steps Select AI Provider Drupal AI Search OpenSense Labs1

AI Agent: Your Intelligent Action Taker

While an assistant focuses on answering user questions, an AI Agent can plan, reason, and execute complex multi-step tasks using Drupal’s AI ecosystem, all powered by the AI Core, AI Provider, and Postgres Vector Database (VDB) modules.

Think of an agent as an intelligent Drupal worker that can analyze content, retrieve information, and perform actions automatically, not just respond to queries.

An AI Agent can:

  1. Make decisions autonomously: Break down complex user requests (like “summarize all recent AI blog posts”) into smaller tasks and execute them step-by-step.
  2. Use multiple tools: Integrate with the **RAG/Vector Search Tool**, APIs, and other AI modules to accomplish its goals.
  3. Handle multi-step workflows: Perform sequences such as retrieving related nodes, summarizing data, and formatting the output.
  4. Adapt dynamically: Adjust its approach based on context, user input, or intermediate results.

AI Agent vs AI Assistant: Key Differences

Features AI Assistant AI Agent
Autonomy Responds to user search queries and provides contextual answers from the vector database Can plan, reason, and execute multi-step actions using Drupal AI Search results automatically
Complexity Handles simple Q&A Manages complex workflows and decision-making
Tool Usage Primarily uses the RAG/Vector Search Tool to retrieve and display relevant results Can use multiple tools and orchestrate them
Behavior Reactive (waits for user input) Proactive (can initiate actions based on goals)
Use Cases Semantic search responses, knowledge-base Q&A, FAQ-style interactions Automated content summarization, insight extraction, workflow orchestration, or generating reports from Drupal AI Search results

Swarm Orchestration

Swarm orchestration enables multiple AI agents to collaborate, coordinating their efforts to solve increasingly complex problems. This is useful when:

  1. Different agents have specialized knowledge or tools
  2. Tasks require collaboration between multiple AI systems
  3. You need to distribute the workload across different AI capabilities

Agent Instructions Structure

When configuring an agent, divide instructions into three clear sections:

  1. Role: Define what the agent is and its primary purpose. Example: "You are a technical documentation assistant specialized in Drupal development."
  2. Behavior: Specify how the agent should act, communicate, and make decisions. Example: "Always provide code examples when explaining concepts. Be concise but thorough. If information is incomplete, say so rather than guessing."
  3. RAG Behavior: Define how the agent should use the vector search tool and retrieve content. Example: "When searching for information, use the RAG tool first. If results are insufficient, acknowledge the limitation. Always cite sources from the knowledge base when providing answers."

RAG/Vector Search Tool

The RAG/Vector Search Tool allows agents to:

  1. Query the vector database for relevant content
  2. Retrieve semantically similar information based on context
  3. Ground their responses in actual site content rather than general knowledge
  4. Provide more accurate, domain-specific answers

Configuration Steps

  1. Navigate to the AI Agent page: admin/config/ai/agents
  2. Configure Agent:
    1. Add Label and Description
    2. Enable "Swarm orchestration agent" (if you need multi-agent coordination)
    3. Provide detailed instructions divided into three sections:
      1. Role: Define the agent's identity and purpose
      2. Behavior: Specify how it should act and communicate
      3. RAG Behavior: Explain how to use vector search and handle retrieved content
    4. Add the Tool "RAG/Vector Search Tool" to enable semantic search capabilities

AI Agent Configuration Steps Add Tool Drupal AI Search OpenSense Labs

AI Agent Configuration Steps Add Tool Drupal AI Search OpenSense Labs1

AI Agent Configuration Steps Add Tool Drupal AI Search OpenSense Labs2

Testing Your Agent

Test RAG AI agent by navigating to: admin/config/ai/explorers/tools_explorer;

AI Agent Testing Your Agent Drupal AI Search OpenSense Labs

Use the tools explorer to verify that your agent:

  1. Correctly interprets user queries
  2. Retrieves relevant content from the vector database
  3. Provides accurate and contextual responses
  4. Uses the RAG tool appropriately

Deep Chat

  1. Add Deep Chat block.
    1. Select an AI assistant.
      Add Deep Chat  Block Drupal AI Search OpenSense Labs
  2. Test Deep Chat With RAG
    Test Deep Chat With RAG Drupal AI Search OpenSense Labs1
  3.  Test Deep Chat With RAG Drupal AI Search OpenSense Labs
    Boost Traditional Search With AI
    1. Navigate to index preprocess page: admin/config/search/search-api/index/{index}/processors
    2. Enable Boost Database by Drupal AI Search

Boost Traditional Search With AI Drupal AI Search OpenSense Labs

Boost Traditional Search With AI Drupal AI Search OpenSense Labs2

Also Check Out

  1. Drupal AI Ecosystem Part 1: Setup and AI CKEditor Configuration
  2. Drupal AI Ecosystem Part 2: AI Logging, Observability, & API Explorer
  3. Drupal AI Ecosystem Part 3: Drupal AI Translate Module
  4. Transform Your Website with Drupal AI Module in 2025

Key Takeaways

  1. Drupal AI Search moves from keyword-focused search to understanding meaning, utilizing AI embeddings and vector databases.
  2. Using PostgreSQL with pgvector makes AI search affordable and simple to implement, enabling teams to utilize their current Drupal database for semantic search.
  3. Drupal AI Search utilizes embeddings, similarity search, and result ranking to provide highly relevant and context-aware search experiences.
  4. Drupal's AI ecosystem extends beyond search; it includes AI Assistants for conversational, RAG-powered Q&A and AI Agents for independent, multi-step task execution.
  5. A complete setup guide helps developers implement semantic search, covering everything from configuring pgvector to deploying AI Assistants, Agents, and Deep Chat.

Subscribe

Ready to start your digital transformation journey with us?

Related Blogs

Drupal AI Ecosystem Part 3: Drupal AI Translate Module

Drupal AI Ecosystem Part 3 Drupal AI Translate OpenSense Labs

In today’s fast-paced digital landscape, delivering content that resonates across languages is no longer optional; it’s…

Drupal AI Ecosystem Part 2: AI Logging, Observability, & API Explorer

Drupal AI Ecosystem Part 2 OpenSense Labs

In the first part of our series, we explored the foundational architecture, setting up the Drupal AI Ecosystem and AI…

DrupalCon Vienna Key Takeaways: Transforming Drupal with AI

DrupalCon Vienna Key Takeaways OpenSense Labs

Dries delivered his 43rd keynote at DrupalCon Vienna! “AI is the storm… but instead of turning away, we need to embrace AI…