🗄️ Vector Databases
🎯 Mục tiêu bài học
Sau bài học này, bạn sẽ:
✅ Hiểu Vector Database là gì và vai trò trong RAG
✅ So sánh các Vector DB phổ biến: Pinecone, Supabase, Qdrant, ChromaDB
✅ Biết cách setup Pinecone, Supabase pgvector, và Qdrant
✅ Nắm cách sử dụng Embeddings nodes trong n8n
✅ Thực hành index documents và similarity search
Vector databases lưu trữ embeddings và cho phép similarity search — trái tim của mọi RAG system.
🔍 Vector DB là gì?
Checkpoint
Vector Database lưu trữ gì và cho phép thao tác gì? Mô tả flow từ text đến search results.
📊 So sánh Vector Databases
| Feature | Pinecone | Supabase | Qdrant | Chroma |
|---|---|---|---|---|
| Hosting | Cloud | Cloud/Self | Cloud/Self | Self |
| Free tier | 100K vectors | 500MB | 1GB | Unlimited |
| n8n support | Native | Native | Native | Community |
| Setup | Easy | Easy | Medium | Easy |
| Best for | Production | Full-stack | Advanced | Local dev |
Checkpoint
So sánh Pinecone, Supabase, Qdrant, ChromaDB về hosting, free tier, và best use case.
🌲 Pinecone Setup
Step 1: Create Index
- Đăng ký tại pinecone.io
- Create new index
- Dimension: 1536 (for OpenAI embeddings)
- Metric: cosine
- Copy API key
Step 2: n8n Credential
- n8n Settings, Credentials
- Add "Pinecone" credential
- Paste API key
- Test connection
Step 3: Index Documents
1// Workflow: Index documents to Pinecone2// Node 1: Read documents (Google Drive, HTTP, File)3// Node 2: Text Splitter (Recursive Character)4// Node 3: Embeddings (OpenAI)5// Node 4: Pinecone Vector Store (Insert)67// Pinecone node configuration:8// - Operation: Upsert9// - Index: your-index-name10// - Namespace: "documents"Checkpoint
Liệt kê 3 bước setup Pinecone trong n8n. Dimension và metric cần chọn cho OpenAI embeddings là gì?
🗄️ Supabase Vector Store
Setup pgvector
1-- Enable pgvector extension2create extension if not exists vector;34-- Create documents table5create table documents (6 id bigserial primary key,7 content text,8 metadata jsonb,9 embedding vector(1536)10);1112-- Create similarity search function13create or replace function match_documents (14 query_embedding vector(1536),15 match_threshold float,16 match_count int17)18returns table (19 id bigint,20 content text,21 metadata jsonb,22 similarity float23)24language sql stable25as $$26 select27 documents.id,28 documents.content,29 documents.metadata,30 1 - (documents.embedding <=> query_embedding) as similarity31 from documents32 where 1 - (documents.embedding <=> query_embedding) > match_threshold33 order by similarity desc34 limit match_count;35$$;n8n Integration
1// Supabase Vector Store node in n8n2// Operation: Insert Documents3// Table: documents4// Content Column: content5// Embedding Column: embedding6// Metadata Columns: metadataCheckpoint
Cần tạo những gì trong Supabase để setup pgvector? (extension, table, function)
⚙️ Qdrant Setup
1// Docker compose for Qdrant2// docker-compose.yml:3// services:4// qdrant:5// image: qdrant/qdrant6// ports:7// - "6333:6333"8// volumes:9// - qdrant_data:/qdrant/storage1011// n8n Qdrant credential:12// - URL: http://localhost:633313// - API Key: (optional for local)1415// Create collection via HTTP Request node:16const createCollection = {17 url: "http://qdrant:6333/collections/my-docs",18 method: "PUT",19 body: {20 vectors: {21 size: 1536,22 distance: "Cosine"23 }24 }25};Checkpoint
Mô tả cách deploy Qdrant với Docker và kết nối từ n8n.
🧬 Embeddings trong n8n
| Model | Dimensions | Cost per 1M tokens | Quality |
|---|---|---|---|
| text-embedding-3-small | 1536 | $0.02 | Good |
| text-embedding-3-large | 3072 | $0.13 | Best |
| Cohere embed-v3 | 1024 | $0.10 | Good |
Dùng text-embedding-3-small cho hầu hết use cases. Chi phí thấp, chất lượng tốt. Chỉ upgrade lên large khi cần precision cao.
Checkpoint
So sánh text-embedding-3-small và text-embedding-3-large. Khi nào nên upgrade lên large?
📝 Bài tập thực hành
- Setup Pinecone free tier, tạo index, connect từ n8n
- Hoặc setup Supabase pgvector, tạo table và function
- Index 5-10 sample documents
- Test similarity search với vài queries
Checkpoint
Bạn cần hoàn thành những exercises nào trong bài này?
🚀 Bài tiếp theo
n8n Vector Store Nodes → — Hướng dẫn chi tiết sử dụng Vector Store nodes trong n8n.
