Concept · Builds on AIF-C01
Aurora and RDS PostgreSQL with pgvector
Vectors in PostgreSQL: column, HNSW or IVFFlat index, distance operators, one query with filters.
You know from AI Practitioner
- Aurora PostgreSQL can store vectors next to your rows.
- It answers vector search with SQL.
- OpenSearch is the separate option built for search at scale.
- 1The application sends one SQL statement.
- 2It names a distance operator and an optional filter.
- 3Aurora applies the filter on normal columns.
- 4It ranks the remaining rows by vector distance.
Step by step
- 1The application sends one SQL statement.
- 2It names a distance operator and an optional filter.
- 3Aurora applies the filter on normal columns.
- 4It ranks the remaining rows by vector distance.
One SQL query filters rows and ranks by distance.
Build
- HNSW
- Slower, no training
- IVFFlat
- Faster, after data load
Recall
- HNSW
- Better
- IVFFlat
- Good, tune probes
Memory
- HNSW
- Higher
- IVFFlat
- Lower
Query setting
- HNSW
- hnsw.ef_search
- IVFFlat
- ivfflat.probes
| Compare | HNSW | IVFFlat |
|---|---|---|
| Build | Slower, no training | Faster, after data load |
| Recall | Better | Good, tune probes |
| Memory | Higher | Lower |
| Query setting | hnsw.ef_search | ivfflat.probes |
What it is
Turn it on with CREATE EXTENSION vector. Then add a column of type vector(n), where n is the model output size, for example vector(1024). Distance operators are <-> for L2 distance, <=> for cosine distance and <#> for negative inner product. An ORDER BY with the operator and a LIMIT returns the nearest rows. Without an index the search scans every row: exact, but slow on large tables.
What it is
Two index types make it approximate and fast. HNSW builds a graph: slower to build and heavier on memory, with better recall and speed, no training needed, and a tuning knob at query time (hnsw.ef_search). IVFFlat splits vectors into lists: faster to build and lighter, but build it after the table has data, and raise the probes setting at query time for better recall. Indexes cover vectors of up to 2,000 dimensions.
What it is
The strength is one query over vectors and ordinary columns: WHERE tenant_id = 7 AND created_at > ... ORDER BY embedding <=> query LIMIT 5. A selective filter can leave an approximate index with fewer results than the limit, and newer pgvector versions add iterative scans to fix that. Choose pgvector when vectors belong with relational data, the scale is moderate and you already run PostgreSQL. Choose a separate store for very large or search-heavy loads.
Remember
- CREATE EXTENSION vector, then a vector(n) column. n must match the model.
- Operators: <-> L2, <=> cosine, <#> negative inner product.
- HNSW: better recall, slower build, more memory. IVFFlat: faster build, build after loading data.
- Indexes cover up to 2,000 dimensions.
- One SQL query can filter relational columns and rank by distance.
Remember
- Selective filters can return fewer than k rows from an approximate index.
On the exam
- “Find similar items and filter by tenant in one SQL statement” points to pgvector in Aurora PostgreSQL.
- “Better recall with no training step” points to an HNSW index.
- “Faster index build on loaded data with lower memory” points to IVFFlat.
In this task · 1.1
- S3 as the ML data lake
- Choosing storage: S3, EFS, EBS, FSx and transfer tools
- Extracting data from databases and search
- Data formats: Parquet, ORC, Avro, CSV, JSON, RecordIO
Kinesis Data Streams
Firehose
Managed Flink
MSK
- Troubleshooting ingestion and storage capacity
Catalog and Lake Formation
- Merging data from multiple sources
- Choosing and configuring a vector store
OpenSearch
- Aurora and RDS PostgreSQL with pgvector
- Ingesting text, image, audio and video
- Ingesting data into SageMaker Feature Store