knowledge · beginner · 30 min

Search by meaning

Turn text into vectors and find the closest sentences, first in memory and then in a database.

HANDS-ON LAB · YOU RUN IT ON YOUR MACHINE · 4 STEPS
  1. Step 1 of 4

    Pull an embedding model and embed one sentence

    Run this to check

    ollama pull nomic-embed-text && curl -s http://localhost:11434/api/embed -d '{"model":"nomic-embed-text","input":"my box arrived crushed"}' | head -c 200

    You pass when

    JSON with an embeddings array of numbers.

  2. Step 3 of 4

    Start Postgres with pgvector

    Run this to check

    docker run -d --name learn-pg -e POSTGRES_PASSWORD=learn -p 5433:5432 pgvector/pgvector:pg17 && sleep 5 && docker exec learn-pg psql -U postgres -c "CREATE EXTENSION IF NOT EXISTS vector; SELECT extversion FROM pg_extension WHERE extname='vector';"

    You pass when

    One row with the extension version.

  3. Step 4 of 4

    Store the vectors in a table and run the same search in SQL

    Run this to check

    uv run --with numpy --with requests --with "psycopg[binary]" search.py --db "my box arrived crushed"

    You pass when

    The same top three as the in-memory search.

    Files you write

    • search.py
No transcript here on purpose. This page does not show terminal output, because model answers differ from run to run. Each step says what a pass looks like; your own terminal is the proof.