AI Chatbot Maker with TiDB Vector Search - Hackathon Plan
Outlines a hackathon plan for building an AI chatbot platform that ingests documentation and GitHub repos, uses TiDB vector search, and generates embeddable script tags.
What this file does
Outlines a hackathon plan for building an AI chatbot platform that ingests documentation and GitHub repos, uses TiDB vector search, and generates embeddable script tags.
When to use it
- Planning a hackathon project that combines vector search with chatbot creation
- Building a SaaS tool that lets users create custom chatbots from their own docs
- Integrating TiDB Vector Search into a Next.js application with Clerk auth
- Designing a system that generates embeddable widgets for third-party websites
Assumes this stack
AI Chatbot Maker with TiDB Vector Search - Hackathon Plan
Based on the hackathon requirements and your existing project, I'll outline a detailed plan for building an AI application that allows users to create chatbots from documentation sites or GitHub repositories using TiDB Vector Search.
Core Features
1. Data Ingestion & Processing
- Website Documentation Ingestion: Users can input a documentation URL to crawl and process
- GitHub Repository Integration: Connect to GitHub repositories to extract documentation and code
- Content Processing Pipeline:
- Extract text content from web pages and markdown files
- Chunk content into manageable pieces for vector embedding
- Store processed content with metadata in TiDB
2. Vector Search Implementation
- Embedding Generation: Use OpenAI or other embedding models to convert text chunks to vectors
- Vector Storage: Store embeddings in TiDB with vector data type
- Similarity Search: Implement cosine similarity search for relevant content retrieval
3. Chatbot Engine
- Conversational Interface: Real-time chat interface for interacting with the AI assistant
- Context Management: Maintain conversation history for contextual responses
- Hybrid Search: Combine vector search with full-text search for better results
4. Script Tag Generator
- Custom Widget: Generate a script tag that users can embed on their websites
- Customization Options: Allow styling and positioning customization
- Domain Restrictions: Configure which domains can use the widget
Technical Architecture
Frontend (Next.js)
- Dashboard for managing chatbots
- Configuration interface for data sources
- Chat interface for testing
- Script tag generator UI
Backend (Next.js API Routes)
- Data ingestion service
- Vector embedding processor
- Search API endpoints
- Chatbot response generator
Database (TiDB Cloud)
- Documents Table: Store original content with metadata
- Vectors Table: Store embeddings with references to documents
- Chat History: Store conversation history
- Chatbots Table: Configuration for each chatbot instance
Implementation Plan
Phase 1: Data Ingestion System
- Create data source connectors:
- Web crawler for documentation sites
- GitHub API integration for repositories
- Implement content processing pipeline:
- Text extraction from HTML/Markdown
- Content chunking algorithm
- Metadata extraction
Phase 2: Vector Search Integration
- Set up embedding service (OpenAI embeddings)
- Create database schema for vector storage
- Implement ingestion pipeline:
- Generate embeddings for content chunks
- Store in TiDB with vector data type
- Build search functionality:
- Vector similarity search
- Hybrid search with full-text
Phase 3: Chatbot Engine
- Implement chat API endpoint
- Create prompt engineering system
- Add conversation memory management
- Integrate with LLM (OpenAI, Claude, etc.)
Phase 4: Script Tag Generator
- Create widget UI component
- Implement script tag generator
- Add customization options
- Create installation instructions
Phase 5: Dashboard & UI
- Chatbot management dashboard
- Data source configuration
- Analytics and usage metrics
- Testing interface
TiDB Cloud Features Integration
Vector Search
- Use TiDB's native
VECTORdata type for storing embeddings - Implement HNSW (Hierarchical Navigable Small World) vector indexes for efficient similarity search
- Use
VEC_COSINE_DISTANCEfunction for calculating similarity between query vectors and stored embeddings - Leverage TiDB's Approximate Nearest Neighbor (ANN) search capabilities for fast retrieval
Example vector search query:
SELECT id, document, VEC_COSINE_DISTANCE(embedding, '[1,2,3]') AS distance
FROM embedded_documents
ORDER BY distance
LIMIT 3;
Full-Text Search
- Combine with vector search for hybrid retrieval using TiDB's full-text search capabilities
- Implement weighted scoring between vector similarity and text relevance
- Use traditional SQL text search functions for keyword matching
Multi-Cluster Placement
- Store frequently accessed data in performance-tier clusters
- Archive older data in cost-effective storage
- Implement data placement policies for disaster recovery and performance optimization
Example placement policy:
CREATE PLACEMENT POLICY primary_rule_for_region1
PRIMARY_REGION="Region1"
REGIONS="Region1,Region2,Region3";
ALTER TABLE chatbots PLACEMENT POLICY=primary_rule_for_region1;
TiDB Vector Indexing
- Create HNSW vector indexes for efficient similarity search:
CREATE TABLE documents (
id INT PRIMARY KEY,
content TEXT,
embedding VECTOR(768), -- For OpenAI embeddings
VECTOR INDEX idx_embedding ((VEC_COSINE_DISTANCE(embedding)))
);
- Use post-filtering techniques to leverage vector indexes with additional filters:
SELECT * FROM (
SELECT * FROM documents
ORDER BY VEC_COSINE_DISTANCE(embedding, '[1, 2, 3]')
LIMIT 10
) t
WHERE category = "documentation";
API Integrations
- OpenAI API: For embeddings and chat completions
- GitHub API: For repository access
- Web Scraping Service: For documentation site processing
- Authentication: Clerk for user management
Database Schema Design
-- Documents table
CREATE TABLE documents (
id BIGINT PRIMARY KEY AUTO_INCREMENT,
chatbot_id BIGINT,
url TEXT,
content TEXT,
content_type ENUM('web_page', 'markdown', 'pdf', 'code'),
metadata JSON,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
-- Vectors table with HNSW index
CREATE TABLE vectors (
id BIGINT PRIMARY KEY AUTO_INCREMENT,
document_id BIGINT,
content TEXT,
embedding VECTOR(768), -- For OpenAI embeddings
metadata JSON,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
VECTOR INDEX idx_embedding ((VEC_COSINE_DISTANCE(embedding))) USING HNSW
);
-- Chatbots table
CREATE TABLE chatbots (
id BIGINT PRIMARY KEY AUTO_INCREMENT,
user_id TEXT,
name VARCHAR(255),
config JSON,
script_config JSON,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
-- Chat history table
CREATE TABLE chat_history (
id BIGINT PRIMARY KEY AUTO_INCREMENT,
chatbot_id BIGINT,
session_id VARCHAR(255),
role ENUM('user', 'assistant'),
content TEXT,
metadata JSON,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Users table (extending existing schema)
CREATE TABLE users (
id TEXT PRIMARY KEY,
name VARCHAR(255),
email VARCHAR(255),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Security Considerations
- Data Privacy: Ensure user data is isolated and protected
- API Key Management: Secure storage of third-party API keys
- Rate Limiting: Prevent abuse of the chatbot service
- Domain Verification: Verify ownership before widget deployment
- Vector Data Encryption: Encrypt sensitive vector data at rest
Performance Optimization
- Caching: Cache frequently accessed embeddings and search results
- Batch Processing: Process documents in batches for efficiency
- Indexing: Proper database indexing for search performance
- CDN: Serve widget assets through CDN
- Connection Pooling: Use connection pooling for database connections
- Vector Index Maintenance: Regularly compact TiFlash delta layers for optimal vector search performance
TiDB-Specific Optimizations
- Vector Index Usage: Ensure queries use
LIMITclause to leverage vector indexes - Proper Filtering: Use post-filtering techniques to maintain vector index usage
- Dimension Consistency: Maintain consistent vector dimensions for all embeddings
- Placement Policies: Use placement policies for data distribution across regions
- Monitoring: Monitor vector index build progress using
INFORMATION_SCHEMA.TIFLASH_INDEXES
This plan leverages your existing Next.js foundation with Clerk authentication and integrates TiDB Vector Search to create a powerful AI chatbot platform that meets all hackathon requirements. The implementation will showcase real-world problem solving by enabling businesses to create custom AI assistants from their existing documentation.
What's inside
5 phases, 4 core features, 6 database tables, 5 SQL examples, 3 API integrations
Change this for your project
- Replace
srthkdev/clawwith your own repository name - Replace
'[1,2,3]'with actual query vectors in SQL examples - Replace
'[1, 2, 3]'with actual query vectors in SQL examples - Replace
Region1with your own TiDB Cloud region names in placement policies
Where it goes
Reference documentation for a retrieval pipeline. Keep with the ingestion or retrieval code it describes.
Worth borrowing
- Post-filtering technique to apply additional filters after vector search without breaking index usage
- Separate documents and vectors tables to decouple raw content from embeddings for easier maintenance
- Placement policies for distributing data across regions based on access patterns
Related Documents
SUMMARY
Proposes three on-prem AI architectures, modular, hybrid, and fully local RAG, with hardware specs and vendor lists.
Retrieval & Prompts
Explains how CharMemory's extraction prompt and Vector Storage settings determine memory retrieval quality in SillyTavern.
Advanced RAG Techniques
Surveys advanced RAG architectures, Agentic, Corrective, Self-RAG, Graph RAG, RAPTOR, Multimodal, Temporal, with design trade-offs and decision guidance.
RFC-BLite: High-Performance Embedded Document Database for .NET
Specifies an embedded document database for.NET with zero-allocation I/O, C-BSON format, and ACID transactions.