Building Vector Stores and Indexes for Semantic Search
This lesson explains how vector search finds items with similar meaning by comparing embeddings, powering semantic search and retrieval augmented generation (RAG), and the pipelines data engineers build to feed it.
Learning outcomes
After completing this lesson, you will be able to:
- Explain how embeddings and similarity measures work.
- Identify the vector stores available on AWS.
- Choose between HNSW and IVF indexes.
- Build vector pipelines with Bedrock Knowledge Bases or custom jobs.
Embeddings and similarity
Embeddings are numeric vectors, produced by models such as Amazon Titan Text Embeddings on Bedrock, that represent meaning. Similar items lie close together, measured by cosine similarity, Euclidean (L2) distance or the inner (dot) product.
Embeddings
Vector stores on AWS
A vector store holds embeddings, numeric representations of text or images, and finds the ones most similar to a query. AWS offers several. Aurora PostgreSQL and RDS for PostgreSQL with the pgvector extension keep vectors in the same database as the relational data they describe, queried with SQL, which suits applications already using PostgreSQL. OpenSearch Service k-NN indexes and OpenSearch Serverless vector collections handle search at large scale, including hybrid search that combines keywords with vector similarity.
Amazon MemoryDB provides durable, in-memory vector search with single-digit millisecond latency. Amazon S3 Vectors stores very large numbers of vectors at low cost, for workloads that can accept slower queries. Neptune Analytics combines graph queries with vectors, and DocumentDB adds vector search to document data. The following table summarises the stores.
| Store | Best for |
|---|---|
| Aurora PostgreSQL / RDS for PostgreSQL with pgvector | Vectors next to relational data, queried with SQL |
| OpenSearch Service k-NN, OpenSearch Serverless vector collections | Search at scale, including hybrid keyword and vector search |
| Amazon MemoryDB | Durable in-memory search with very low latency |
| Amazon S3 Vectors | Low-cost storage of huge numbers of vectors |
| Neptune Analytics, DocumentDB | Graph plus vectors; document data |
Vector stores
HNSW vs IVF indexes
Comparing a query with every stored vector is exact but too slow for millions of vectors, so stores use indexes that find close matches quickly. HNSW (hierarchical navigable small world) builds a multi-layer graph linking each vector to its neighbours; a search starts in the sparse top layer and moves closer to the query layer by layer. It gives high recall and fast queries and handles new inserts well, but uses more memory and takes longer to build.
IVF (inverted file index), called IVFFlat in pgvector, groups vectors into clusters, called lists, and searches only the lists nearest the query; the probes setting decides how many. It uses less memory and builds faster, but its accuracy depends on the lists and probes chosen, and it may need rebuilding as data changes, because the clusters were based on the original data. The following table summarises the differences.
Both are approximate nearest neighbour (ANN) methods that trade a little accuracy for speed; exact search compares every vector.
The following diagram shows how each index type finds near neighbours.

HNSW or IVF?
Building vector pipelines
Vector data can be prepared by a managed pipeline or a custom one. Amazon Bedrock Knowledge Bases automate the whole process: they read documents from a data source, split them into chunks, generate embeddings, store them in a vector store and keep the store synchronised with the source, which suits most retrieval applications.
Custom pipelines, built with AWS Glue or Lambda, chunk and embed data themselves and add metadata, such as product, date or access level, that searches can filter on. They suit data that needs unusual processing, data from sources without a connector, or pipelines that must fit into existing data engineering workflows.
The following diagram shows the indexing and query paths of a vector search pipeline for support articles.

Managed or custom vector pipeline?
Building a vector pipeline for search
A company wants semantic search over 2 million support articles that change daily.
| Step | Service |
|---|---|
| Split articles into chunks | A Glue or Lambda job |
| Create an embedding for each chunk | Amazon Titan Text Embeddings through Amazon Bedrock |
| Store vectors with metadata | OpenSearch Service (HNSW index), Aurora PostgreSQL with pgvector, or S3 Vectors for lowest cost |
| Keep in sync with article changes | Process only changed articles, triggered by events |
| Query | Embed the user's question and find the nearest vectors |
HNSW indexes give fast, accurate search at higher memory cost; IVF indexes use less memory but need training and can be less accurate. If the articles already live in Aurora, pgvector keeps vectors next to the relational data with no new database to run.
Where can vectors be stored alongside existing relational data?
Show answer
In Aurora or RDS for PostgreSQL with the pgvector extension.
Exam Tips
Remember for the exam
- To store vectors alongside existing relational data, use Aurora or RDS for PostgreSQL with pgvector.
- For the best recall and query speed choose HNSW; for lower memory use and faster builds choose IVF.
- For durable, very low-latency in-memory vector search, use MemoryDB.
- The lowest-cost storage for huge numbers of vectors is S3 Vectors.
- For managed chunking, embedding and storage for RAG, use Bedrock Knowledge Bases.