pg_vectorsearch क्या है?
pg_vectorsearch PostgreSQL के अंदर तेज़ vector search के लिए partition-based PRISM index. यह Retrieval & Knowledge (RAG) टूल्स की Vector Databases श्रेणी में आता है; ओपन सोर्स है, C में लिखा गया है और PostgreSQL लाइसेंस के तहत है। शुरू करने के लिए: extension build और install करें.
सारांश
pg_vectorsearch, Tiger Data (Timescale के पीछे की कंपनी) का बनाया एक ओपन सोर्स PostgreSQL extension है, जो approximate nearest neighbor (ANN) vector search के लिए है। इसमें PRISM (Partitioned Routing Index for Similarity Matching) नाम का index type जुड़ता है, एक IVF-style index जिसमें hierarchical routing है और जो 100 million vectors या उससे ज़्यादा के collections के लिए बनाया गया है।

HNSW जो graph बनाता है, उसकी जगह PRISM समान vectors को k-means partitions में समूहबद्ध करता है और compressed RaBitQ codes स्टोर करता है। इन codes में हर dimension के लिए लगभग एक bit होता है, और इन्हें database pages में पैक किया जाता है। Query cluster centroids के एक छोटे tree से होकर गुजरती है और फिर SIMD (AVX2, AVX512 या NEON) से सबसे नज़दीकी partitions को scan करती है। Partition की सीमा के पास वाले vectors को recall बढ़ाने के लिए एक से ज़्यादा partition में स्टोर किया जा सकता है, और error bounds वाला two-stage search full-precision reranking की ज़रूरत को सीमित करता है।
यह extension अपने `vec32` और `vec16` types के साथ काम करता है, और मौजूदा pgvector के `vector` व `halfvec` columns को सीधे index कर सकता है। इसलिए pgvector इस्तेमाल करने वाली table अपना schema और queries जस के तस रखती है। Tiger Data इसे pgvectorscale के successor के रूप में पेश करता है, और कंपनी के अनुसार pgvectorscale maintenance mode में जा रहा है। यह project alpha के रूप में चिह्नित है: README के अनुसार यह testing के लिए है, production के लिए नहीं, और prereleases के बीच indexes को दोबारा बनाना चाहिए।
यह क्या करता है
- PRISM index: hierarchical centroid routing के साथ k-means partitions, 100M+ vectors के लिए बनाया गया
- RaBitQ quantization, दो-चरणीय (two-stage) और error-bounded search के साथ, जो full-precision reranking को कम करता है
- AVX2, AVX512 और NEON पर SIMD distance computation

- मौजूदा pgvector vector और halfvec columns को table दोबारा लिखे बिना index करता है
- vec32/vector और vec16/halfvec के लिए L2, inner-product और cosine operator classes
- एक मुख्य tuning knob, prism.nprobe, जहाँ 0 का मतलब है कि लगभग 95% recall अपने-आप लक्ष्य होता है
- Inserts, updates और deletes, जिनमें बड़ी posting lists को prism_rebalance या REINDEX से split किया जाता है
शुरू करें
pg_vectorsearch को Meson से source से build किया जाता है। इसके लिए development headers के साथ PostgreSQL 18 या उसके बाद का संस्करण और C11 compiler (GCC 11+ या Clang 14+) चाहिए। Index बनाने से पहले अपना data load करें, क्योंकि index का साइज़ row count से तय होता है।
Extension build और install करें
Repository clone करें और उसे release mode में build करें। CBLAS वैकल्पिक है, लेकिन यह RaBitQ encoding को तेज़ करता है।
git clone https://github.com/timescale/pg_vectorsearch.git
cd pg_vectorsearch
meson setup builddir --buildtype=release
meson install -C builddirTable बनाएँ और vectors load करें
Extension enable करें और embeddings को vec32 column में स्टोर करें (storage आधा करने के लिए vec16 इस्तेमाल करें)।
CREATE EXTENSION pg_vectorsearch;
CREATE TABLE items (
id serial PRIMARY KEY,
embedding vec32(3) STORAGE PLAIN
);
INSERT INTO items (embedding)
SELECT ARRAY[i::real, (i % 7)::real, (i % 5)::real]::vec32
FROM generate_series(1, 1000) i;PRISM index बनाएँ और उस पर query करें
Operator class के साथ index बनाएँ, ज़्यादा recall के लिए चाहें तो nprobe बढ़ाएँ, फिर distance के हिसाब से order करें।
CREATE INDEX ON items USING prism (embedding vec32_l2_ops);
SET prism.nprobe = 40; -- 0 = auto (about 0.95 recall)
SELECT * FROM items
ORDER BY embedding <-> '[3,1,2]'
LIMIT 5;या मौजूदा pgvector table को index करें
PRISM pgvector के vector और halfvec columns को सीधे पढ़ता है। vector_<metric>_ops को vec32_<metric>_ops से बदलें (halfvec के लिए vec16), EXPLAIN से जाँचें कि planner उसका इस्तेमाल कर रहा है, और फिर पुराना HNSW index हटा दें, अगर उसकी ज़रूरत नहीं है।
CREATE EXTENSION vector;
CREATE EXTENSION pg_vectorsearch;
CREATE INDEX documents_embedding_prism
ON documents USING prism (embedding vec32_l2_ops);कमांड और कोड प्रोजेक्ट के अपने दस्तावेज़ों से लिए गए हैं — हमेशा जांचें आधिकारिक repo ताज़ा जानकारी के लिए।
कब इस्तेमाल करें
- अलग vector database के बिना PostgreSQL के अंदर 100M+ embeddings पर vector search चलाना
- pgvector के उस HNSW index को बदलना, जो बनाने में बहुत धीमा है या उपलब्ध memory के लिए बहुत बड़ा है
- छोटे, सस्ते database instances पर उच्च recall के साथ RAG retrieval चलाना
- Migration से पहले मौजूदा pgvector setup के साथ partition-based ANN index को परखना
How pg_vectorsearch compares
pg_vectorsearch alongside other open-source vector databases tools AI/TLDR tracks, ranked by GitHub stars.
| टूल | स्टार | यह क्या करता है |
|---|---|---|
| Supabase | ★ 116k | Managed Postgres backend whose Vector toolkit (pgvector) stores, indexes, and queries embeddings next to transactional data. |
| Redis Cloud | ★ 77.9k | Fully-managed Redis with built-in vector search, offering low-latency similarity and hybrid queries over any embeddings. |
| Milvus | ★ 46.8k | अरबों embeddings में बड़े पैमाने पर खोज के लिए एक ओपन सोर्स वेक्टर डेटाबेस |
| FAISS | ★ 42k | dense vectors पर कुशल similarity search और clustering के लिए लाइब्रेरी |
| Qdrant | ★ 35.9k | Rust में लिखा, समृद्ध payload फ़िल्टरिंग वाला सिमेंटिक सर्च के लिए वेक्टर सर्च इंजन |
| Chroma | ★ 29.8k | ओपन सोर्स एम्बेडिंग डेटाबेस, जो रिट्रीवल और RAG फ़ीचर बनाने में मदद करता है |
| pgvector | ★ 23.9k | Postgres के लिए ओपन सोर्स वेक्टर similarity search |
| pg_vectorsearch | ★ 459 | PostgreSQL के अंदर तेज़ vector search के लिए partition-based PRISM index |

