Skip to main content
pgvector ships on every InsForge project. Use it for semantic search, recommendations, and RAG.

Prompt your agent

Add pgvector to my project. Create a documents table with content and a 1536-dim embedding column, plus an HNSW cosine index. When I insert content, embed it with OpenRouter’s text-embedding-3-small from a server-side route. Expose a match_documents(query, count, threshold) RPC that returns top similarity matches.

Concepts

A vector is a list of numbers representing an item. Two vectors are similar if they sit close in vector space. Store the vector next to its row, embed the user query the same way, and pgvector ranks by distance.

Usage

Enable the extension and create a vector column. Match the dimension to your model (text-embedding-3-small is 1536).
Generate an embedding server-side and insert it.
Query by cosine distance (<=>). L2 (<->) and inner product (<#>) are also available.

Specific usage cases

Wrap search in a Postgres function and call it via rpc() to keep the math server-side:
Past ~10k rows, add an HNSW index:

More resources