Objective
Create a table with VECTOR type columns for storing embeddings. Vectors are fundamental to AI-native features like semantic search and similarity matching in AIDB.
Step 1: Create a Table with Vector Column
Create a table with a vector column for storing embeddings.
CREATE TABLE product_embeddings (
id INTEGER PRIMARY KEY,
product_name VARCHAR(255) NOT NULL,
description TEXT,
embedding VECTOR(384),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Step 2: Create Tables with Different Vector Dimensions
Different embedding models produce different dimensions.
-- MiniLM embeddings (384 dimensions)
CREATE TABLE minilm_embeddings (
id INTEGER PRIMARY KEY,
content TEXT NOT NULL,
embedding VECTOR(384)
);
-- BERT Base embeddings (768 dimensions)
CREATE TABLE bert_base_embeddings (
id INTEGER PRIMARY KEY,
content TEXT NOT NULL,
embedding VECTOR(768)
);
-- BERT Large embeddings (1024 dimensions)
CREATE TABLE bert_large_embeddings (
id INTEGER PRIMARY KEY,
content TEXT NOT NULL,
embedding VECTOR(1024)
);
-- OpenAI-style embeddings (1536 dimensions)
CREATE TABLE openai_embeddings (
id INTEGER PRIMARY KEY,
content TEXT NOT NULL,
embedding VECTOR(1536)
);
Step 3: Insert Records with Embeddings
Insert sample data and generate embeddings using the EMBED function.
INSERT INTO product_embeddings (id, product_name, description) VALUES
(1, 'Wireless Headphones', 'Premium noise-canceling wireless headphones with 30-hour battery life'),
(2, 'Bluetooth Speaker', 'Portable waterproof speaker with deep bass and 360-degree sound'),
(3, 'USB Microphone', 'Professional condenser microphone for streaming and podcasting'),
(4, 'Webcam HD', 'Full HD webcam with auto-focus and built-in microphone'),
(5, 'Gaming Mouse', 'Ergonomic gaming mouse with customizable RGB lighting');
Step 4: Generate Embeddings
Use the EMBED function to create vector embeddings from text.
UPDATE product_embeddings
SET embedding = EMBED(description)
WHERE embedding IS NULL;
Step 5: Query with Embedding Generation
Select products and generate embeddings inline.
SELECT
id,
product_name,
EMBED(description) as generated_embedding
FROM product_embeddings
LIMIT 3;