Build a Personalized AI Assistant with Postgres
A personal AI assistant with long-term memory can be built on Postgres by giving the LLM an execute_sql tool scoped to a dedicated `memories` schema and role, so it creates its own tables for structured facts. Memory has three layers: recent message history, pgvector embeddings for fuzzy recall, and LLM-created SQL tables for precise queries. pg_cron and pg_net run scheduled prompts through the same Edge Functions, so the assistant can act on its own. It also uses OpenAI web search, Zapier MCP for external actions, Telegram as the interface, and a versioned, user-editable personality prompt. The setup guide covers migrations, Edge Functions and environment variables, and estimates about $0.54/month at 10 messages a day on GPT-4.1-mini.
Related posts
- Building an AI-powered ChatBot using Vercel, OpenAI, and Postgres
Neon mediumAdept
A ChatGPT-style documentation assistant (Ask Neon) is built by storing OpenAI text-embedding-ada-002 vectors in Postgres with pgvector, retrieving context by cosine distance, and feeding it to text-davinci-003 from a Vercel Edge Function. A window-function query caps retrieved context at a cumulative 1,500 tokens to fit the 4,096-token model limit, and an ivfflat index (lists ≈ 4·sqrt(rows)) speeds up the similarity search. Neon's WebSocket-based serverless driver works around Edge Functions' lack of TCP, and streaming completions via SSE parsing return answers faster. User feedback is stored for later fine-tuning.
- Web-based AI SQL Playground and connecting to Postgres from the browser
Neon mediumAdept
Neon's Postgres AI Playground connects to a Postgres database directly from the browser and uses OpenAI's gpt-3.5-turbo to turn natural-language prompts into SQL. Browsers can't open TCP connections, so the Neon serverless driver tunnels the Postgres wire protocol through a WebSocket-to-TCP proxy. The proxy is open source and can be self-hosted to reach other Postgres providers. A Vercel edge function rate-limits requests with Upstash Redis, injects the user's schema (pulled from information_schema.columns and flattened to a compact text form) into the prompt, and streams the model's response back to the editor.
- database.build v2: Bring-your-own-LLM
Supabase mediumAdeptdatabase.build, Supabase's in-browser Postgres sandbox built on PGlite, now lets users bring any OpenAI-compatible LLM, with no login and no rate limits. Requests go straight from the browser to the provider. This works because most LLM APIs send CORS headers, and a service worker intercepts the Vercel AI SDK's /api/chat route, reading its BYO-LLM config from IndexedDB. Models need reliable tool calling, SQL knowledge and Chart.js knowledge, so gpt-4o is recommended; local Ollama models still struggle with tool calls, and Ollama buffers tool-call streams. The release also adds one-click deploys to Supabase by piping server-side pg_dump over Live Share into pg_restore, and replaces the tar.gz export with a WASM pg_dump. Serverless PGlite was shelved because of its memory use and single-connection limit in multi-tenant setups and unreliable s3fs storage.
- Building a Deep Research Agent with Neon and Durable Endpoints
Neon mediumAdept
A recursive deep research agent built on Neon Postgres with pgvector, Inngest durable endpoints, Claude, Exa search and OpenAI embeddings. Planning, search, reflection and report generation from the DeepResearcher and Step-DeepResearch papers map onto concrete LLM functions, with depth-limited recursion that halves breadth at each level. Every external call runs as a retriable, memoized Inngest step with deterministic IDs. Idempotent Postgres writes (ON CONFLICT DO NOTHING, UNIQUE constraints) make replays safe. One database holds sessions, cursor-polled progress events and embeddings, so past learnings can be recalled via cosine distance to inform new searches.
- Building a GPT Backed by a Heroku-Deployed API
Heroku Engineering mediumAdeptA custom OpenAI GPT can be backed by a simple Express API on Heroku that answers natural-language questions about an employee directory. The API makes two Chat Completions calls: one turns the user's question into a PostgreSQL query using the table schema in a system prompt and JSON response format, and a second turns the returned rows into a readable answer, resending the schema because the models keep no memory between requests. The walkthrough covers bearer-token auth, environment configuration, local curl testing, Heroku deployment with Postgres, and configuring the GPT action. It also warns that all data leaves Heroku's trust boundary to reach OpenAI.