Cookie settings

Decide per category. You can come back here at any time from the footer.

NecessaryAlways on

Signing in, your language and theme, and remembering this very choice. The site does not work without them, so there is nothing to switch off.

Google Analytics, to see which pages get used and where people give up. Off until you turn it on, and the data is never passed on to Google Ads.

Aderlo Cloud
Sign inGet started

pgvector in practice: semantic search and a knowledge base for an AI agent in your store

Grzegorz Ciupek · Updated 6 October 2026 · 7 min read

pgvector is a PostgreSQL extension that stores vectors (embeddings) and finds the most similar ones. With it, a store can find “shoes for the rain” among products described as “waterproof footwear”, and an AI agent can answer customer questions based on your terms and conditions and product descriptions. You do not need a separate vector database: on Aderlo Cloud pgvector is available in every PostgreSQL database from the moment it is created.

How it works in three steps

  1. Turn text into a vector

    An embedding model from the AI provider of your choice turns a product description or a document fragment into a list of numbers (for example 1,536 values).

  2. Store it in PostgreSQL

    The vector goes into a column of type vector next to ordinary data: name, price, page URL.

  3. Search by similarity

    You turn the customer’s question into a vector with the same model and ask the database for the nearest results.

A minimal example

CREATE TABLE product_chunks (
  id bigserial PRIMARY KEY,
  product_url text NOT NULL,
  content text NOT NULL,
  embedding vector(1536)
);

CREATE INDEX ON product_chunks USING hnsw (embedding vector_cosine_ops);

-- $1 = the question's vector, computed with the same model
SELECT product_url, content
FROM product_chunks
ORDER BY embedding <=> $1
LIMIT 5;

The column’s dimension must match the embedding model. If you change models, recompute the vectors — vectors from two different models are not comparable.

Uses in a store

  • Search by meaning that understands synonyms and descriptions of needs, not just product names.
  • A knowledge base for a customer-service agent: terms and conditions, delivery, returns — the agent answers from your own documents, with a link to the source.
  • Similar products based on the description, when purchase data is missing.
  • Catalogue clean-up: detecting duplicate products listed under different names.

AI agents and pgvector on Aderlo Cloud

An agent connected over MCP can create a vector table itself in a database you have given it full access to, and query it in the production database with read-only access. You schedule vector recomputation inside the database with pg_cron, and pass product changes on with a webhook from the database. Access details: PostgreSQL for AI agents.

Frequently asked questions

Do I need a separate vector database, such as Pinecone?
For a store with thousands or tens of thousands of products, usually not. pgvector keeps vectors next to the data, so filtering by price or availability and searching by meaning happen in a single query.
Which index should I choose: HNSW or IVFFlat?
HNSW usually gives a better balance of speed and accuracy and does not need data to build the index; IVFFlat builds faster and uses less memory. The pgvector documentation describes both.

Sources