🎯 Slide 1 — Title: DB Evolution Tutorial

Say this:

Welcome everyone to the Database Evolution Tutorial! Today, we’ll walk through how data storage has evolved from traditional relational databases to NoSQL and finally to vector databases — the foundation of AI-powered search. We’ll be using a single Docker Compose setup that ties together SQLite, Redis, and PostgreSQL with pgvector, all managed through a FastAPI backend.


🧩 Slide 2 — Why This Tutorial?

Say this:

Every type of database solves a different kind of problem.


🧱 Slide 3 — Relational DB: SQLite

Say this:

Let’s begin with SQLite — a lightweight, file-based relational database. It follows a strict schema with tables, columns, and data types. Every record must fit into this structure, and SQL queries let us filter, join, and update data with precision. Relational databases are perfect for transactions, accounting, and core business logic where data integrity matters. In this project, you can test it using endpoints like /sqlite/items for CRUD operations. It’s simple but powerful — an ideal starting point.


⚡ Slide 4 — NoSQL DB: Redis

Say this:

Now we move to Redis, which represents the NoSQL family. Unlike relational databases, Redis doesn’t require a schema — it stores key-value pairs directly in memory. This makes it lightning-fast. Redis is great for caching, real-time analytics, message queues, and even temporary document storage. In this tutorial, we show both styles:


🧠 Slide 5 — Vector DB: Postgres + pgvector

Say this:

Finally, the modern frontier — Vector Databases. Here, we use Postgres extended with pgvector. It allows us to store embeddings — numeric vector representations of text — and perform similarity searches. Instead of exact matches, we can find conceptually similar items. For example, when you search for “Python web API,” it can find documents that talk about FastAPI even if that phrase never appears literally. This kind of search powers chatbots, recommendation systems, and semantic search engines. You can try it using /vector/docs to add documents and /vector/search to query similar ones.


🏗️ Slide 6 — Architecture Overview

Say this:

Let’s look at how it all fits together.


🧪 Slide 7 — Testing Each Layer with curl

Say this:

The best way to understand this system is to test it directly using curl.


🚀 Slide 8 — Conclusion: The Future of Data

Say this:

The future of data is hybrid. Real-world applications no longer rely on a single database type. Instead, they combine relational reliability, NoSQL performance, and vector intelligence. Imagine a workflow like this:


LAB

Awesome—here’s a copy-paste lab sheet with curl commands to test every feature in your stack. These assume the API is at http://localhost:8000 and you have jq installed for pretty output.


đź§± SQLite (Relational CRUD)

1) Create

curl -s -X POST http://localhost:8000/sqlite/items \
  -H "Content-Type: application/json" \
  -d '{"name":"Pen","description":"Blue ink"}' | jq

2) List all

curl -s http://localhost:8000/sqlite/items | jq

3) Get by ID (replace 1 if needed)

curl -s http://localhost:8000/sqlite/items/1 | jq

4) Update

curl -s -X PUT http://localhost:8000/sqlite/items/1 \
  -H "Content-Type: application/json" \
  -d '{"name":"Marker","description":"Black permanent marker"}' | jq

5) Delete

curl -s -X DELETE http://localhost:8000/sqlite/items/1 | jq

⚡ Redis (NoSQL: KV + Keys + Doc/Hash)

1) KV: Set (JSON body)

curl -s -X POST http://localhost:8000/redis/kv \
  -H "Content-Type: application/json" \
  -d '{"key":"greeting","value":"hello world"}' | jq

2) KV: Get

curl -s http://localhost:8000/redis/kv/greeting | jq

3) Keys: List (optional pattern)

curl -s "http://localhost:8000/redis/keys" | jq
# or with a pattern
curl -s "http://localhost:8000/redis/keys?pattern=doc:*" | jq

4) Doc (Hash): Create/Update

curl -s -X POST http://localhost:8000/redis/doc \
  -H "Content-Type: application/json" \
  -d '{"doc_id":"a1","title":"Reminder","body":"Drink water"}' | jq

5) Doc (Hash): Get

curl -s http://localhost:8000/redis/doc/a1 | jq

đź§  Postgres + pgvector (Vector DB)

1) Insert vectorized documents

curl -s -X POST http://localhost:8000/vector/docs \
  -H "Content-Type: application/json" \
  -d '{"text":"FastAPI is a modern Python web framework"}' | jq

curl -s -X POST http://localhost:8000/vector/docs \
  -H "Content-Type: application/json" \
  -d '{"text":"Redis is an in-memory data store used for caching"}' | jq

curl -s -X POST http://localhost:8000/vector/docs \
  -H "Content-Type: application/json" \
  -d '{"text":"Postgres with pgvector enables semantic search"}' | jq

2) Verify what’s stored (available in v4)

curl -s http://localhost:8000/vector/docs/all | jq

3) Similarity search (URL-encode query or use --data-urlencode)

# Option A: encode spaces
curl -s "http://localhost:8000/vector/search?query=python%20web%20api&top_k=2" | jq

# Option B: safer (lets curl encode)
curl -sG http://localhost:8000/vector/search \
  --data-urlencode "query=python web api" \
  --data-urlencode "top_k=2" | jq

🔄 Full end-to-end smoke test (one script)

bash -lc '
set -e
BASE=http://localhost:8000

echo "== SQLite =="
curl -s -X POST $BASE/sqlite/items -H "Content-Type: application/json" -d "{\"name\":\"Pen\",\"description\":\"Blue ink\"}" | jq
curl -s $BASE/sqlite/items | jq

echo "== Redis KV =="
curl -s -X POST $BASE/redis/kv -H "Content-Type: application/json" -d "{\"key\":\"greeting\",\"value\":\"hello world\"}" | jq
curl -s $BASE/redis/kv/greeting | jq

echo "== Redis Doc =="
curl -s -X POST $BASE/redis/doc -H "Content-Type: application/json" -d "{\"doc_id\":\"a1\",\"title\":\"Reminder\",\"body\":\"Drink water\"}" | jq
curl -s $BASE/redis/doc/a1 | jq
curl -s \"$BASE/redis/keys?pattern=doc:*\" | jq

echo "== pgvector =="
curl -s -X POST $BASE/vector/docs -H "Content-Type: application/json" -d "{\"text\":\"FastAPI is a modern Python web framework\"}" | jq
curl -s -X POST $BASE/vector/docs -H "Content-Type: application/json" -d "{\"text\":\"Redis is an in-memory data store used for caching\"}" | jq
curl -s -X POST $BASE/vector/docs -H "Content-Type: application/json" -d "{\"text\":\"Postgres with pgvector enables semantic search\"}" | jq
curl -s $BASE/vector/docs/all | jq
curl -sG $BASE/vector/search --data-urlencode "query=python web api" --data-urlencode "top_k=2" | jq
'