What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To use pgvector, install the extension on the PostgreSQL server, enable it in the database where you need it, then create a vector column and an index whose operator class matches your distance metric. The steps below take you from installation to a working nearest-neighbor query.

1. Install pgvector on the PostgreSQL server

Installing pgvector makes the extension available to PostgreSQL; it does not enable it in every database. The project’s README documents source builds and package-manager installation routes including Docker, Homebrew, PGXN, APT, and Yum. Package names and PostgreSQL-version support vary by platform, so choose instructions that match the operating system and PostgreSQL server version you actually run.

The current project README’s source-build example checks out the v0.8.7 branch and runs make followed by make install. The documented source-build support is for Linux and Mac with PostgreSQL 13 or later; installation may require elevated privileges. Check the project instructions for the exact prerequisites and commands for your environment.

If PostgreSQL is managed by a cloud or hosting provider, check that provider’s current documentation for pgvector availability, supported versions, and required permissions. Those details differ by service; the SQL steps below assume the server has the extension installed.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

2. Enable pgvector in the database

Connect to the specific database that will store vectors and run:

CREATE EXTENSION vector;

This is database-specific: run the command once in each database where pgvector is needed. Your database role must have enough privilege to create the extension; the required role or grant depends on the PostgreSQL service.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

3. Create a vector column and insert sample data

A vector column declares how many dimensions each vector contains. This small example uses three dimensions only to demonstrate the SQL syntax:

CREATE TABLE items (
  id bigserial PRIMARY KEY,
  embedding vector(3)
);

INSERT INTO items (embedding)
VALUES ('[1,2,3]'), ('[4,5,6]');

Replace 3 with the dimensionality produced by your embedding model or other vector source. Stored vectors and query vectors must match the declared dimension. The sample values are not meaningful production embeddings.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

4. Run an exact nearest-neighbor query

Before adding an approximate index, try a query against the table. This example orders rows by L2 distance from the supplied vector and returns at most five:

SELECT *
FROM items
ORDER BY embedding <-> '[3,1,2]'
LIMIT 5;

pgvector provides several distance operators. Choose the one that matches the comparison your application needs:

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
  • <->: L2 (Euclidean) distance.
  • <#>: negative inner product. It is negative so PostgreSQL can use ascending-order index scans; multiply the returned value by -1 if you need the positive inner product.
  • <=>: cosine distance.
  • <+>: L1 (Manhattan) distance.

By default, pgvector performs exact nearest-neighbor search, which provides perfect recall. Exact search is a useful baseline: an approximate index can change which rows appear among the nearest results.

5. Create an index for your distance metric

For L2 distance, create an HNSW index with the L2 operator class:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
CREATE INDEX ON items USING hnsw (embedding vector_l2_ops);

Use an operator class that matches the distance operator in your query. For cosine distance use vector_cosine_ops; for inner product use vector_ip_ops. For example, a cosine-distance query should order by embedding <=> query_vector and use an index on embedding vector_cosine_ops.

For production, the project documentation recommends adding indexes after initial bulk loading for best performance and creating them concurrently to avoid blocking writes. Concurrent index creation uses PostgreSQL’s CREATE INDEX CONCURRENTLY form; follow PostgreSQL’s restrictions for that command when choosing where and how to run it.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose between HNSW and IVFFlat

Both HNSW and IVFFlat are approximate nearest-neighbor indexes: they can improve query speed but trade away some recall compared with exact search. The following are qualitative tradeoffs described by the pgvector project documentation, not independent benchmark results.

Consideration HNSW IVFFlat
Speed and recall tradeoff Better query performance in the project’s speed-recall comparison. Lower query performance in the project’s speed-recall comparison.
Build and memory Slower index build and more memory. Faster index build and less memory.
When to build Can be created before the table contains data. Build after the table has some data for good recall.
Index form CREATE INDEX ON items USING hnsw (embedding vector_l2_ops); CREATE INDEX ON items USING ivfflat (embedding vector_l2_ops) WITH (lists = ...);

IVFFlat starting points

The project README suggests these initial values for the IVFFlat lists setting: use approximately rows / 1000 lists for tables up to one million rows, and sqrt(rows) for larger tables. Start with approximately sqrt(lists) probes. These are tuning starting points, not universal optimal settings. More probes favor recall over speed; measure the tradeoff with your own data and workload.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Account for filters in approximate searches

With an approximate index, a selective WHERE filter is applied after the index scan. As a result, the query may return fewer matching rows than the requested LIMIT. The project documentation describes iterative index scans as one way to address this, and also points to ordinary indexes on filter columns, partial indexes, or partitioning as alternatives depending on the workload. Choose based on your filter patterns and validate the result count and recall you need.

Quick setup checklist

  • Install pgvector for the PostgreSQL server and version you use.
  • Run CREATE EXTENSION vector; in every database that needs the extension.
  • Set vector(n) to the actual vector dimension, and use vectors of that same dimension in inserts and queries.
  • Test the distance-ordered query before adding an approximate index.
  • Match the index operator class to the query’s distance operator.
  • Evaluate approximate-search recall, filtering behavior, and tuning against your workload.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.