惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
Martin Fowler
Martin Fowler
The GitHub Blog
The GitHub Blog
B
Blog RSS Feed
U
Unit 42
阮一峰的网络日志
阮一峰的网络日志
量子位
GbyAI
GbyAI
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
云风的 BLOG
云风的 BLOG
小众软件
小众软件
博客园 - 三生石上(FineUI控件)
L
LangChain Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园_首页
IT之家
IT之家
V
Visual Studio Blog
Y
Y Combinator Blog
Blog — PlanetScale
Blog — PlanetScale
宝玉的分享
宝玉的分享
Apple Machine Learning Research
Apple Machine Learning Research
I
InfoQ
D
Docker
V
V2EX

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Building a RAG System from Scratch — Wrap-up and What Com...
Hiroki Kameyama · 2026-06-28 · via DEV Community

In this final article, we'll recap what we built across the series, consolidate the design decisions, and point to where to go next.


What We Built

Starting from a blank Python project, we built a complete AI system step by step:

01_setup_db.py       pgvector table + extension
02_create_index.py   HNSW index (m=16, ef_construction=64)
03_ingest.py         Embed documents → store in pgvector
04_search.py         Cosine similarity search
05_rag.py            Full RAG pipeline

06_tool_basic.py     LLM decides whether to search
07_tool_multi.py     LLM routes between multiple tools
08_tool_agent.py     Multi-step agentic loop

09_agent_basic.py    ReAct pattern
10_agent_memory.py   Persistent memory across sessions
11_agent_planner.py  Plan → Execute → Evaluate

mcp_server/
  server.py          MCP server (stdio, Claude Desktop)
  server_http.py     MCP server (HTTP)
  server_render.py   MCP server (Render deployment)

12_mcp_agent.py      Agent via MCP (local)
13_mcp_http_agent.py Agent via MCP (cloud)


Design Decisions at a Glance

pgvector over a dedicated vector DB

pgvector integrates with existing PostgreSQL, supports SQL + vector in one query, and handles millions of documents comfortably. Start here and migrate only when you have evidence you need to.

768 dimensions

gemini-embedding-001 outputs 3072 dims by default, but pgvector's HNSW index has a 2000-dim hard limit. 768 dims stays well within bounds with negligible quality loss.

Asymmetric task_type

Use RETRIEVAL_DOCUMENT when storing, RETRIEVAL_QUERY when searching. The Gemini embedding model is trained to map queries toward documents, not to the same point. Using the same task type for both degrades retrieval accuracy.

HNSW over IVFFlat

HNSW requires no training data, delivers consistent recall at scale, and is faster at query time. IVFFlat is only worth considering under tight memory constraints.

Tool description is routing logic

The LLM selects tools based on their description field. Precise, distinguishing descriptions produce correct tool selection. Vague descriptions produce random behavior.

The conversation history is the agent's memory

Each tool call and result gets appended to contents. The LLM reads the full history on every step — this is how multi-step reasoning works.

MCP makes tools infrastructure

MCP turns hardcoded functions into a standalone server. Claude Desktop, Gemini agents, and any future client can connect to the same server without duplicating tool definitions.

Render + Supabase for zero-cost cloud deployment

Render's free web service hosts the MCP server. Supabase's free tier hosts pgvector. The Connection Pooler (port 6543) is mandatory — Render doesn't support the IPv6 used by Supabase's standard port 5432.


The Architecture We Ended Up With

Local:
  Claude Desktop
      ↓ stdio
  mcp_server/server.py
      ↓ psycopg2
  pgvector (Docker)

Cloud:
  Python agent (13_mcp_http_agent.py)
      ↓ HTTPS
  Render (server_render.py)
      ↓ PostgreSQL + SSL (port 6543)
  Supabase (pgvector)
      ↓
  Gemini Embedding + LLM


What This Series Did Not Cover

This series focused on getting a production-ready RAG system off the ground. Several important topics are out of scope here:

Evaluation (Evals) — How do you know if your RAG is actually working? You need automated quality measurement: Context Recall, Answer Relevancy, and Faithfulness scoring.

Observability — When something goes wrong in production, how do you debug it? Tracing each step with a tool like Langfuse tells you exactly where latency or quality issues originate.

Security — How do you handle adversarial inputs? Prompt injection, jailbreaks, and PII leakage are real threats in any public-facing RAG system.

MLOps / LLMOps — How do you ship changes safely? Prompt versioning, CI/CD quality gates, and API cost tracking become essential when the system is in production.

Fine-tuning — When the base model doesn't behave the way you need, LoRA fine-tuning lets you adapt it to your domain with surprisingly little data and compute.

Multi-Agent Systems — When a single agent isn't enough, orchestrator-worker patterns distribute work across specialized agents.

Governance — The EU AI Act is now fully in force. Compliance for a chatbot system means AI disclosure notices, audit logging, and a documented risk assessment.

All of these are covered in Vol.2 of this series.


Vol.2: Production Operations Guide

The second series picks up where this one leaves off — taking a working RAG system and making it production-grade.

AI Production Operations Guide (Japanese — English Dev.to series coming soon)

Chapter Topic
1 What "production" actually means
2 Evals — automated quality measurement
3 Observability with Langfuse v4
4 Security — guardrails and prompt injection defense
5 MLOps / LLMOps — CI/CD pipeline
6 Fine-tuning with LoRA
7 Multi-Agent: orchestrator-worker pattern
8 Governance — EU AI Act compliance
9 Wrap-up

Source Code

Everything built in this series is in one repository:

github.com/qameqame/pgvector-tutorial

The README covers setup, directory structure, and the reasoning behind each design decision.


Series Index

  1. Introduction
  2. RAG · Embedding · Vector DB Implementation
  3. Design Decisions Explained
  4. Tool Use — Autonomous Search
  5. AI Agents — Memory and Planning
  6. MCP — Reusable Tool Server
  7. Cloud Deployment — Render × Supabase
  8. Wrap-up and Next Steps (this article)

Thanks for following along. If you found this useful, the GitHub repo and Vol.2 are the best places to continue.