Getting Started with PgVector

Prev Next

Introduction

Pgvector is an open-source PostgreSQL extension that adds native support for vector similarity search, allowing Cake teams to integrate vector-based retrieval directly into their relational data infrastructure. With pgvector, embeddings generated by LLMs, image encoders, or other ML models can be stored and queried within the same database that powers transactional or metadata storage—reducing complexity, improving performance, and enabling tight coupling between structured and unstructured search.

Key Benefits of Using pgvector include:

  • Native Vector Storage: Adds a vector data type to PostgreSQL, allowing storage of dense numerical arrays (e.g., sentence embeddings, product vectors) alongside tabular metadata.

  • Similarity Search: Supports efficient similarity metrics like cosine distance, Euclidean distance, and inner product—crucial for nearest neighbor search in semantic applications.

  • Indexing with IVFFlat: Enables fast approximate nearest neighbor (ANN) search using the ivfflat index type—making it viable for large-scale retrieval use cases.

  • PostgreSQL Integration: Seamlessly fits into existing Postgres-based systems, allowing joins, filters, ordering, and full SQL expressiveness when working with hybrid queries (e.g., filter by user and rank by vector similarity).

  • Production-Ready Simplicity: Avoids external infrastructure dependencies (like standalone vector DBs), reduces architectural complexity, and simplifies deployment and monitoring within Cake’s data stack.

Use Cases

PGVector is used for:

  • Powering vector-based retrieval in RAG pipelines (e.g., document search, Q&A, semantic memory for agents).

  • Storing multimodal embeddings (e.g., text, image, or audio) alongside rich metadata for unified access.

  • Enabling hybrid search—combining structured filters with unstructured similarity—for personalized recommendations and LLM input curation.

  • Rapid prototyping of semantic search systems with minimal infrastructure overhead.

PGVector integrates with upstream embedding generators (e.g., OpenAI, Hugging Face Transformers, LLaMA), and downstream inference pipelines (e.g., vLLM, LangChain, Arize Phoenix), and fits into orchestration and monitoring workflows via PipeCat, Airflow, and Grafana.

Important Links

Main Site

Documentation