Objective
Build an AI-powered knowledge base from PDF documents with semantic search capabilities. This enables building intelligent documentation systems, FAQ bots, and information retrieval applications.
Step 1: Create Knowledge Articles Table
Create a table for knowledge articles.
CREATE TABLE knowledge_articles (
id INTEGER PRIMARY KEY,
source_pdf PDF,
title VARCHAR(255) NOT NULL,
category VARCHAR(50),
subcategory VARCHAR(50),
summary TEXT,
full_content TEXT,
content_embedding VECTOR(384),
keywords VARCHAR(500),
author VARCHAR(100),
version VARCHAR(20) DEFAULT '1.0',
is_published BOOLEAN DEFAULT FALSE,
view_count INTEGER DEFAULT 0,
helpful_count INTEGER DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Step 2: Create Content Chunks Table
Store document chunks for retrieval.
CREATE TABLE knowledge_chunks (
id INTEGER PRIMARY KEY,
article_id INTEGER NOT NULL,
chunk_index INTEGER NOT NULL,
chunk_text TEXT NOT NULL,
chunk_embedding VECTOR(384),
section_title VARCHAR(255),
start_page INTEGER,
token_count INTEGER,
FOREIGN KEY (article_id) REFERENCES knowledge_articles(id)
);
Step 3: Create FAQ Table
Store frequently asked questions.
CREATE TABLE knowledge_faq (
id INTEGER PRIMARY KEY,
article_id INTEGER,
question TEXT NOT NULL,
answer TEXT NOT NULL,
question_embedding VECTOR(384),
category VARCHAR(50),
view_count INTEGER DEFAULT 0,
is_featured BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (article_id) REFERENCES knowledge_articles(id)
);
Step 4: Insert Knowledge Articles
Add sample articles.
INSERT INTO knowledge_articles (id, title, category, subcategory, summary, full_content, keywords, author, is_published) VALUES
(1, 'Getting Started Guide', 'onboarding', 'basics',
'Complete guide for new users to set up their account and learn the basics of the platform.',
'Welcome to our platform. This guide will walk you through the initial setup process. First, create your account by clicking Sign Up. Enter your email and create a strong password. Once verified, you can customize your profile settings. The dashboard provides quick access to all features. Navigation is organized into main sections: Home, Projects, Reports, and Settings.',
'getting started,setup,account,basics,onboarding', 'Documentation Team', TRUE),
(2, 'User Authentication', 'security', 'authentication',
'Learn about authentication methods including password policies, two-factor authentication, and single sign-on options.',
'Security is our top priority. We support multiple authentication methods. Password requirements include minimum 8 characters with uppercase, lowercase, numbers, and special characters. Two-factor authentication adds an extra layer of security using authenticator apps or SMS. Enterprise users can configure SSO with SAML or OAuth providers.',
'authentication,security,password,2FA,SSO,login', 'Security Team', TRUE),
(3, 'API Integration Guide', 'technical', 'api',
'Technical documentation for integrating with our REST API including authentication, endpoints, and examples.',
'Our REST API enables programmatic access to all platform features. Authentication uses API keys or OAuth tokens. Base URL is api.example.com/v1. Common endpoints include /users, /projects, /reports. All responses are JSON formatted. Rate limits apply based on your subscription tier. Webhooks provide real-time event notifications.',
'API,REST,integration,endpoints,authentication,webhooks', 'Engineering Team', TRUE),
(4, 'Billing and Subscriptions', 'account', 'billing',
'Information about subscription plans, payment methods, invoices, and billing management.',
'We offer flexible subscription plans to meet your needs. Plans include Free, Professional, and Enterprise tiers. Payment methods accepted include credit cards, wire transfers, and purchase orders for enterprise. Invoices are generated monthly and available in your account. Upgrades take effect immediately while downgrades apply at next billing cycle.',
'billing,subscription,payment,invoice,pricing,plans', 'Support Team', TRUE),
(5, 'Troubleshooting Common Issues', 'support', 'troubleshooting',
'Solutions to frequently encountered problems and error messages.',
'This guide addresses common issues users encounter. Login problems: Clear browser cache, verify email, reset password if needed. Performance issues: Check internet connection, disable browser extensions, try incognito mode. Error messages: Document specific error codes and contact support with details. Data sync issues: Refresh the page, check for conflicts, force sync from settings.',
'troubleshooting,errors,problems,solutions,support,help', 'Support Team', TRUE);
Step 5: Generate Article Embeddings
Create embeddings for articles.
UPDATE knowledge_articles
SET content_embedding = EMBED(title || ' ' || summary || ' ' || full_content)
WHERE content_embedding IS NULL;