Skip to content
engineering workbench.by StudyPort Academy
Learning path
Intermediate18 min

Vector Databases: Embeddings, Similarity Search, and AI

Understand the idea

How AI embeddings and similarity search turned high-dimensional vectors into core database tech.

The idea

The rise of AI and Large Language Models has made a vital part of modern web development. When working with AI, text, code, audio, and images are turned into -lists of numbers (often 768 to 3072 numbers long) where items with similar meanings end up close to each other in mathematical space.

Normal databases search simple values (like numbers, strings, or dates) using indexes that sort items in a single straight line. But vectors have hundreds or thousands of dimensions. You cannot sort high-dimensional vectors with greater-than or less-than comparisons.

Instead, a vector database performs similarity search: given a search query vector, it finds the closest matching vectors using distance formulas like Cosine Similarity. Comparing a search vector against millions of items one by one requires a slow . To make search sub-second fast, vector engines use smart graph-based indexing algorithms (like HNSW).

In practice, teams usually choose between:

  1. Integrated Vector Relational (e.g. pgvector in PostgreSQL): Stores vectors alongside regular tables in your existing database, allowing a direct between vectors and user tables.
  2. Dedicated Vector Databases (e.g. Pinecone, Qdrant): Separate standalone services built specifically for tens of millions of vectors.

What changes

pgvector (PostgreSQL) vs Dedicated Vector DB (Pinecone / Qdrant)
DimensionPostgreSQL with pgvectorDedicated Vector DB (Pinecone / Qdrant)
ArchitectureExtension running inside your existing Postgres instanceIndependent standalone cluster or managed SaaS
Metadata JoinsDirect SQL JOIN between embeddings and user/order tablesRequires syncing IDs or pre-filtering in API code
Operational OverheadZero extra services to manage or monitorSeparate cluster, auth tokens, backups, and network latency
Scale Sweet SpotUp to millions of vectors (covers 95% of applications)Tens of millions to billions of high-dimensional vectors

The command

Semantic similarity search using vector dot product

3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.

The mistake

Check the result

Run the example to see cosine similarity score database documents against a query vector, ranking semantic relevance.

Guided challenge

Compare semantic similarity scores

Update the function to return true when scoreA is greater than scoreB (closer semantic relevance) and false otherwise.

Compare semantic similarity scores

3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.

EXPECTED RESULT

true
false

Hints 0/1

    Use all hints or make 3 failed checks (0/3).

    Free exploration

    Change this example and run it again. Each run is a new process. Nothing is saved.

    Your variation

    3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.

    Quiz

    A quick check for understanding. Retry as often as you like; your learning path stays open.

    01Why do high-dimensional vector embeddings require specialized index algorithms like HNSW rather than standard B-trees?
    02What advantage does pgvector offer over spinning up a dedicated standalone vector database?

    Ready to call this one understood?

    Mark this lesson complete to earn 150 XP. You can always revisit it.

    Sign in to save progress
    Next lesson