# pgvector MCP for AI Agents AI Agent Connect

> pgvector (Vector Database) lets you run vector similarity searches and manage embedding tables directly inside your existing PostgreSQL database. It connects your database to your AI client so you can build retrieval pipelines without adding new infrastructure.

## Overview
- **Category:** loved-by-devs
- **Price:** Free
- **Endpoint:** https://edge.vinkius.com/vk_preview_m3Dmr7TKd7NjkaPwx4OA0eTWiY7yo9GZdmp9NSJ4/ai-agent-connect
- **Tags:** embeddings, similarity-search, postgresql, nearest-neighbor, vector-index

## Description

You're already using PostgreSQL for your data, so why move your embeddings to a separate database? This Connector lets your agent talk directly to your tables. Instead of writing manual SQL queries or building extra API layers just to get some semantic search results, you can just ask your agent to find the most relevant documents or update your records. It handles the heavy lifting of creating indexes to keep your searches fast as your data grows. Because it lives inside your primary database, you don't have to worry about keeping two different systems in sync. It's a straightforward way to bring retrieval capabilities to your existing stack. You can find this among the thousands of integrations in the Vinkius marketplace, making it easy to plug into your workflow. It's about making your data accessible to your agent without the overhead of managing more services.

## Tools

### search_vectors
Run a similarity search to find the closest matches for a specific query. This helps you find relevant data based on meaning rather than just keywords.

### list_tables
View a list of all tables in your database. Use this to quickly identify which ones contain your vector data.

### insert_vector
Add a new vector and its associated metadata into an existing table. This keeps your knowledge base updated with new entries.

### create_index
Set up HNSW or IVFFlat indexes on your vector columns. This makes your similarity searches much faster as your dataset grows.

### create_table
Build a new table with the specific dimensions required for your embeddings. This sets up the correct structure for your vector data.

### delete_vector
Remove a specific vector entry from your database. This is useful for keeping your data clean and up to date.

## Prompt Examples

**Prompt:** 
```
Show me the 3 most similar support tickets to this issue: 'My login is failing on the mobile app'.
```

**Response:** 
```
### Top 3 Similar Tickets

| Ticket ID | Subject | Distance |
| :--- | :--- | :--- |
| #4021 | **Login loop on iOS** | 0.12 |
| #3988 | **Auth timeout error** | 0.15 |
| #3812 | **Incorrect credentials prompt** | 0.19 |

**Summary:** The issue seems closely related to mobile authentication loops. Would you like me to pull the full logs for ticket #4021?
```

**Prompt:** 
```
Create a new table for movie embeddings with 768 dimensions and an HNSW index.
```

**Response:** 
```
### Table Creation Successful

I've created the following structure for you:

*   **Table Name:** `movie_embeddings`
*   **Columns:** `id` (TEXT), `embedding` (vector(768)), `title` (TEXT)
*   **Index:** HNSW (vector_cosine_ops)

The table is now ready for data ingestion. Do you want to start inserting records now?
```

**Prompt:** 
```
Which tables in my database currently have vector columns?
```

**Response:** 
```
### Vector Tables Found

I scanned your database and found 2 tables containing vector data:

1.  **`document_chunks`**: 1536 dimensions, 48,200 rows (HNSW index active)
2.  **`product_embeddings`**: 768 dimensions, 12,500 rows (No index active)

**Note:** You might want to create an index for the `product_embeddings` table to improve search speed.
```

## Capabilities

### Run nearest-neighbor queries
Find the closest data matches using cosine, L2, or inner product distance metrics.

### Discover vector tables
Identify which tables in your database contain vector columns and dimensions.

### Add vector entries
Insert new embeddings along with their metadata into your existing tables.

### Create embedding tables
Build new tables with the specific dimensions required for your vector data.

### Build HNSW or IVFFlat indexes
Accelerate your search results by creating specialized indexes on vector columns.

### Remove vector records
Delete specific vector entries to keep your database clean and accurate.

## Use Cases

### Finding similar support tickets
A developer needs to find the 5 most similar documents to a user's question using search_vectors.

### Improving search speed on large datasets
An engineer needs to create a new index on a large product table to improve search speed with create_index.

### Auditing vector columns across the database
A data scientist wants to see which tables currently hold vector data to plan a migration using list_tables.

### Updating user embeddings on the fly
A fullstack dev needs to add new user embeddings to a table without writing a backend endpoint using insert_vector.

## Benefits

- Keep your architecture simple by staying inside PostgreSQL instead of managing a separate vector database.
- Speed up your search results significantly by using create_index to build HNSW or IVFFlat indexes.
- Reduce development time by using search_vectors to query your data without writing custom SQL.
- Maintain data integrity by using insert_vector to keep your embeddings and metadata in one place.
- Simplify your schema management by using list_tables to quickly audit your vector columns.
- Build faster RAG pipelines by using create_table to set up dedicated embedding storage.

## How It Works

The bottom line is you get production-ready vector search without leaving your PostgreSQL environment.

1. Connect your PostgreSQL connection string to the Connector.
2. Grant your AI client permission to access your database.
3. Ask your agent to perform searches, create indexes, or manage tables.

## Frequently Asked Questions

**Can pgvector MCP help me build a RAG system?**
Yes, it allows your agent to query embeddings directly from your PostgreSQL database. This makes it easy to build a retrieval-augmented generation pipeline without needing a separate vector database.

**How do I use pgvector MCP to speed up my searches?**
You can ask your agent to create HNSW or IVFFlat indexes on your vector columns. These indexes significantly reduce the time it takes to find the most similar results in large datasets.

**Does pgvector MCP support different distance metrics?**
Yes, it supports common metrics like cosine, L2, and inner product. You can specify which one your agent should use when performing a similarity search.

**Can I manage my embeddings directly with pgvector MCP?**
Absolutely. You can ask your agent to insert new embeddings, update existing ones, or delete old records directly within your PostgreSQL tables.

**Is pgvector MCP better than a separate vector database?**
It depends on your needs. If you already use PostgreSQL and want to keep your data in one place, this is often the simplest choice. If you need specialized high-scale vector-only features, a dedicated store might be better.

**How does pgvector MCP handle large datasets?**
It handles large scale data by using production-grade indexing. By creating HNSW or IVFFlat indexes, the Connector ensures your similarity searches remain fast even as your row count grows into the millions.

**Does the agent connect directly to my database?**
Yes. Your connection string is encrypted at rest and injected into an isolated runtime. The agent connects directly to your PostgreSQL instance — no intermediate proxies, no data copies, no third-party storage.

**What vector dimensions are supported?**
Any dimension supported by pgvector — from small 128-d vectors to large 3072-d embeddings (e.g., OpenAI text-embedding-3-large). Specify the dimension when creating a table and the agent handles the rest.

**Which distance metrics can I use for similarity search?**
pgvector supports three operators: `` (L2/Euclidean distance), `` (cosine distance), and `` (negative inner product). The agent uses cosine distance by default, which works best for normalized embeddings like those from OpenAI.