Docker Pull สำหรับ pgvecto.rs:
VectorChord (VCHORD) เป็นส่วนขยายของ PostgreSQL ที่ออกแบบมาสำหรับการค้นหาความคล้ายคลึงกันของเวกเตอร์ที่มีประสิทธิภาพสูงและมีประสิทธิภาพสูงและทำหน้าที่เป็นผู้สืบทอดต่อ PGVECTO.RS
ด้วย VectorChord คุณสามารถจัดเก็บเวกเตอร์ 400,000 ตัวในราคาเพียง $ 1 ทำให้สามารถประหยัดได้อย่างมีนัยสำคัญ: 6x เวกเตอร์มากขึ้นเมื่อเทียบกับการจัดเก็บที่ดีที่สุดของ Pinecone และมากกว่า 26x มากกว่า pgvector/pgvecto.rs ในราคาเดียวกัน 1 สำหรับข้อมูลเชิงลึกเพิ่มเติมลองดูโพสต์บล็อกเปิดตัวของเรา
VectorChord แนะนำการปรับปรุงที่น่าทึ่งเหนือ PGVECTO.RS และ PGVECTER:
⚡ประสิทธิภาพที่ได้รับการปรับปรุง : การส่งมอบการดำเนินงานที่ดีที่สุดด้วยการสืบค้นที่เร็วกว่า 5 เท่า, ปริมาณการแทรกที่สูงขึ้น 16x และการสร้างดัชนีที่เร็วขึ้น 16X เมื่อเทียบกับการใช้งาน HNSW ของ PGVector
- การค้นหาเวกเตอร์ราคาไม่แพง : การสืบค้น 100m 768 มิติเวกเตอร์โดยใช้หน่วยความจำเพียง 32GB ซึ่งได้รับความล่าช้า 35ms P50 ด้วยการเรียกคืน top10@95%ช่วยให้คุณรักษาค่าใช้จ่ายโครงสร้างพื้นฐานในขณะที่รักษาคุณภาพการค้นหาที่สูง
- การรวมที่ไร้รอยต่อ : เข้ากันได้อย่างเต็มที่กับประเภทข้อมูล PGVector และไวยากรณ์ในขณะที่ให้ค่าเริ่มต้นที่ดีที่สุดออกจากกล่อง - ไม่จำเป็นต้องปรับค่าพารามิเตอร์ด้วยตนเอง เพียงแค่วางใน vectorchord เพื่อประสิทธิภาพที่เพิ่มขึ้น
- การสร้างดัชนีภายนอก : ใช้ประโยชน์จาก IVF เพื่อสร้างดัชนีภายนอก (เช่นบน GPU) สำหรับการจัดกลุ่ม KMEAN ที่เร็วขึ้นรวมกับการบีบอัด Rabitq 3 เพื่อจัดเก็บเวกเตอร์อย่างมีประสิทธิภาพ
- การรองรับเวกเตอร์ยาว : จัดเก็บและค้นหาเวกเตอร์สูงสุด 65,535 มิติทำให้สามารถใช้รุ่นมิติสูงที่ดีที่สุดเช่นการฝังตัวข้อความ -3 ขนาดใหญ่ได้อย่างง่ายดาย
สำหรับผู้ใช้ใหม่เราขอแนะนำให้ใช้อิมเมจ Docker เพื่อเริ่มต้นอย่างรวดเร็ว
docker run
--name vectorchord-demo
-e POSTGRES_PASSWORD=mysecretpassword
-p 5432:5432
-d tensorchord/vchord-postgres:pg17-v0.1.0 จากนั้นคุณสามารถเชื่อมต่อกับฐานข้อมูลโดยใช้เครื่องมือบรรทัดคำสั่ง psql ชื่อผู้ใช้เริ่มต้นคือ postgres และรหัสผ่านเริ่มต้นคือ mysecretpassword
psql -h localhost -p 5432 -U postgresเรียกใช้ SQL ต่อไปนี้เพื่อให้แน่ใจว่าเปิดใช้งานส่วนขยาย
CREATE EXTENSION IF NOT EXISTS vchord CASCADE; และตรวจสอบให้แน่ใจว่าได้เพิ่ม vchord.so ลงใน shared_preload_libraries ใน postgresql.conf
-- Add vchord and pgvector to shared_preload_libraries --
ALTER SYSTEM SET shared_preload_libraries = ' vchord.so ' ;ในการสร้างดัชนี VectorChord Rabitq (VCHORDRQ) คุณสามารถใช้ SQL ต่อไปนี้
-- Set residual_quantization to true and spherical_centroids to false for L2 distance --
CREATE INDEX ON gist_train USING vchordrq (embedding vector_l2_ops) WITH (options = $$
residual_quantization = true
[ build . internal ]
lists = [ 4096 ]
spherical_centroids = false
$$);
-- Set residual_quantization to false and spherical_centroids to true for cos/dot distance --
CREATE INDEX ON laion USING vchordrq (embedding vector_cos_ops) WITH (options = $$
residual_quantization = false
[ build . internal ]
lists = [ 4096 ]
spherical_centroids = true
$$);คำสั่ง Query นั้นเหมือนกับ PGVector VectorChord รองรับการดำเนินการตัวกรองใด ๆ และสถานที่/เข้าร่วมประโยคเช่น pgvecto.rs กับ VBase
SELECT * FROM items ORDER BY embedding < - > ' [3,1,2] ' LIMIT 5 ;ฟังก์ชั่นระยะทางที่รองรับคือ:
คุณสามารถปรับแต่งประสิทธิภาพการค้นหาได้โดยการปรับพารามิเตอร์ probes และ epsilon :
-- Set probes to control the number of lists scanned.
-- Recommended range: 3%–10% of the total `lists` value.
SET vchordrq . probes = 100 ;
-- Set epsilon to control the reranking precision.
-- Larger value means more rerank for higher recall rate.
-- Don't change it unless you only have limited memory.
-- Recommended range: 1.0–1.9. Default value is 1.9.
SET vchordrq . epsilon = 1 . 9 ;
-- vchordrq relies on a projection matrix to optimize performance.
-- Add your vector dimensions to the `prewarm_dim` list to reduce latency.
-- If this is not configured, the first query will have higher latency as the matrix is generated on demand.
-- Default value: '64,128,256,384,512,768,1024,1536'
-- Note: This setting requires a database restart to take effect.
ALTER SYSTEM SET vchordrq . prewarm_dim = ' 64,128,256,384,512,768,1024,1536 ' ;และสำหรับการตั้งค่า Postgres
-- If using SSDs, set `effective_io_concurrency` to 200 for faster disk I/O.
SET effective_io_concurrency = 200 ;
-- Disable JIT (Just-In-Time Compilation) as it offers minimal benefit (1–2%)
-- and adds overhead for single-query workloads.
SET jit = off;
-- Allocate at least 25% of total memory to `shared_buffers`.
-- For disk-heavy workloads, you can increase this to up to 90% of total memory. You may also want to disable swap with network storage to avoid io hang.
-- Note: A restart is required for this setting to take effect.
ALTER SYSTEM SET shared_buffers = ' 8GB ' ;ในการทำดัชนีล่วงหน้าคุณสามารถใช้ SQL ต่อไปนี้ มันจะปรับปรุงประสิทธิภาพอย่างมีนัยสำคัญเมื่อใช้หน่วยความจำที่ จำกัด
-- vchordrq_prewarm(index_name::regclass) to prewarm the index into the shared buffer
SELECT vchordrq_prewarm( ' gist_train_embedding_idx ' ::regclass) "การสร้างดัชนีสามารถขนานกันและด้วยการคำนวณเซนทรอยด์ภายนอกเวลาทั้งหมดจะถูก จำกัด ด้วยความเร็วของดิสก์เป็นหลัก เพิ่มประสิทธิภาพการขนานโดยใช้การตั้งค่าต่อไปนี้:
-- Set this to the number of CPU cores available for parallel operations.
SET max_parallel_maintenance_workers = 8 ;
SET max_parallel_workers = 8 ;
-- Adjust the total number of worker processes.
-- Note: A restart is required for this setting to take effect.
ALTER SYSTEM SET max_worker_processes = 8 ; คุณสามารถตรวจสอบความคืบหน้าการจัดทำดัชนีโดยการสอบถามมุมมอง pg_stat_progress_create_index
SELECT phase, round( 100 . 0 * blocks_done / nullif(blocks_total, 0 ), 1 ) AS " % " FROM pg_stat_progress_create_index;ซึ่งแตกต่างจาก SQL บริสุทธิ์การคำนวณดัชนีภายนอกจะทำการจัดกลุ่มภายนอกและแทรกเซนทรอยด์ลงในตาราง postgreSQL แม้ว่ามันอาจจะซับซ้อนกว่า แต่การสร้างภายนอกนั้นเร็วกว่าในชุดข้อมูลขนาดใหญ่กว่า (> 5m)
ในการเริ่มต้นคุณต้องทำการจัดกลุ่มเวกเตอร์โดยใช้ faiss , scikit-learn หรือห้องสมุดการจัดกลุ่มอื่น ๆ
centroids ควรตั้งไว้ล่วงหน้าในตารางที่มี 3 คอลัมน์:
pgvector vector ประเภทและตัวอย่างอาจเป็นเช่นนี้:
-- Create table of centroids
CREATE TABLE public .centroids (id integer NOT NULL UNIQUE, parent integer , vector vector( 768 ));
-- Insert centroids into it
INSERT INTO public . centroids (id, parent, vector) VALUES ( 1 , NULL , ' {0.1, 0.2, 0.3, ..., 0.768} ' );
INSERT INTO public . centroids (id, parent, vector) VALUES ( 2 , NULL , ' {0.4, 0.5, 0.6, ..., 0.768} ' );
INSERT INTO public . centroids (id, parent, vector) VALUES ( 3 , NULL , ' {0.7, 0.8, 0.9, ..., 0.768} ' );
-- ...
-- Create index using the centroid table
CREATE INDEX ON gist_train USING vchordrq (embedding vector_l2_ops) WITH (options = $$
[ build . external ]
table = ' public.centroids '
$$);เพื่อลดความซับซ้อนของเวิร์กโฟลว์เราให้สคริปต์แบบ end-to-end สำหรับดัชนีภายนอกการคำนวณล่วงหน้าดูสคริปต์
ติดตั้ง PGRX ตามคำแนะนำของ PGRX
cargo install --locked cargo-pgrx
cargo pgrx init --pg17 $( which pg_config ) # To init with system postgres, with pg_config in PATH
cargo pgrx install --release --sudo # To install the extension into the system postgres with sudo ซอฟต์แวร์นี้ได้รับอนุญาตภายใต้รูปแบบใบอนุญาตคู่:
GNU Affero Public Public License V3 (AGPLV3) : คุณสามารถใช้แก้ไขและแจกจ่ายซอฟต์แวร์นี้ภายใต้ข้อกำหนดของ AGPLV3
Elastic License V2 (ELV2) : คุณสามารถใช้แก้ไขและแจกจ่ายซอฟต์แวร์นี้ภายใต้ใบอนุญาตยืดหยุ่น V2 ซึ่งมีข้อ จำกัด เฉพาะ
คุณสามารถเลือกใบอนุญาตตามความต้องการของคุณ เรายินดีต้อนรับการทำงานร่วมกันหรือการสนับสนุนเชิงพาณิชย์ดังนั้นโปรดส่งอีเมลถึงเรา [email protected] ส่งอีเมลถึงเราด้วยคำถามหรือคำขอเกี่ยวกับใบอนุญาต
ขึ้นอยู่กับเกณฑ์มาตรฐาน myscale ที่มีเวกเตอร์ 768 มิติและการเรียกคืน 95%
ขึ้นอยู่กับเกณฑ์มาตรฐาน myscale กับเวกเตอร์ 768 มิติ โปรดตรวจสอบโพสต์บล็อกของเราสำหรับรายละเอียดเพิ่มเติม
Gao, Jianyang และ Cheng Long "RabitQ: การหาปริมาณเวกเตอร์มิติสูงที่มีข้อผิดพลาดทางทฤษฎีที่ถูกผูกไว้สำหรับการค้นหาเพื่อนบ้านที่ใกล้ที่สุดโดยประมาณ" การดำเนินการของ ACM เกี่ยวกับการจัดการข้อมูล 2.3 (2024): 1-27