---
title: "Build an end-to-end RAG pipeline entirely in psql using pgrag and DeepSeek"
description: "pgrag, Neon's open-source Postgres extension, lets you build a complete RAG pipeline inside psql."
url: "https://swe.quest/articles/build-an-end-to-end-rag-pipeline-entirely-in-psql-using-pgrag-and-deepseek-250dc9ab3281f7d0"
canonical: "https://neon.com/blog/pgrag-and-deepseek"
source: "Neon"
published: "2025-01-30"
difficulty: "medium"
kind: "How-to"
reading_minutes: 9
tags: ["rag","postgres","vector-search","llms"]
---

# Build an end-to-end RAG pipeline entirely in psql using pgrag and DeepSeek

A post on [Neon](https://swe.quest/sources/neon.md), published 2025-01-30, 9 min read, How-to. Original: [https://neon.com/blog/pgrag-and-deepseek](https://neon.com/blog/pgrag-and-deepseek)

## Summary

pgrag, Neon's open-source Postgres extension, lets you build a complete RAG pipeline inside psql. It provides SQL functions for PDF/DOCX/HTML text extraction, character- or token-based chunking, local CPU embeddings (bge-small-en-v1.5) and reranking (jina-reranker-v1-tiny), plus API calls to OpenAI, Voyage, Anthropic and Fireworks. Paired with pgvector HNSW indexes, a worked example indexes PGConf EU 2023 slides. A single query then retrieves the top 10 chunks, reranks them to 5, and prompts DeepSeek V3, which correctly declines out-of-scope questions. The local models ship as separate ~100MB extensions, and on Neon they need around 2GB RAM of compute.

Written by swe.quest, not by the author.

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

## Topics

- [RAG & retrieval](https://swe.quest/tags/rag.md) (AI & ML)
- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Vector search](https://swe.quest/tags/vector-search.md) (Data & databases)
- [LLMs](https://swe.quest/tags/llms.md) (AI & ML)

## Prerequisites

- SQL and psql ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))
- vector embeddings basics ([easy posts on RAG & retrieval](https://swe.quest/tags/rag.md?difficulty=easy))
- pgvector

## Keywords

pgrag, pgvector, DeepSeek V3, Neon, Fireworks AI, bge-small-en-v1.5, jina-reranker-v1-tiny-en, HNSW

## Related posts

- [ChatGPT plugins now support Postgres & Supabase](https://swe.quest/articles/chatgpt-plugins-now-support-postgres-supabase-db9d10a95a8d96b9.md): Supabase · 2023-05-25 · Medium · 7 min read · RAG & retrieval, Vector search, PostgreSQL, LLMs
  Supabase contributed Postgres and Supabase datastore providers to OpenAI's ChatGPT Retrieval Plugin, storing text-embedding-ada-002 embeddings in pgvector.
- [Building AI Search on Heroku](https://swe.quest/articles/building-ai-search-on-heroku-fdce052b7ed2fc31.md): Heroku Engineering · 2026-01-29 · Medium · 3 min read · RAG & retrieval, Vector search, PostgreSQL, Search, LLMs
  A reference RAG architecture on Heroku pairs pgvector cosine-similarity search (top 20 chunks) with a cross-encoder reranker (Cohere Rerank 3.5, top 5), so answers come from documents that actually address the query rather than ones that are merely semantically close.
- [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.
- [CommSync Runs Text, Vector, and Hybrid Search on Postgres with Lakebase Search](https://swe.quest/articles/commsync-runs-text-vector-and-hybrid-search-on-postgres-with-lakebase-search-8b687b59899ef5ac.md): Neon · 2026-07-30 · Medium · 5 min read · Search, PostgreSQL, Vector search, RAG & retrieval
  CommSync, a unified SMS/email inbox, runs keyword, semantic and hybrid search entirely in Postgres using Neon's Lakebase Search extensions. lakebase\_text provides BM25 search with top-K pushdown over tsvector, and lakebase\_vector is a pgvector-compatible drop-in with an ANN index.
- [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.

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)
