Skip to content

pgvector

pgvector

PostgreSQL extension for vector similarity search, enabling RAG on existing Postgres.

Official Site
01

Overview

pgvector is a retrieval-augmented generation (RAG) or vector-database tool that stores embeddings of your documents or code and retrieves the most relevant chunks to ground LLM responses. It handles indexing, similarity search, filtering, and hybrid retrieval so your AI applications cite accurate, up-to-date information instead of hallucinating.

02

Getting Started

Start with pgvector by creating a collection/index, embedding your source documents or code, and upserting the vectors with metadata. At query time, embed the user query, run a similarity search (optionally with metadata filters), and feed the top results into your LLM prompt as context.

bash
# Install
pip install pgvector

# Index and query (Python example)
from pgvector import Client
client = Client()
client.create_collection("docs")
client.upsert("docs", ids=[...], embeddings=[...], metadatas=[...])
results = client.query("docs", query_embedding=embed("question"), top_k=5)
03

Use Cases

Use cases for pgvector: (1) building a docs-search or support-chatbot that answers from your knowledge base; (2) code-semantic search across a monorepo; (3) hybrid search combining keyword (BM25) and vector retrieval for precision + recall; (4) deduplicating near-identical documents via embedding distance; (5) powering "find similar issues" features in issue trackers.

04

Tips

Tips for pgvector: chunking strategy matters as much as the embedding model—experiment with chunk size and overlap. Store rich metadata (source, section, date) so you can filter at query time. Re-embed when you upgrade the embedding model; mixing models in one index degrades recall. Measure retrieval quality (recall@k, MRR) on a labeled eval set, not just vibe-check.

Ready to try pgvector?

Visit the official site for the latest version and full documentation.

Visit pgvector