Vector INSERT Examples - Quick Reference
Vector INSERT Examples - Quick Reference
All Working Syntax Forms
1. Explicit CAST (Your Original Query)
INSERT INTO docs VALUES (1, 'AI', '[0.9, 0.1, 0.0]'::VECTOR(3));Status: WORKS NOW
2. Auto-Detection (Recommended - Simpler)
INSERT INTO docs VALUES (1, 'AI', '[0.8, 0.2, 0.0]');Status: WORKS - Automatically detects VECTOR column
3. With Explicit Column Names
INSERT INTO docs (id, content, embedding)VALUES (1, 'AI', '[0.9, 0.1, 0.0]'::VECTOR(3));Status: WORKS
4. Partial Column List
INSERT INTO docs (id, embedding)VALUES (1, '[0.9, 0.1, 0.0]');Status: WORKS - Auto-detects vector
5. Multiple Rows
INSERT INTO docs VALUES (1, 'AI', '[0.9, 0.1, 0.0]'), (2, 'ML', '[0.8, 0.2, 0.0]'), (3, 'DL', '[0.7, 0.3, 0.0]');Status: WORKS - All auto-detected
Vector Literal Formats
All these formats work for vector values:
-- With brackets'[0.9, 0.1, 0.0]'
-- Explicit CAST'[0.9, 0.1, 0.0]'::VECTOR(3)
-- Different precision'[0.9234, 0.1567, 0.0123]'
-- Scientific notation'[9e-1, 1e-1, 0.0]'Full Example Session
-- Create tableCREATE TABLE docs ( id INT, content TEXT, embedding VECTOR(3));
-- Insert using CASTINSERT INTO docs VALUES (1, 'AI', '[0.9, 0.1, 0.0]'::VECTOR(3));
-- Insert using auto-detection (easier!)INSERT INTO docs VALUES (2, 'ML', '[0.8, 0.2, 0.0]');
-- QuerySELECT id, content FROM docs ORDER BY id;
-- Vector similarity searchSELECT id, content, embedding <-> '[1.0, 0.0, 0.0]' AS distanceFROM docsORDER BY distanceLIMIT 5;Testing Your Setup
Run this to verify everything works:
cd /home/claude/HeliosDBcargo test -p heliosdb-lite --test vector_insert_cast_testExpected output:
test test_insert_vector_with_cast ... oktest result: ok. 1 passedNext Steps
- Create table with VECTOR column
- INSERT vectors (with or without CAST)
- Query your data
- Create HNSW index for fast similarity search
- Run vector similarity queries
Happy testing!