Building a RAG application with Llama 3.1 and pgvector
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. The walkthrough enables the vector extension, creates a table with a VECTOR(1024) column, and embeds and inserts a CSV of fake quotes from Python via psycopg2. At query time it embeds the user input, retrieves the two nearest quotes with a cosine-distance ORDER BY ... LIMIT 2 query, and injects them into the system prompt. Embedding dimension directly drives storage cost, e.g. 1024 for gte-large versus up to 3072 for OpenAI's model.
Related posts
- Storing OpenAI embeddings in Postgres with pgvector
Supabase mediumAdeptpgvector 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. The walkthrough creates a documents table, a match_documents SQL function that filters by a cosine-similarity threshold, and an IVFFlat index sized at roughly 4 * sqrt(rows) lists. It then generates embeddings in JavaScript and builds Deno Edge Functions for semantic search and for retrieval-augmented answers with text-davinci-003, keeping injected context under about 1500 tokens to fit the 4000-token limit.
- Building Data-Aware AI Applications with Heroku AI and LlamaIndex
Heroku Engineering mediumAdeptA RAG stack on Heroku pairs LlamaIndex for ingestion, indexing and retrieval with Heroku Managed Inference (Claude 4 Sonnet via an OpenAI-compatible API), Cohere Embed Multilingual for embeddings, and Heroku Postgres with pgvector as the vector store. The walkthrough provisions the add-ons via the Heroku CLI. It then shows Python code that points LlamaIndex's OpenAILikeEmbedding at Heroku's embedding endpoint, stores 1024-dimension vectors in PGVectorStore, and queries documents through a query engine. Example use cases include financial report analysis, insurance claim agents and support chatbots.
- Build an end-to-end RAG pipeline entirely in psql using pgrag and DeepSeek
Neon mediumAdept
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.
- ChatGPT plugins now support Postgres & Supabase
Supabase mediumAdeptSupabase contributed Postgres and Supabase datastore providers to OpenAI's ChatGPT Retrieval Plugin, storing text-embedding-ada-002 embeddings in pgvector. The Postgres provider connects directly via psycopg2, while the Supabase provider goes through PostgREST to enable Row Level Security. Both share the same documents schema and use a plpgsql match function that filters by source, author and date and ranks results by inner product distance. A walkthrough ingests the PostgreSQL 15 docs (about 7,904 chunks), adds an approximate ivfflat index with lists ≈ rows/1000, and registers the local plugin with ChatGPT to answer documentation questions.
- Easy Embeddings Indexing Pipelines with Redpanda and Neon
Neon mediumAdept
An embeddings indexing pipeline can be built from configuration alone with Redpanda Connect: it consumes e-commerce invoice messages from a Redpanda Serverless topic over SASL/TLS, builds a text description of each order with Bloblang, computes embeddings locally via Ollama's nomic-embed-text model, and flattens items into separate messages before writing them to Neon Postgres with pgvector for natural-language search. The whole setup is a few dozen lines of YAML, and Redpanda serves as a Kafka-compatible buffer that absorbs traffic spikes. Note that the Step 4 output config shown duplicates the processor config, so the actual Postgres sink settings are missing.