---
title: "Semantic search using OpenAI, pg_embedding and Neon"
description: "A YC idea-matcher app implements semantic search by embedding ~4,400 YCombinator company descriptions with OpenAI's text-embedding-ada-002 (1536 dimensions) and storing them as real[] columns in Neon Postgres via the pg_embedding extension."
url: "https://swe.quest/articles/semantic-search-using-openai-pg-embedding-and-neon-aeafbc27d93ca728"
canonical: "https://neon.com/blog/semantic-search"
source: "Neon"
published: "2023-08-25"
difficulty: "medium"
kind: "How-to"
reading_minutes: 9
tags: ["vector-search","postgres","llms","serverless","typescript"]
---

# Semantic search using OpenAI, pg\_embedding and Neon

A post on [Neon](https://swe.quest/sources/neon.md), published 2023-08-25, 9 min read, How-to. Original: [https://neon.com/blog/semantic-search](https://neon.com/blog/semantic-search)

## Summary

A YC idea-matcher app implements semantic search by embedding ~4,400 YCombinator company descriptions with OpenAI's text-embedding-ada-002 (1536 dimensions) and storing them as real\[\] columns in Neon Postgres via the pg\_embedding extension. Queries embed the user's idea and order rows by cosine distance (\<=\>) to return the top five matches from a Next.js edge function, which is colocated with the database region and uses the Neon serverless driver, Upstash rate limiting and Zod validation. The full ingestion script and API route are shown. Sequential scan is fine for this small dataset, but larger tables need an HNSW index. pg\_embedding has since been deprecated in favor of pgvector.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Vector search](https://swe.quest/tags/vector-search.md) (Data & databases)
- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [LLMs](https://swe.quest/tags/llms.md) (AI & ML)
- [Serverless](https://swe.quest/tags/serverless.md) (Backend & APIs)
- [TypeScript](https://swe.quest/tags/typescript.md) (Languages)

## Prerequisites

- Postgres basics ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- Node.js/TypeScript ([easy posts on JavaScript](https://swe.quest/tags/javascript.md?difficulty=easy))
- REST APIs ([easy posts on API design](https://swe.quest/tags/api-design.md?difficulty=easy))

## Keywords

pg\_embedding, pgvector, Neon, OpenAI Embeddings API, text-embedding-ada-002, Next.js, Upstash, HNSW

## Related posts

- [Storing OpenAI embeddings in Postgres with pgvector](https://swe.quest/articles/storing-openai-embeddings-in-postgres-with-pgvector-19a5d03614f86fc6.md): Supabase · 2023-02-06 · Medium · 11 min read · Vector search, PostgreSQL, RAG & retrieval, LLMs
  pgvector adds a vector data type and distance operators (Euclidean \<-\>, negative inner product \<#\>, cosine \<=\>) to Postgres, so OpenAI text-embedding-ada-002 embeddings (1536 dimensions) can be stored and queried for similarity directly in the database.
- [Neon Docs search is now built on Neon](https://swe.quest/articles/neon-docs-search-is-now-built-on-neon-6358bcc8a0cf6214.md): Neon · 2026-10-26 · Medium · 6 min read · Search, PostgreSQL, Vector search, Caching, AI agents
  Neon's docs search now runs entirely on its own stack: Lakebase Postgres with the lakebase\_vector (pgvector-compatible ANN) and lakebase\_text (BM25) extensions, a Hono API on Neon Functions, and Neon AI Gateway for embeddings and reranking.
- [In-Browser Semantic AI Search with PGlite and Transformers.js](https://swe.quest/articles/in-browser-semantic-ai-search-with-pglite-and-transformers-js-f90228d6e99e01b6.md): Supabase · 2024-08-29 · Medium · 7 min read · Vector search, PostgreSQL, Browsers, JavaScript, React
  A fully local, in-browser semantic search can be built by combining PGlite (Postgres compiled to run in the browser, persisted to IndexedDB) with the pgvector extension and Transformers.js running the Supabase/gte-small embedding model.
- [Search From a Million Books in Milliseconds With Neon and pg\_search](https://swe.quest/articles/search-from-a-million-books-in-milliseconds-with-neon-and-pg-search-2b2bd7a3bf8b0ad8.md): Neon · 2025-03-26 · Medium · 6 min read · PostgreSQL, Search, Performance engineering
  Swapping the OpenAI-embedding semantic search in Vercel's Next.js Book Inventory template for pg\_search's BM25 full-text index on Neon Postgres made title searches over a million Goodreads books roughly 180–236x faster, dropping from about 2.7 seconds to 11–14 ms. The setup loads the dataset into a books table, prewarms the table and index with pg\_prewarm, creates a covering bm25 index, and queries with the @@@ operator and paradedb.match in conjunction\_mode.
- [Building a RAG application with Llama 3.1 and pgvector](https://swe.quest/articles/building-a-rag-application-with-llama-3-1-and-pgvector-aa7660e0eb99da02.md): Neon · 2024-07-30 · Medium · 12 min read · RAG & retrieval, Vector search, PostgreSQL, LLMs, Python
  A small RAG pipeline built on Neon Postgres with pgvector as the vector store, OctoAI's gte-large embedding model producing 1024-dimensional vectors, and Llama 3.1 405B generating answers.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
