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

To add semantic search to PostgreSQL, generate an embedding for every document or text chunk and every incoming query with the same model and compatible dimensions, store document vectors alongside their source records, and order matches with pgvector’s distance operators. Start with exact search; add HNSW or IVFFlat only after measurements show that exact queries are too slow.

An embedding is a list of floating-point numbers that represents text in a form useful for comparing relatedness. Similarity is a signal, not a guarantee that the nearest result is correct: test retrieval on your own content and combine it with literal text search when exact terms matter.

What you need for PostgreSQL semantic search

PostgreSQL does not provide vector storage and nearest-neighbor operators by itself. The pgvector extension adds them. Your application also needs an embedding model that can turn both stored text and user queries into vectors.

  • Embedding model: select one and record its name and settings. Use the same model configuration for the documents and the queries you compare.
  • pgvector: install and enable the extension in the database where the search will run.
  • Source records: retain each text or chunk, a stable identifier, and relevant metadata alongside its vector or in a reliably linked table.
  • Retrieval test set: prepare representative searches and judge whether the returned records are useful before tuning an index.

For example, OpenAI’s API guide lists default widths of 1,536 dimensions for text-embedding-3-small and 3,072 for text-embedding-3-large. It also supports a dimensions parameter to reduce the output width. These are provider-specific specifications, not universal dimensions for embedding models. The guide lists a maximum input length of 8,192 tokens for both models; keep each input within the selected model’s current documented limit. See the OpenAI Embeddings API guide.

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.

Generate document and query embeddings consistently

For each record, send the text or chunk to your chosen embedding endpoint and save the returned vector. When a user searches, embed the query with the same model and compatible settings. The vector width must match the database column and the vectors already stored in the collection.

Model changes are not just a configuration toggle. Vectors from unrelated model spaces should not be compared as though they were interchangeable. If you change model or dimensions, plan a re-embedding process, and keep track of which model configuration produced each collection’s vectors. You can migrate or backfill a new collection before switching queries to it.

OpenAI’s API guide describes sending input text and a model name to the embeddings endpoint, then extracting the returned vector. Keep API credentials in environment variables or a secret-management system rather than hard-coding them in application code.

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.

Enable pgvector and create a table

Enable the extension in the database, then create a table with a stable key, source text, any useful retrieval metadata, and a vector column sized for the selected model configuration:

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.
CREATE EXTENSION vector;

CREATE TABLE document_chunks (
    id bigserial PRIMARY KEY,
    document_id text NOT NULL,
    content text NOT NULL,
    metadata jsonb NOT NULL DEFAULT '{}'::jsonb,
    embedding vector(1536) NOT NULL
);

Here, vector(1536) is appropriate only if the configured embedding output has 1,536 dimensions. Change it if your model or requested output width differs. The OpenAI Cookbook’s Supabase example likewise uses a non-null content field and embedding vector(1536); its dimension is an example, not a size to copy blindly.

Keep each vector with the text it represents, its document identifier, and the metadata needed for filtering or provenance. If a document is split into chunks, give each chunk its own stable row and retain a way to identify the parent document.

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.

pgvector also allows an unconstrained vector column for mixed dimensions, but an index can cover only rows with the same dimensions. The extension documentation describes expression and partial indexes for specific dimension or model groups. For a single collection, a dimensioned column makes the expected shape explicit and helps prevent mismatched vectors.

Query nearest rows with the matching distance operator

Embed the query, bind its vector as a parameter, and sort by a pgvector distance operator. For cosine distance, an illustrative query is:

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.
SELECT id, document_id, content,
       embedding <=> $1 AS distance
FROM document_chunks
ORDER BY embedding <=> $1
LIMIT 10;

Replace $1 with a properly bound query vector in your database driver; do not construct SQL by concatenating untrusted input. The smaller cosine distance indicates a closer match. pgvector also provides <-> for L2 distance and <#> for negative inner product. The latter is negative because PostgreSQL index scans use ascending operator order.

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

Choose the metric that fits your model and vector handling, then use the corresponding operator class if you add an index. If vectors are normalized to length 1, pgvector recommends inner product for best performance. Do not assume cosine, L2, and inner product produce identical rankings in every setup; validate with the model’s intended similarity behavior and your own queries. The pgvector documentation describes the operators and index classes.

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

Start with exact search, then choose an index by measurement

pgvector performs exact nearest-neighbor search by default, which provides perfect recall. This is a useful baseline: it returns the true nearest rows according to the chosen metric, without the recall tradeoff of approximate search. Measure query latency and result quality on representative data before adding an approximate index.

HNSW and IVFFlat can reduce search work, but may return different results from exact search. Compare approximate results with the exact baseline and evaluate latency, recall, index build duration, memory and storage use, write/update cost, and behavior under the filters your application actually applies. There is no universal setting that documentation alone can establish for your workload.

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.
Approach What to expect Build and tuning considerations
Exact search Perfect recall relative to the selected vector metric; a useful correctness baseline. No approximate index is required. Measure query latency as data and traffic grow.
HNSW Approximate search with a favorable speed/recall tradeoff, but it uses more memory and takes longer to build than IVFFlat in pgvector’s comparison. Can be created before data is loaded because it has no training step. Tune construction and search settings against measured recall and latency.
IVFFlat Approximate search with a different speed/recall tradeoff from HNSW. Uses lists and requires a training step; pgvector advises creating it after data is loaded. Tune lists and probes for the target workload.

Create an HNSW index

For cosine distance, the basic index form is:

CREATE INDEX document_chunks_embedding_hnsw
ON document_chunks
USING hnsw (embedding vector_cosine_ops);

Choose the operator class to match the query metric: cosine, L2, or inner product. HNSW’s m controls graph connections, while ef_construction controls the candidate list during index construction. Higher construction effort can improve recall while increasing build time and insert cost. At query time, hnsw.ef_search controls the candidate list size; increasing it generally spends more work to improve recall.

Consider IVFFlat when it fits the workload

IVFFlat partitions vectors into lists and searches a selected number of them. Its lists and ivfflat.probes settings are tuning controls; more probes generally spend more work and can improve recall. Create the index after representative data has been loaded, as its setup requires training. Benchmark it against HNSW and exact search rather than assuming one index is always best.

Managed services may document their own defaults and supported extension versions. For example, Google Cloud’s Cloud SQL guide discusses HNSW parameters in its Cloud SQL context. Check the exact pgvector and PostgreSQL versions and service guidance for your deployment before copying defaults.

Test metadata filters separately

A vector index may find nearest neighbors first and apply metadata filters afterward. With a selective filter, this can leave fewer rows than requested even when matching records exist. pgvector documents iterative index scans as a mitigation. Test recall and result counts under your actual filters—for example, tenant, language, status, or date—not just on unfiltered queries. If filtered searches remain weak, compare iterative scans and exact search for the affected query patterns.

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

Combine semantic search with full-text search when terms must match

Vector similarity is useful for conceptual matches, but can miss an exact identifier, quoted phrase, or rare proper noun. PostgreSQL full-text search represents documents and queries with tsvector and tsquery; PostgreSQL identifies GIN as the preferred full-text index type. See the PostgreSQL 16 full-text index documentation.

For applications that need both conceptual relevance and literal-term recall, combine vector and full-text results. The pgvector project recommends approaches such as reciprocal rank fusion or a cross-encoder to combine or rerank results. The choice depends on whether your content needs exact lexical matches, semantic similarity, or higher-quality reranking—and on the added implementation and compute cost.

Deploy and operate the feature safely

  • Use migrations: manage extension, table, and index changes through your normal schema migration process rather than ad hoc production edits.
  • Control data access: if a Supabase-generated REST API exposes the table, configure row-level security and policies deliberately. The Cookbook example enables RLS to prevent unauthorized access through the generated API.
  • Protect credentials: keep embedding API keys in environment or secret-management systems, not source code or SQL data.
  • Plan model transitions: record model and dimension settings, then re-embed affected text before comparing its new vectors with query vectors from the same configuration.
  • Monitor retrieval quality: maintain a representative set of queries and compare result relevance, counts, latency, and approximate recall after changes to data, filters, models, or index settings.

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.