The goal is to develop a web search feature for the BrainDriveBasicAIChat plugin, enabling real-time web search capabilities using a SearXNG instance. This feature will enhance the chat’s ability to fetch and process relevant web content, improving response accuracy and context awareness within the existing AI/Braindrive chat system.
2. Objectives
Enable seamless integration of web search into the BrainDriveBasicAIChat plugin.
Use SearXNG for privacy-focused and robust search results.
Ensure low latency and efficient scraping to avoid rate-limiting issues.
Add web search toggle box to AI Chat V2 Component.
Optionally allow the AI to decide when to trigger a search based on query context.
3. Functional Requirements
3.1 Search Engine Integration
SearXNG:
Host a local SearXNG instance via Docker for privacy and control.
Configure to return JSON results for API compatibility.
Optimize settings to avoid port conflicts (default: 8080).
Support 5-10 results per query with title, link, and snippet.
3.2 User & AI Search Trigger
Enable the user to toggle the web search on or off.
Enable the AI to determine when a search is needed (e.g., for factual or recent data queries).
Support multi-turn tool use for iterative searches if initial results are insufficient.
3.3 Data Processing
Parse search results (title, URL, snippet) and feed them into the AI’s context.
Clean HTML tags and irrelevant content from scraped pages.
3.4 User Interface
Display search results within the chat UI, with clickable links and source attribution.
Optionally provide a collapsible “thinking” section to show search duration and logic.
4. Non-Functional Requirements
Performance: Search latency < 10 seconds for 5-10 results.
Scalability: Handle up to 100 concurrent searches without crashing.
Security: Use secure API keys or bearer tokens for SearXNG API access.
Privacy: Prioritize SearXNG to minimize tracking.
Compatibility: Support Python 3.8+ and Docker for deployment; integrate with existing BrainDriveBasicAIChat TypeScript/React setup.
5. Technical Architecture
5.1 Components
Backend:
A Python-based FastAPI service to handle search requests, integrated as a new endpoint within the BrainDrive backend.
A TypeScript-based service module in the BrainDriveBasicAIChat plugin to facilitate API calls to the FastAPI backend.
Search Module:
A service to interface with SearXNG for result retrieval, implemented within the BrainDrive backend.
Configurable result counts and query parameters, managed via the existing configuration system or a new configuration module.
AI Integration:
Extend the AI message processing logic in the BrainDriveBasicAIChat plugin to trigger searches contextually.
Modify the backend AI provider logic to incorporate search results into the AI’s context, leveraging existing conversation and message models.
Update chat components to handle search triggers and display results.
Frontend:
Add a web search toggle box to the chat interface, styled with existing Tailwind CSS.
Render search results in the chat history component or a new dedicated component.
Reuse existing dropdown components for the toggle UI or create a lightweight alternative.
Utilize existing portal utilities for rendering search results in the chat UI.
5.2 Data Flow
The user submits a query through the chat interface in the BrainDriveBasicAIChat plugin.
The query is sent to the backend, where the system checks the web search toggle state stored in the configuration or user settings.
If web search is enabled, the backend search service sends a request to the local SearXNG instance and retrieves results.
Search results are parsed, cleaned, and passed to the local AI model running in the backend to augment its context.
The AI model processes the query with search results, generates a response, and returns it to the frontend for display with attributed links in the chat UI.
6. Development Phases
Phase 1: Setup and Prototyping (~0.5-1 week)
Set up SearXNG Docker instance and configure JSON output.
Build a FastAPI endpoint, integrated with BrainDriveBasicAIChat backend.
Test SearXNG integration with sample queries using the TypeScript service module.
Phase 2: AI Integration (~0.5-1 week)
Develop logic in the AI service for contextual search triggering.
Hook search results into the AI response pipeline via the backend AI provider.
Implement result parsing and cleaning in the backend search service.
Phase 3: UI and Optimization (~0.5-1 week)
Add toggle box to the chat interface using Tailwind CSS.
Include search results with links and attribution in the chat UI.
Optimize search latency and handle rate-limiting gracefully.
Test multi-turn search scenarios.
Phase 4: Testing and Deployment (~0.5-1 week)
Conduct unit and integration tests for search reliability, leveraging existing test setups.
Commit and push updated BrainDriveBasicAIChat plugin to GitHub.
Document setup and configuration steps.
7. Deliverables
Web search feature source code (Python FastAPI, TypeScript/React) within BrainDriveBasicAIChat plugin.
Docker configuration for SearXNG and plugin deployment.
Documentation for setup, configuration, and usage.
Matt, Dave J. and I went through this document on a call today recording for which is below.
Excited to get search added to BrainDrive!
Questions, comments, ideas welcome as always. Just hit the reply button.
Thanks,
Dave W.
Video Recording:
AI Powered Summary:
Technology and Implementation
The team decided to use SearXNG instead of DuckDuckGo, citing privacy benefits and the API limitations of other services. The plan is to add a “web search” toggle box to the user interface. When enabled, the system will query a local SearXNG instance and pass the search results to the AI model to generate a sourced response. This feature will be built into the more advanced, unified chat plugin that already includes features like personas.
Development Strategy and Timeline
The group agreed on an MVP-first approach to get a working version out quickly for feedback, even if it’s “janky” at first. The fastest path, suggested by David Jones, is to have the front-end query SearXNG directly. With this focus, Matt believes he can have something to demo within a week or a week and a half and expects to show progress by the next meeting. David Jones also directed Matt to the correct repository to ensure the work is done on the right component.
The BrainDriveChat plugin’s web search feature integrates SearXNG with web scraping capabilities to provide real-time information to AI conversations. Here’s the complete event/data pipeline:
1. SearXNG
First things first, I installed SearXNG by pulling the latest docker container - documentation on that here.
docker pull docker.io/searxng/searxng:latest
Then, I updated the settings.yml to enable JSON responses and GET HTTP queries.
settings.yml lines 77-79:
formats:
- html
- json
line 105 updated to:
method: "GET"
Start the container:
# Start
docker container start searxng
Confirm the container is running by checking the process status:
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d9629e724821 searxng/searxng:latest "/usr/local/searxng/…" X hours ago Up X hours 0.0.0.0:8888->8080/tcp, [::]:8888->8080/tcp searxng
Single Combined Request: Frontend creates one comprehensive prompt that includes:
Original user question
[WEB SEARCH CONTEXT] section with both search results AND scraped content
Direct AI Call: This combined prompt goes directly to /api/v1/ai/providers/chat
5. Response Flow
AI model processes the enriched prompt with web context
Backend streams response back to frontend
Frontend displays AI response in chat
6. User Experience
From the logs:
Message 1 (Search Results Summary):
Found 46 web search results for "What is the weather today?":
[5 top results with URLs and summaries]
Additionally scraped detailed content from 2 web page(s) for deeper analysis.
Analyzing this information to provide a comprehensive answer...
Message 2 (AI Response):
The weather in Portland is currently cloudy with a high near 76°F and low around 55°F.
There's a slight chance of rain shower later today. Winds are from the northwest at 5 to 10 mph.
Humidity is at 60%.
Just a heads up here that we have switched Matt over to working on polishing the AI chat plugin for the last and this coming week but we’ll be back to search functionality shortly.