SELECT version();
version |
PostgreSQL 15.14 on x86_64-pc-linux-gnu, compiled by gcc (GCC) |
SELECT name, setting, unitFROM pg_settingsWHERE name IN ('shared_buffers', 'effective_cache_size', 'work_mem','maintenance_work_mem', 'max_connections','max_parallel_workers', 'max_parallel_workers_per_gather','wal_level')ORDER BY name;
name | setting | unit |
effective_cache_size | 524288 | 8KB |
maintenance_work_mem | 524288 | KB |
max_connections | 2048 | - |
max_parallel_workers | 8 | - |
max_parallel_workers_per_gather | 2 | - |
shared_buffers | 1572864 | 8KB |
wal_level | logical | - |
work_mem | 4096 | KB |
CREATE EXTENSION IF NOT EXISTS vector;
SELECT extname, extversion FROM pg_extension WHERE extname = 'vector';
extname | extversion |
vector | 0.8.2 |
DROP TABLE IF EXISTS chat_messages CASCADE; -- took 5.7msDROP TABLE IF EXISTS chat_sessions CASCADE; -- took 2.7msDROP TABLE IF EXISTS text_vectors CASCADE; -- took 3.7msDROP TABLE IF EXISTS image_vectors CASCADE; -- took 3.4ms
CREATE TABLE image_vectors (id BIGSERIAL PRIMARY KEY,image_id VARCHAR(64) NOT NULL UNIQUE,image_url TEXT NOT NULL,thumbnail_url TEXT,embedding vector(768) NOT NULL, -- generated by large model, 768-dimensional outputcategory VARCHAR(100),tags TEXT[],source VARCHAR(50) DEFAULT 'upload',metadata JSONB DEFAULT '{}',status SMALLINT DEFAULT 1,created_at TIMESTAMPTZ DEFAULT NOW(),updated_at TIMESTAMPTZ DEFAULT NOW());COMMENT ON TABLE image_vectors IS 'image vector table - intelligent customer service image search';COMMENT ON COLUMN image_vectors.embedding IS '768-dimensional image vector generated by large model';
SELECT column_name, data_type, is_nullable, column_defaultFROM information_schema.columnsWHERE table_name = 'image_vectors'ORDER BY ordinal_position;
column_name | data_type | is_nullable | column_default |
id | bigint | NO | nextval('image_vectors_id_seq'::regclass) |
image_id | character varying | NO | - |
image_url | text | NO | - |
thumbnail_url | text | YES | - |
embedding | USER-DEFINED | NO | - |
category | character varying | YES | - |
tags | ARRAY | YES | - |
source | character varying | YES | 'upload'::character varying |
metadata | jsonb | YES | '{}'::jsonb |
status | smallint | YES | 1 |
created_at | timestamp with time zone | YES | now() |
updated_at | timestamp with time zone | YES | now() |
CREATE TABLE text_vectors (id BIGSERIAL PRIMARY KEY,doc_id VARCHAR(64) NOT NULL UNIQUE,title TEXT,content TEXT NOT NULL,content_type VARCHAR(20) DEFAULT 'faq',embedding vector(1024) NOT NULL, -- 1024-dimensional output generated by large modelcategory VARCHAR(100),tags TEXT[],source VARCHAR(100),metadata JSONB DEFAULT '{}',priority SMALLINT DEFAULT 0,status SMALLINT DEFAULT 1,expire_at TIMESTAMPTZ,created_at TIMESTAMPTZ DEFAULT NOW(),updated_at TIMESTAMPTZ DEFAULT NOW());COMMENT ON TABLE text_vectors IS 'text vector table - intelligent customer service knowledge base search';COMMENT ON COLUMN text_vectors.embedding IS '1024-dimensional text vector generated by large model';
column_name | data_type | is_nullable | column_default |
id | bigint | NO | nextval('text_vectors_id_seq'::regclass) |
doc_id | character varying | NO | - |
title | text | YES | - |
content | text | NO | - |
content_type | character varying | YES | 'faq'::character varying |
embedding | USER-DEFINED | NO | - |
category | character varying | YES | - |
tags | ARRAY | YES | - |
source | character varying | YES | - |
metadata | jsonb | YES | '{}'::jsonb |
priority | smallint | YES | 0 |
status | smallint | YES | 1 |
expire_at | timestamp with time zone | YES | - |
created_at | timestamp with time zone | YES | now() |
updated_at | timestamp with time zone | YES | now() |
CREATE TABLE chat_sessions (id BIGSERIAL PRIMARY KEY,session_id VARCHAR(64) NOT NULL UNIQUE,user_id VARCHAR(64) NOT NULL,channel VARCHAR(20) DEFAULT 'web',status VARCHAR(20) DEFAULT 'active',created_at TIMESTAMPTZ DEFAULT NOW(),closed_at TIMESTAMPTZ);
CREATE TABLE chat_messages (id BIGSERIAL PRIMARY KEY,session_id VARCHAR(64) NOT NULL,role VARCHAR(10) NOT NULL,content_type VARCHAR(20) DEFAULT 'text',content TEXT NOT NULL,image_url TEXT,embedding vector(1024), -- 1024-dimensional vector used for similar question recommendationmatched_doc_ids TEXT[],confidence REAL,feedback SMALLINT,created_at TIMESTAMPTZ DEFAULT NOW());COMMENT ON TABLE chat_messages IS 'chat messages table - containing vector field used for similar question recommendation';
SELECT table_name, pg_size_pretty(pg_total_relation_size(quote_ident(table_name)))FROM information_schema.tablesWHERE table_schema = 'public'AND table_name IN ('image_vectors', 'text_vectors', 'chat_sessions', 'chat_messages')ORDER BY table_name;
table_name | pg_size_pretty |
chat_messages | 16KB |
chat_sessions | 16KB |
image_vectors | 24KB |
text_vectors | 24KB |
# | Index Name | Type | Description | Duration |
1 | idx_image_vectors_category | B-Tree (partial) | Image classification, WHERE status=1 | 2.2ms |
2 | idx_image_vectors_status | B-Tree | Image status | 2.1ms |
3 | idx_text_vectors_category | B-Tree (partial) | Text classification, WHERE status=1 | 2.1ms |
4 | idx_text_vectors_content_type | B-Tree (partial) | Text type, WHERE status=1 | 2.1ms |
5 | idx_text_vectors_priority | B-Tree (partial) | Text priority descending, WHERE status=1 | 2.1ms |
6 | idx_chat_messages_session | B-Tree | message-session composite index | 2.2ms |
7 | idx_chat_sessions_user | B-Tree | session-user index (time descending) | 2.1ms |
8 | idx_image_vectors_tags | GIN (partial) | image tag array, WHERE status=1 | 2.2ms |
9 | idx_text_vectors_tags | GIN (partial) | text tag array, WHERE status=1 | 2.0ms |
10 | idx_image_vectors_metadata | GIN | image JSONB metadata | 2.0ms |
11 | idx_text_vectors_metadata | GIN | text JSONB metadata | 2.0ms |
-- Image classification index (partial index, only records with status=1)CREATE INDEX idx_image_vectors_category ON image_vectors (category) WHERE status = 1;-- Image Tag GIN indexCREATE INDEX idx_image_vectors_tags ON image_vectors USING GIN (tags) WHERE status = 1;-- Image metadata JSONB GIN indexCREATE INDEX idx_image_vectors_metadata ON image_vectors USING GIN (metadata);
SELECT indexname, indexdefFROM pg_indexesWHERE schemaname = 'public'AND tablename IN ('image_vectors', 'text_vectors', 'chat_sessions', 'chat_messages')ORDER BY tablename, indexname;
indexname | Table |
chat_messages_pkey | chat_messages |
idx_chat_messages_session | chat_messages |
chat_sessions_pkey | chat_sessions |
chat_sessions_session_id_key | chat_sessions |
idx_chat_sessions_user | chat_sessions |
idx_image_vectors_category | image_vectors |
idx_image_vectors_metadata | image_vectors |
idx_image_vectors_status | image_vectors |
idx_image_vectors_tags | image_vectors |
image_vectors_image_id_key | image_vectors |
image_vectors_pkey | image_vectors |
idx_text_vectors_category | text_vectors |
idx_text_vectors_content_type | text_vectors |
idx_text_vectors_metadata | text_vectors |
idx_text_vectors_priority | text_vectors |
idx_text_vectors_tags | text_vectors |
text_vectors_doc_id_key | text_vectors |
text_vectors_pkey | text_vectors |
INSERT INTO text_vectors (doc_id, title, content, content_type, embedding, category, tags, priority)VALUES ('faq-001','How to reset password','You can reset your password by following these steps: 1. Click the "forgot password" link on the login page; 2. Input your registered email;3. Check your inbox for the reset email; 4. Click the link in the email to set a new password.','faq',(SELECT array_agg(random())::vector(1024) FROM generate_series(1, 1024)),'account management',ARRAY['account management', 'faq'],2);
doc_id | Title | Category | Priority | Duration |
faq-001 | How to reset password | Account management | 2 | 2.6ms |
faq-002 | How to modify personal information | Account management | 1 | 2.0ms |
faq-003 | Order delivery time | Order Logistics | 2 | 1.9ms |
faq-004 | Return and Refund Process | After-Sales Service | 2 | 1.9ms |
faq-005 | How to use coupons | Promotions | 1 | 1.9ms |
faq-006 | Delivery Area and Shipping Fee | Order Logistics | 1 | 2.1ms |
faq-007 | How to Contact Customer Service | Customer Service Help | 2 | 2.0ms |
faq-008 | Account Security Settings | Account management | 1 | 2.0ms |
faq-009 | Payment Methods Explanation | Payment-Related | 1 | 2.0ms |
faq-010 | Membership Tier Benefits | Membership Services | 1 | 2.0ms |
faq-011 | Product Warranty Policy | After-Sales Service | 1 | 2.1ms |
faq-012 | Invoice Issuance Instructions | Payment-Related | 0 | 2.0ms |
SELECT doc_id, title, category, priority, status,LEFT(content, 40) || '...' AS content_previewFROM text_vectorsORDER BY priority DESC, doc_id;
doc_id | title | category | priority | status | content_preview |
faq-001 | How to reset password | Account management | 2 | 1 | You can reset your password by following these steps: 1. Click the "Forgot Password" link on the login page; 2. ... |
faq-003 | Order delivery time | Order Logistics | 2 | 1 | Regular orders will be shipped within 48 hours after payment, while expedited orders will be shipped within 24 hours. Shipping times during holidays may be extended... |
faq-004 | Return and Refund Process | After-Sales Service | 2 | 1 | Return request process: 1. Go to "My Orders" to find the corresponding order; 2. Click "Request Return"; 3. ... |
faq-007 | How to Contact Customer Service | Customer Service Help | 2 | 1 | You can contact customer service through the following methods: 1. Click "Online Support" in the APP to transfer to a live agent; 2. Call... |
faq-002 | How to modify personal information | Account management | 1 | 1 | After logging in, go to the "Personal Center" and click the "Edit Profile" button to modify personal information such as nickname, profile picture, phone number, and so on... |
faq-005 | How to use coupons | Promotions | 1 | 1 | On the Shopping Cart page or Checkout page, click "use coupon" and select available coupons to apply the discount. Note: discount... |
faq-006 | Delivery Area and Shipping Fee | Order Logistics | 1 | 1 | We support nationwide delivery (excluding Hong Kong (China), Macao (China), and Taiwan (China) and overseas regions). Orders over CNY 99 qualify for free shipping, while orders under CNY 99 incur a shipping fee of CNY 8... |
faq-008 | Account Security Settings | Account management | 1 | 1 | We recommend that you enable the following security settings: 1. Set a complex password (containing letters, numbers, and special characters); 2. ... |
faq-009 | Payment Methods Explanation | Payment-Related | 1 | 1 | We support the following payment methods: WeChat Pay, Alipay, bank card quick payment, credit card payment, Huabei installment. |
faq-010 | Membership Tier Benefits | Membership Services | 1 | 1 | Membership is divided into four tiers: Regular, Silver, Gold, and Diamond. Upgrade eligibility is based on annual spending amount, with different discounts enjoyed at each level... |
faq-011 | Product Warranty Policy | After-Sales Service | 1 | 1 | Electronic products come with a 1-year warranty; apparel items are eligible for no-questions-asked returns within 7 days; food items can be returned or exchanged within their shelf life... |
faq-012 | Invoice Issuance Instructions | Payment-Related | 0 | 1 | After order completion, you can apply for an e-invoice in "My Orders", supporting both VAT ordinary invoices and VAT special invoices. |
INSERT INTO image_vectors (image_id, image_url, embedding, category, tags, metadata)VALUES ('img-001','https://cdn.example.com/products/phone_x1.jpg',(SELECT array_agg(random())::vector(768) FROM generate_series(1, 768)),Product ImagesARRAY['Product Images', 'smart_cs'],'{"width":800,"height":600,"format":"jpg"}'::jsonb);
image_id | Category | URL | Duration |
img-001 | Product Images | .../products/phone_x1.jpg | 2.3ms |
img-002 | Product Images | .../products/laptop_pro.jpg | 2.0ms |
img-003 | Product Images | .../products/headphone_bt.jpg | 2.0ms |
img-004 | Fault Images | .../faults/screen_crack.jpg | 1.9ms |
img-005 | Fault Images | .../faults/battery_swell.jpg | 1.9ms |
img-006 | Manual | .../manuals/phone_guide.jpg | 1.9ms |
img-007 | Product Images | .../products/tablet_air.jpg | 1.9ms |
img-008 | Product Images | .../products/watch_smart.jpg | 1.9ms |
INSERT INTO chat_sessions (session_id, user_id, channel, status)VALUES('sess-001', 'user-1001', 'web', 'active'),('sess-002', 'user-1002', 'wechat', 'active'),('sess-003', 'user-1003', 'app', 'closed');
session_id | role | content_type | Content Preview | Duration |
sess-001 | user | text | What should I do if I forgot my password? | 2.1ms |
sess-001 | assistant | text | You can reset your password via the "Forgot Password" link... | 2.0ms |
sess-001 | user | text | How long does it take for the password reset to take effect? | 1.9ms |
sess-002 | user | text | When will my order be delivered? | 2.2ms |
sess-002 | assistant | text | Regular orders will be shipped within 48 hours after payment... | 2.1ms |
sess-002 | user | image | This product has a quality issue. | 2.0ms |
sess-003 | user | text | How to apply for a refund? | 1.9ms |
sess-003 | assistant | text | Return and refund process: Go to My Orders... | 2.0ms |
ANALYZE image_vectors; -- took 2.8msANALYZE text_vectors; -- took 2.1msANALYZE chat_sessions; -- took 1.8msANALYZE chat_messages; -- took 1.9ms
SELECT'image_vectors' AS table_name, count(*) AS row_count FROM image_vectorsUNION ALL SELECT'text_vectors', count(*) FROM text_vectorsUNION ALL SELECT'chat_sessions', count(*) FROM chat_sessionsUNION ALL SELECT'chat_messages', count(*) FROM chat_messagesORDER BY table_name;
table_name | row_count |
chat_messages | 8 |
chat_sessions | 3 |
image_vectors | 8 |
text_vectors | 12 |
CREATE INDEX idx_image_vectors_embedding_cosineON image_vectorsUSING hnsw (embedding vector_cosine_ops)WITH (m = 16, ef_construction = 128);
CREATE INDEX idx_text_vectors_embedding_cosineON text_vectorsUSING hnsw (embedding vector_cosine_ops)WITH (m = 16, ef_construction = 128);
CREATE INDEX idx_chat_messages_embedding_cosineON chat_messagesUSING hnsw (embedding vector_cosine_ops)WITH (m = 16, ef_construction = 64);
SELECTindexname AS index_name,pg_size_pretty(pg_relation_size(indexname::regclass)) AS index_size,indexdefFROM pg_indexesWHERE schemaname = 'public'AND indexname LIKE '%embedding_cosine'ORDER BY indexname;
index_name | index_size | Description |
idx_chat_messages_embedding_cosine | 72KB | 1024-dimensional message table |
idx_image_vectors_embedding_cosine | 40KB | 768-dimensional picture table |
idx_text_vectors_embedding_cosine | 104KB | 1024-dimensional text table |
-- Set the search candidate list size (the larger the value, the more precise the search, recommended 100 ~ 200)SET hnsw.ef_search = 100;-- Enable iterative scan mode (to address the issue of insufficient results during WHERE filtering)SET hnsw.iterative_scan = relaxed_order;
SHOW hnsw.ef_search;
hnsw.ef_search |
100 |
# pgvector HNSW search parametershnsw.ef_search = 100hnsw.iterative_scan = relaxed_order
SELECTiv.image_id,iv.image_url,iv.category,iv.tags,1 - (iv.embedding <=> (SELECT embedding FROM image_vectors WHERE image_id = 'img-001'))AS similarityFROM image_vectors ivWHERE iv.status = 1ORDER BY iv.embedding <=> (SELECT embedding FROM image_vectors WHERE image_id = 'img-001')LIMIT 5;
image_id | category | similarity | Description |
img-001 | Product Images | 1.0000 | Query vector itself |
img-008 | Product Images | 0.7696 | Smart watch |
img-006 | Manual | 0.7631 | Mobile Phone Manual |
img-007 | Product Images | 0.7535 | Tablet computer |
img-003 | Product Images | 0.7471 | Bluetooth earphones |
SELECTiv.image_id,iv.image_url,iv.category,1 - (iv.embedding <=> (SELECT embedding FROM image_vectors WHERE image_id = 'img-004'))AS similarityFROM image_vectors ivWHERE iv.status = 1AND iv.category = 'Product Images'ORDER BY iv.embedding <=> (SELECT embedding FROM image_vectors WHERE image_id = 'img-004')LIMIT 5;
image_id | category | similarity |
img-001 | Product Images | 0.7459 |
img-008 | Product Images | 0.7355 |
img-002 | Product Images | 0.7300 |
img-007 | Product Images | 0.7265 |
img-003 | Product Images | 0.7218 |
SELECTtv.doc_id,tv.title,tv.category,tv.priority,1 - (tv.embedding <=> (SELECT embedding FROM text_vectors WHERE doc_id = 'faq-001'))AS similarityFROM text_vectors tvWHERE tv.status = 1AND (tv.expire_at IS NULL OR tv.expire_at > NOW())ORDER BY tv.embedding <=> (SELECT embedding FROM text_vectors WHERE doc_id = 'faq-001')LIMIT 5;
doc_id | title | category | priority | similarity |
faq-001 | How to reset password | Account management | 2 | 1.0000 |
faq-003 | Order delivery time | Order Logistics | 2 | 0.7757 |
faq-006 | Delivery Area and Shipping Fee | Order Logistics | 1 | 0.7662 |
faq-004 | Return and Refund Process | After-Sales Service | 2 | 0.7635 |
faq-009 | Payment Methods Explanation | Payment-Related | 1 | 0.7580 |
SELECTtv.doc_id,tv.title,tv.category,1 - (tv.embedding <=> (SELECT embedding FROM text_vectors WHERE doc_id = 'faq-004'))AS similarityFROM text_vectors tvWHERE tv.status = 1AND 1 - (tv.embedding <=> (SELECT embedding FROM text_vectors WHERE doc_id = 'faq-004')) > 0.5ORDER BY tv.embedding <=> (SELECT embedding FROM text_vectors WHERE doc_id = 'faq-004')LIMIT 5;
doc_id | title | category | similarity |
faq-004 | Return and Refund Process | After-Sales Service | 1.0000 |
faq-001 | How to reset password | Account management | 0.7635 |
faq-008 | Account Security Settings | Account management | 0.7594 |
faq-006 | Delivery Area and Shipping Fee | Order Logistics | 0.7557 |
faq-003 | Order delivery time | Order Logistics | 0.7528 |
SELECTtv.doc_id,tv.title,LEFT(tv.content, 50) AS content_preview,1 - (tv.embedding <=> (SELECT embedding FROM text_vectors WHERE doc_id = 'faq-003'))AS vector_score,ts_rank(to_tsvector('simple', tv.content), plainto_tsquery('simple', 'shipment'))AS text_score,0.7 * (1 - (tv.embedding <=> (SELECT embedding FROM text_vectors WHERE doc_id = 'faq-003')))+ 0.3 * ts_rank(to_tsvector('simple', tv.content), plainto_tsquery('simple', 'shipment'))AS hybrid_scoreFROM text_vectors tvWHERE tv.status = 1ORDER BY hybrid_score DESCLIMIT 5;
doc_id | title | vector_score | text_score | hybrid_score |
faq-003 | Order delivery time | 1.0000 | 0.0 | 0.7000 |
faq-001 | How to reset password | 0.7757 | 0.0 | 0.5430 |
faq-011 | Product Warranty Policy | 0.7712 | 0.0 | 0.5398 |
faq-009 | Payment Methods Explanation | 0.7677 | 0.0 | 0.5374 |
faq-007 | How to Contact Customer Service | 0.7652 | 0.0 | 0.5356 |
SELECTcm.session_id,cm.role,LEFT(cm.content, 50) AS content_preview,1 - (cm.embedding <=> (SELECT embedding FROM chat_messages WHERE content LIKE '%password%' LIMIT 1))AS similarityFROM chat_messages cmWHERE cm.role = 'user'ORDER BY cm.embedding <=> (SELECT embedding FROM chat_messages WHERE content LIKE '%password%' LIMIT 1)LIMIT 5;
session_id | role | content_preview | similarity |
sess-001 | user | What should I do if I forgot my password? | 1.0000 |
sess-002 | user | This product has a quality issue. | 0.7460 |
sess-001 | user | How long does it take for the password reset to take effect? | 0.7460 |
sess-002 | user | When will my order be delivered? | 0.7454 |
sess-003 | user | How to apply for a refund? | 0.7338 |
EXPLAIN (ANALYZE, BUFFERS)SELECTiv.image_id,1 - (iv.embedding <=> (SELECT embedding FROM image_vectors WHERE image_id = 'img-001'))AS similarityFROM image_vectors ivWHERE iv.status = 1ORDER BY iv.embedding <=> (SELECT embedding FROM image_vectors WHERE image_id = 'img-001')LIMIT 10;
Limit (cost=3.48..3.50 rows=8 width=24) (actual time=0.097...)Buffers: shared hit=67InitPlan 1 (returns $0)-> Seq Scan on image_vectors (cost=0.00..1.10 rows=1 ...)Filter: ((image_id)::text = 'img-001'::text)Rows Removed by Filter: 7Buffers: shared hit=1InitPlan 2 (returns $1)-> Seq Scan on image_vectors image_vectors_1 (cost=0.00..1.10 ...)Filter: ((image_id)::text = 'img-001'::text)Rows Removed by Filter: 7Buffers: shared hit=1-> Sort (cost=1.28..1.30 rows=8 width=24) (actual time=0....)Sort Key: ((iv.embedding <=> $1))Sort Method: quicksort Memory: 25kBBuffers: shared hit=67-> Seq Scan on image_vectors iv (cost=0.00..1.16 ...)Filter: (status = 1)Buffers: shared hit=67Planning Time: 0.101 msExecution Time: 0.115 ms
SELECTc.relname AS table_name,pg_size_pretty(pg_total_relation_size(c.oid)) AS total_size,pg_size_pretty(pg_relation_size(c.oid)) AS data_size,pg_size_pretty(pg_indexes_size(c.oid)) AS index_size,s.n_live_tup AS row_countFROM pg_stat_user_tables sJOIN pg_class c ON s.relid = c.oidWHERE c.relname IN ('image_vectors', 'text_vectors', 'chat_sessions', 'chat_messages')ORDER BY pg_total_relation_size(c.oid) DESC;
table_name | total_size | data_size | index_size | row_count |
text_vectors | 344 kB | 8192 bytes | 232 kB | 12 |
image_vectors | 232 kB | 8192 bytes | 152 kB | 8 |
chat_messages | 200 kB | 8192 bytes | 104 kB | 8 |
chat_sessions | 56 kB | 8192 bytes | 48 kB | 3 |
SELECTindexrelname AS index_name,idx_scan AS times_used,pg_size_pretty(pg_relation_size(indexrelid)) AS index_sizeFROM pg_stat_user_indexesWHERE schemaname = 'public'ORDER BY idx_scan DESC;
index_name | times_used | index_size |
image_vectors_pkey | 0 | 16KB |
image_vectors_image_id_key | 0 | 16KB |
text_vectors_pkey | 0 | 16KB |
text_vectors_doc_id_key | 0 | 16KB |
chat_sessions_pkey | 0 | 16KB |
chat_sessions_session_id_key | 0 | 16KB |
chat_messages_pkey | 0 | 16KB |
idx_image_vectors_category | 0 | 16KB |
idx_image_vectors_status | 0 | 16KB |
idx_text_vectors_category | 0 | 16KB |
idx_text_vectors_content_type | 0 | 16KB |
idx_text_vectors_priority | 0 | 16KB |
idx_chat_messages_session | 0 | 16KB |
idx_chat_sessions_user | 0 | 16KB |
idx_image_vectors_tags | 0 | 24KB |
idx_text_vectors_tags | 0 | 24KB |
idx_image_vectors_metadata | 0 | 24KB |
idx_text_vectors_metadata | 0 | 24KB |
idx_image_vectors_embedding_cosine | 0 | 40KB |
idx_text_vectors_embedding_cosine | 0 | 104KB |
idx_chat_messages_embedding_cosine | 0 | 72KB |
SELECTROUND(sum(heap_blks_hit)::numeric /NULLIF(sum(heap_blks_hit) + sum(heap_blks_read), 0) * 100, 2) AS buffer_hit_ratio_pctFROM pg_statio_user_tables;
buffer_hit_ratio_pct |
- (No statistics available for new tables yet) |
-- Install the pg_prewarm extensionCREATE EXTENSION IF NOT EXISTS pg_prewarm;-- Prewarm the image vectors HNSW indexSELECT pg_prewarm('idx_image_vectors_embedding_cosine') AS pages_prewarmed;-- Prewarm the text vectors HNSW indexSELECT pg_prewarm('idx_text_vectors_embedding_cosine') AS pages_prewarmed;
Operation | pages_prewarmed | Duration |
Install pg_prewarm | - | 1.7ms |
Prewarm the image vectors index | 5 pages | 2.0ms |
Prewarm the text vectors index | 13 pages | 1.7ms |
┌─────────────────────────────────────────────────────┐│ Intelligent Customer Service Application Layer │├──────────┬──────────┬──────────┬────────────────────┤│ Image Search │ FAQ Search │ Hybrid Search │ Similar Question Recommendation │├──────────┴──────────┴──────────┴────────────────────┤│ pgvector HNSW index layer ││ • image_vectors: 768-dimensional (CLIP ViT-L/14) ││ • text_vectors: 1024-dimensional (BGE-large-zh-v1.5) ││ • chat_messages: 1024-dimensional (dialogue vector) │├─────────────────────────────────────────────────────┤│ PostgreSQL 15.14 + pgvector 0.8.2 ││ • Cosine distance: <=> operator ││ • HNSW parameters: m=16, ef_search=100 ││ • Auxiliary index: B-Tree + GIN (partial index) │└─────────────────────────────────────────────────────┘
Was this page helpful?
You can also Contact sales or Submit a Ticket for help.
Help us improve! Rate your documentation experience in 5 mins.
Feedback